From 23abdda66e8c980b295d1365b6a5a8c62438494a Mon Sep 17 00:00:00 2001 From: Wanasit Tanakitrungruang Date: Sat, 10 Aug 2024 13:25:30 +0900 Subject: [PATCH] Fix: (en) support new separator for date/time --- .../en/refiners/ENMergeDateTimeRefiner.ts | 2 +- test/en/en_time_exp.test.ts | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/locales/en/refiners/ENMergeDateTimeRefiner.ts b/src/locales/en/refiners/ENMergeDateTimeRefiner.ts index 6fa75347..37a2749f 100644 --- a/src/locales/en/refiners/ENMergeDateTimeRefiner.ts +++ b/src/locales/en/refiners/ENMergeDateTimeRefiner.ts @@ -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*$"); } } diff --git a/test/en/en_time_exp.test.ts b/test/en/en_time_exp.test.ts index 95ab5a90..8b0b7110 100644 --- a/test/en/en_time_exp.test.ts +++ b/test/en/en_time_exp.test.ts @@ -27,6 +27,11 @@ 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); @@ -34,6 +39,11 @@ 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); @@ -41,6 +51,11 @@ 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); @@ -48,10 +63,53 @@ 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); + }); +}); + +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 () {