Skip to content

Commit

Permalink
Fix regex to capture multiple time units in ENTimeUnitWithinFormatPar…
Browse files Browse the repository at this point in the history
…ser with forward dates
  • Loading branch information
Toby Rothe committed Dec 21, 2023
1 parent 80ca03a commit 0425219
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts
Expand Up @@ -9,7 +9,7 @@ const MULTIPLE_TIME_UNITS_PATTERN = `${TIME_UNIT_PATTERN}(?:${TIME_UNIT_CONNECTO

const PATTERN_WITH_OPTIONAL_PREFIX = new RegExp(
`(?:(?:within|in|for)\\s*)?` +
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?${MULTIPLE_TIME_UNITS_PATTERN}(?=\\W|$)`,
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${MULTIPLE_TIME_UNITS_PATTERN})(?=\\W|$)`,
"i"
);

Expand Down
7 changes: 7 additions & 0 deletions test/en/en_time_units_within.test.ts
Expand Up @@ -60,6 +60,13 @@ test("Test - The normal within expression", () => {
expect(result.start).toBeDate(new Date(2012, 7, 10, 12, 19, 30));
});

testSingleCase(chrono, "set a timer for 10 minutes and 10 seconds", new Date(2012, 7, 10, 12, 14), { forwardDate: true }, (result) => {
expect(result.index).toBe(12);
expect(result.text).toBe("for 10 minutes and 10 seconds");

expect(result.start).toBeDate(new Date(2012, 7, 10, 12, 24, 10));
});

testSingleCase(chrono, "within 1 hour", new Date(2012, 7, 10, 12, 14), (result) => {
expect(result.index).toBe(0);
expect(result.text).toBe("within 1 hour");
Expand Down

0 comments on commit 0425219

Please sign in to comment.