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

forwardDate: true and day of the week happens to be today? #484

Open
bytrangle opened this issue Dec 7, 2022 · 5 comments
Open

forwardDate: true and day of the week happens to be today? #484

bytrangle opened this issue Dec 7, 2022 · 5 comments

Comments

@bytrangle
Copy link

It's a bit hard to explain in the title, but what happens if:

  • forwardDate is set to true
  • today is Wednesday
  • the input date contains "Wednesday"

Then the result will be the next Wednesday, 7 days from now, it seems. Is there any way to interpret it as Wednesday of today? The way forwardDate: true works in other scenarios is good for me.

@wanasit
Copy link
Owner

wanasit commented Dec 25, 2022

Hello @bytrangle. Sorry for my slow reply.
Could you explain more about your use case?

Without the time input mentioned, "Wednesday" is parsed as "Wednesday at 12pm" (midday). So:

  • if your reference time (now) is before 12, the "Wednesday" is today.
  • if your reference time (now) is after 12, because forwardDate, the "Wednesday" is next week.
chrono.parseDate("Wednesday", new Date("Wed Dec 21 2022 7:50:22"), { forwardDate: true }) 
// should be "Wed Dec 21..."

chrono.parseDate("Wednesday", new Date("Wed Dec 21 2022 13:50:22"), { forwardDate: true }) 
// should be "Wed Dec 28..."

If the time doesn't matter, I suggest using the beginning of the day as your reference instead of now.

@Nantris
Copy link

Nantris commented Mar 16, 2023

At 9pm on a Wednesday I wrote out remind me wednesday at 10pm to test and it resolves to 10pm on the same day even forwardDate true. The code is like this: chrono.parse(reminderInput, new Date(), { forwardDate: true })

@wanasit Is this expected? It seems incorrect and it seems not in line with your explanation above, but maybe I'm misinterpreting?

@wanasit
Copy link
Owner

wanasit commented Mar 25, 2023

Yes. It'd work like that currently. It would not say it's "correct", but the { forwardDate: true } simply means the output must be later than the reference date.

In your example, "Wednesday at 10pm" is already later than the reference (Wednesday at 9pm), thus it does not assume it would need to add another week.

I'll see if this could be improve by applying forwardDate on date and time separately.
For now, I'm afraid you would have to check for that manually.

@Nantris
Copy link

Nantris commented Apr 20, 2023

@wanasit have any ideas for fixing this occurred to you? Not looking for an implementation of course, but I wonder if your subconscious has floated you any good ideas for resolving this edge case?

@wanasit
Copy link
Owner

wanasit commented Apr 22, 2023

I have not time to change and test it, but I am thinking rather than rely on ForwardDateRefiner to make the change, createParsingComponentsAtWeekday() in weekday.ts should detect the forward date options.

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

3 participants