Skip to content

Commit 971b833

Browse files
author
Wanasit Tanakitrungruang
committed
Fix: ignore short digits follow date
1 parent 3b8c844 commit 971b833

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/locales/en/refiners/ENExtractYearSuffixRefiner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ export default class ENExtractYearSuffixRefiner implements Refiner {
1010
if (!result.start.isDateWithUnknownYear()) {
1111
return;
1212
}
13-
1413
const suffix = context.text.substring(result.index + result.text.length);
1514
const match = YEAR_SUFFIX_PATTERN.exec(suffix);
1615
if (!match) {
1716
return;
1817
}
19-
18+
// If the suffix match is just a short number, e.g. "14/4 90", don't assume it year.
19+
if (match[0].trim().length <= 3) {
20+
return;
21+
}
2022
context.debug(() => {
2123
console.log(`Extracting year: '${match[0]}' into : ${result}`);
2224
});
23-
2425
const year = parseYear(match[YEAR_GROUP]);
2526
if (result.end != null) {
2627
result.end.assign("year", year);
2728
}
2829
result.start.assign("year", year);
2930
result.text += match[0];
3031
});
31-
3232
return results;
3333
}
3434
}

test/en/en_slash.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,11 @@ test("Test - forward dates only option", function () {
274274
expect(result.start).toBeDate(new Date(2022, 1 - 1, 8, 12));
275275
});
276276
});
277+
278+
test("Test - Slash date with an extra chunk", () => {
279+
testSingleCase(chrono, "14/4 90", new Date(2012, 7, 10), (result) => {
280+
expect(result.start.get("year")).toBe(2012);
281+
expect(result.start.get("month")).toBe(4);
282+
expect(result.start.get("day")).toBe(14);
283+
});
284+
});

0 commit comments

Comments
 (0)