Skip to content

Commit

Permalink
Fix: (en) support new separator for date/time
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanasit Tanakitrungruang committed Aug 10, 2024
1 parent be6e995 commit 23abdda
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/locales/en/refiners/ENMergeDateTimeRefiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import AbstractMergeDateTimeRefiner from "../../../common/refiners/AbstractMerge
*/
export default class ENMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner {
patternBetween(): RegExp {
return new RegExp("^\\s*(T|at|after|before|on|of|,|-|\\.|:)?\\s*$");
return new RegExp("^\\s*(T|at|after|before|on|of|,|-|\\.|∙|:)?\\s*$");
}
}
58 changes: 58 additions & 0 deletions test/en/en_time_exp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,89 @@ test("Test - Time expression", function () {
test("Test - Time expression after date", function () {
testSingleCase(chrono, "05/31/2024 14:15", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2024);
expect(result.start.get("month")).toBe(5);
expect(result.start.get("day")).toBe(31);

expect(result.start.get("hour")).toBe(14);
expect(result.start.get("minute")).toBe(15);
expect(result.start.get("meridiem")).toBe(Meridiem.PM);
});

testSingleCase(chrono, "05/31/2024.14:15", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2024);
expect(result.start.get("month")).toBe(5);
expect(result.start.get("day")).toBe(31);

expect(result.start.get("hour")).toBe(14);
expect(result.start.get("minute")).toBe(15);
expect(result.start.get("meridiem")).toBe(Meridiem.PM);
});

testSingleCase(chrono, "05/31/2024:14:15", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2024);
expect(result.start.get("month")).toBe(5);
expect(result.start.get("day")).toBe(31);

expect(result.start.get("hour")).toBe(14);
expect(result.start.get("minute")).toBe(15);
expect(result.start.get("meridiem")).toBe(Meridiem.PM);
});

testSingleCase(chrono, "05/31/2024-14:15", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2024);
expect(result.start.get("month")).toBe(5);
expect(result.start.get("day")).toBe(31);

expect(result.start.get("hour")).toBe(14);
expect(result.start.get("minute")).toBe(15);
expect(result.start.get("meridiem")).toBe(Meridiem.PM);
});
});

test("Test - Time expression before date", () => {
testSingleCase(chrono, "14:15 05/31/2024", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2024);
expect(result.start.get("month")).toBe(5);
expect(result.start.get("day")).toBe(31);

expect(result.start.get("hour")).toBe(14);
expect(result.start.get("minute")).toBe(15);
expect(result.start.get("meridiem")).toBe(Meridiem.PM);
});

testSingleCase(chrono, "8:23 AM, Jul 9", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2016);
expect(result.start.get("month")).toBe(7);
expect(result.start.get("day")).toBe(9);

expect(result.start.get("hour")).toBe(8);
expect(result.start.get("minute")).toBe(23);
expect(result.start.get("meridiem")).toBe(Meridiem.AM);
});

testSingleCase(chrono, "8:23 AM ∙ Jul 9", new Date(2016, 10 - 1, 1, 8), (result, text) => {
expect(result.text).toBe(text);

expect(result.start.get("year")).toBe(2016);
expect(result.start.get("month")).toBe(7);
expect(result.start.get("day")).toBe(9);

expect(result.start.get("hour")).toBe(8);
expect(result.start.get("minute")).toBe(23);
expect(result.start.get("meridiem")).toBe(Meridiem.AM);
});
});

test("Test - Time range expression", function () {
Expand Down

0 comments on commit 23abdda

Please sign in to comment.