Skip to content

Commit 6a52cf3

Browse files
author
Wanasit Tanakitrungruang
committedMar 21, 2021
Fix: handling quote sign around time parsing
1 parent 8f3a9f4 commit 6a52cf3

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
 

‎src/common/parsers/AbstractTimeExpressionParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Meridiem } from "../../index";
55
// prettier-ignore
66
function primaryTimePattern(primaryPrefix: string, primarySuffix: string) {
77
return new RegExp(
8-
"(^|\\s|T)" +
8+
"(^|\\s|T|\\b)" +
99
`${primaryPrefix}` +
1010
"(\\d{1,4})" +
1111
"(?:" +

‎src/configurations.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export function includeCommonConfiguration(configuration: Configuration, strictM
1515
configuration.refiners.unshift(new ExtractTimezoneAbbrRefiner());
1616
configuration.refiners.unshift(new ExtractTimezoneOffsetRefiner());
1717
configuration.refiners.unshift(new OverlapRemovalRefiner());
18+
19+
configuration.refiners.push(new OverlapRemovalRefiner());
Has conversations. Original line has conversations.
1820
configuration.refiners.push(new ForwardDateRefiner());
1921
configuration.refiners.push(new UnlikelyFormatFilter(strictMode));
2022
return configuration;

‎test/en/en.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ test("Test - Time Expression", function () {
2828
});
2929
});
3030

31+
test("Test - Quoted Expressions", function () {
32+
testSingleCase(chrono, "Want to meet for dinner (5pm EST)?", new Date(2020, 7 - 1, 6), (result) => {
33+
expect(result.text).toContain("5pm EST");
34+
});
35+
36+
testSingleCase(chrono, "between '3:30-4:30pm'", new Date(2020, 7 - 1, 6), (result) => {
37+
expect(result.text).toContain("3:30-4:30pm");
38+
39+
expect(result.start).toBeDate(new Date(2020, 7 - 1, 6, 15, 30));
40+
expect(result.end).toBeDate(new Date(2020, 7 - 1, 6, 16, 30));
41+
});
42+
43+
testSingleCase(chrono, "The date is '2014-04-18'", (result) => {
44+
expect(result.text).toContain("2014-04-18");
45+
expect(result.start).toBeDate(new Date(2014, 4 - 1, 18, 12));
46+
});
47+
});
48+
3149
test("Test - Strict Mode", function () {
3250
testUnexpectedResult(chrono.strict, "Tuesday");
3351
});

0 commit comments

Comments
 (0)
Please sign in to comment.