Skip to content

fix(en): support 'of' connector in weekday postfix modifier (e.g. 'Tuesday of next week')#644

Merged
wanasit merged 1 commit into
wanasit:masterfrom
breissingerj:fix/weekday-of-next-week-modifier
May 5, 2026
Merged

fix(en): support 'of' connector in weekday postfix modifier (e.g. 'Tuesday of next week')#644
wanasit merged 1 commit into
wanasit:masterfrom
breissingerj:fix/weekday-of-next-week-modifier

Conversation

@breissingerj
Copy link
Copy Markdown

Problem

ENWeekdayParser did not recognise the word of as a connector between a weekday and its postfix modifier (this/last/next week). The postfix group regex only allowed optional whitespace directly before the modifier keyword:

// before
"(?:\\s*(this|last|past|next)\\s*week)?"

As a result, any phrase of the form <weekday> of <modifier> week silently dropped the modifier and fell back to getDaysToWeekdayClosest(). When today is the named weekday (e.g. parsing "Tuesday of next week" on a Tuesday), the closest match is 0 days away — returning today instead of next week. Additionally, because the full phrase was not consumed as one token, adding a time component (e.g. "Tuesday of next week after 2pm") produced two separate results instead of one merged date-time.

Fix

Add (?:of\\s*)? as an optional non-capturing group inside the postfix:

// after
"(?:\\s*(?:of\\s*)?(this|last|past|next)\\s*week)?"

This accepts "Tuesday of next week", "Friday of last week", and "Wednesday of this week" while leaving all existing patterns ("next Tuesday", "Tuesday next week", "Tuesday, next week", etc.) completely unchanged.

Tests

A new test block — "Test - Weekday 'of next/last/this week' connector" — is added to test/en/en_weekday.test.ts with 10 cases covering:

  • of next week for the same weekday as the ref date (the original edge case)
  • of next week for earlier and later weekdays
  • of last week for same and different weekdays
  • of this week for the same and a forward weekday
  • Combined with a time component (after 2pm, at 9am) — asserts a single merged result
  • In-sentence context

All 519 tests pass (npm test).

…next week')

ENWeekdayParser's postfix regex only allowed whitespace before 'this/last/next week',
so the word 'of' caused the modifier to be silently dropped. Phrases like
'Tuesday of next week' fell back to getDaysToWeekdayClosest(), which returns 0 days
when today is the named weekday — resolving to today instead of next week.
A time suffix (e.g. 'after 2pm') also split into two results instead of one.

Fix: add (?:of\s*)? as an optional non-capturing group in the postfix pattern.

Add 10 test cases covering of-next, of-last, of-this, same-weekday edge case,
time merging (single result assertion), and in-sentence context.
@wanasit
Copy link
Copy Markdown
Owner

wanasit commented May 5, 2026

Thanks for the improvement!

@wanasit wanasit merged commit 59f0bf8 into wanasit:master May 5, 2026
1 check passed
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 92.482% (-0.03%) from 92.515% — breissingerj:fix/weekday-of-next-week-modifier into wanasit:master

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.

4 participants