Skip to content

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

Merged
wanasit merged 1 commit into
wanasit:masterfrom
Enesuygurs:fix/en-last-weekday-on-monday
Nov 3, 2026
Merged

wanasit merged 1 commit into
wanasit:masterfrom
Enesuygurs:fix/en-last-weekday-on-monday

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

"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).

@wanasit

wanasit commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Thank you for the fix!

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.133% (+0.001%) from 93.132% — Enesuygurs:fix/en-last-weekday-on-monday into wanasit:master

@wanasit
wanasit merged commit 3e1f570 into wanasit:master Nov 3, 2026
2 checks passed
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.

3 participants