Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent behaviour #464

Closed
Mtillmann opened this issue Aug 2, 2022 · 5 comments
Closed

inconsistent behaviour #464

Mtillmann opened this issue Aug 2, 2022 · 5 comments

Comments

@Mtillmann
Copy link

    let schedules = [
            ['next_morning', chrono.parse('Tomorrow at 10:00', new Date('08-02-2022'))[0].start.date()],
            ['next_evening', chrono.parse('Tomorrow at 19:00', new Date('08-02-2022'))[0].start.date()],
            ['next_saturday', chrono.parse('next Saturday at 11:00', new Date('08-02-2022'))[0].start.date()],
            ['next_sunday', chrono.parse('next Sunday at 15:00', new Date('08-02-2022'))[0].start.date()]
        ];

yields

[
 [ 'next_morning', 2022-08-03T08:00:00.000Z ],
 [ 'next_evening', 2022-08-03T17:00:00.000Z ],
 [ 'next_saturday', 2022-08-13T09:00:00.000Z ],
 [ 'next_sunday', 2022-08-07T13:00:00.000Z ]
]

next_sunday works as expected while next_saturday is one week off. Am I missing something?

@Mtillmann
Copy link
Author

FWIW, the following chrono.parse-syntax seems to yield the desired values:

 let referenceDate = new Date('08-02-2022'),
      parsingOptions = {
          forwardDate: true
      },
      schedules = [
          ['next_morning', chrono.parse('Tomorrow, 10:00', referenceDate, parsingOptions)[0].start.date()],
          ['next_evening', chrono.parse('Tomorrow, 19:00', referenceDate, parsingOptions)[0].start.date()],
          ['next_saturday', chrono.parse('Saturday, 10:00', referenceDate, parsingOptions)[0].start.date()],
          ['next_sunday', chrono.parse('Sunday, 15:00', referenceDate, parsingOptions)[0].start.date()]
      ];

@wanasit
Copy link
Owner

wanasit commented Aug 7, 2022

Hello. Thanks for reporting.

What happened was the reference date "August 2, 2022 - Tuesday" (enum date 2)

  • The "next Sunday" (enum date 0) is 5 day later
  • But, the "next Saturday" is (date enum 6) is 4+7 day later

Calculating "next" based on the date-enum-offset rather than date-window seems like a bug.

However, deciding e.g. what is "Saturday" vs "Next Saturday" has been a difficult edge case, I need some more time to check if it doesn't break any current tests.

@wanasit
Copy link
Owner

wanasit commented Aug 13, 2022

The d0551cd fixes this issue, but there are other changes relating to the day of the week I want to clean up.

It should be released in the new minor version (2.4.0) sometime next week.

@Mtillmann
Copy link
Author

@wanasit Thanks a lot for taking the time mate 🙇

@wanasit
Copy link
Owner

wanasit commented Aug 21, 2022

Published. Please update to 2.4.1+

@wanasit wanasit closed this as completed Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants