Skip to content

fix(en): resolve "last/next weekday" to the adjacent working day - #679

Open
Enesuygurs wants to merge 1 commit into
wanasit:masterfrom
Enesuygurs:fix/en-last-weekday-on-monday
Open

Enesuygurs wants to merge 1 commit into
wanasit:masterfrom
Enesuygurs:fix/en-last-weekday-on-monday

Conversation

@Enesuygurs

Copy link
Copy Markdown

"last weekday" and "next weekday" give the wrong date on 4 of the 7 days of the week. The existing tests only use Friday and Saturday as the reference date, and both happen to work.

With a reference of Monday 2024-10-21:

  • "last weekday" -> Sun Oct 20 (expected Fri Oct 18)
  • "next weekday" -> Tue Oct 29 (expected Tue Oct 22)

"next weekday" is also a week late from Tuesday, Wednesday and Thursday. For example, Wed Oct 23 gives Thu Oct 31 instead of Thu Oct 24.

There are two causes, both in the "weekday" branch of ENWeekdayParser:

  • (weekday % 5) + 1 is meant to wrap Monday back to Friday, but in JS -1 % 5 is -1, so the result is Sunday. It is now ((weekday + 5) % 5) + 1.
  • The branch already works out the adjacent working day, then passes "next" on to createParsingComponentsAtWeekday. There, "next Tuesday" said on a Monday means Tuesday of the following week. For "weekday", the "next" modifier is now passed as "this", which counts forward to the day already computed. The Friday, Saturday and Sunday results don't change.

I added Monday and Wednesday reference cases to the existing "Casual 'weekday' mentioning" test. They fail before this change and pass with it, and the full suite passes (753 tests).

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant