Skip to content

Commit

Permalink
Fix: incorrect reference "for the ..."
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanasit Tanakitrungruang committed Dec 30, 2023
1 parent fed9f9d commit 2cbe422
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default class ENTimeUnitWithinFormatParser extends AbstractParserWithWord
}

innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
// Exclude "for the unit" phases, e.g. "for the year"
if (match[0].match(/^for\s*the\s*\w+/)) {
return null;
}

const timeUnits = parseTimeUnits(match[1]);
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
}
Expand Down
6 changes: 6 additions & 0 deletions test/en/en_month.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ test("Test - Month-Year expression", function () {

expect(result.start).toBeDate(new Date(2012, 9 - 1, 1, 12));
});

testSingleCase(chrono, "Statement of comprehensive income for the year ended Dec. 2021", (result) => {
expect(result.start.get("year")).toBe(2021);
expect(result.start.get("month")).toBe(12);
expect(result.text).toBe("Dec. 2021");
});
});

test("Test - Month-Only expression", function () {
Expand Down
7 changes: 7 additions & 0 deletions test/en/en_month_name_middle_endian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ test("Test - Single Expression", () => {
expect(result.start.get("month")).toBe(1);
expect(result.start.get("day")).toBe(20);
});

testSingleCase(chrono, "Dec. 21", new Date(2012, 7, 10), (result) => {
expect(result.text).toBe("Dec. 21");
expect(result.start.get("year")).toBe(2012);
expect(result.start.get("month")).toBe(12);
expect(result.start.get("day")).toBe(21);
});
});

test("Test - Single expression with separators", () => {
Expand Down
4 changes: 4 additions & 0 deletions test/en/negative_cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ test("Test - Skip version number pattern", () => {
testUnexpectedResult(chrono, "Version: 1.10.30");
});

test("Test - Skip incorrect reference", () => {
testUnexpectedResult(chrono, "for the year");
});

test("Test - Date with version number pattern", () => {
testSingleCase(chrono.en, "1.5.3 - 2015-09-24", (result) => {
expect(result.text).toBe("2015-09-24");
Expand Down

0 comments on commit 2cbe422

Please sign in to comment.