fix(en): support 'of' connector in weekday postfix modifier (e.g. 'Tuesday of next week')#644
Merged
wanasit merged 1 commit intoMay 5, 2026
Conversation
…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.
Owner
|
Thanks for the improvement! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ENWeekdayParserdid not recognise the wordofas 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:As a result, any phrase of the form
<weekday> of <modifier> weeksilently dropped the modifier and fell back togetDaysToWeekdayClosest(). 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: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
testblock — "Test - Weekday 'of next/last/this week' connector" — is added totest/en/en_weekday.test.tswith 10 cases covering:of next weekfor the same weekday as the ref date (the original edge case)of next weekfor earlier and later weekdaysof last weekfor same and different weekdaysof this weekfor the same and a forward weekdayafter 2pm,at 9am) — asserts a single merged resultAll 519 tests pass (
npm test).