chrono-node 2.2.7 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -9
- package/benchmark/benchmark.js +4 -0
- package/dist/bundle.js +5047 -0
- package/dist/chrono.d.ts +7 -6
- package/dist/chrono.js +6 -5
- package/dist/common/casualReferences.d.ts +6 -6
- package/dist/common/casualReferences.js +16 -15
- package/dist/common/refiners/ForwardDateRefiner.js +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/locales/de/constants.js +1 -1
- package/dist/locales/de/parsers/DECasualDateParser.js +2 -2
- package/dist/locales/en/constants.d.ts +1 -1
- package/dist/locales/en/constants.js +5 -5
- package/dist/locales/en/parsers/ENCasualDateParser.js +5 -5
- package/dist/locales/en/parsers/ENCasualTimeParser.js +1 -1
- package/dist/locales/en/parsers/ENMonthNameLittleEndianParser.js +6 -8
- package/dist/locales/en/parsers/ENRelativeDateFormatParser.js +3 -3
- package/dist/locales/en/parsers/ENTimeUnitAgoFormatParser.js +3 -3
- package/dist/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +1 -1
- package/dist/locales/en/parsers/ENTimeUnitLaterFormatParser.js +2 -2
- package/dist/locales/en/parsers/ENTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/fr/constants.js +1 -1
- package/dist/locales/fr/parsers/FRCasualDateParser.js +4 -4
- package/dist/locales/fr/parsers/FRTimeUnitAgoFormatParser.js +1 -1
- package/dist/locales/fr/parsers/FRTimeUnitRelativeFormatParser.js +1 -1
- package/dist/locales/fr/parsers/FRTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/ja/parsers/JPCasualDateParser.js +3 -3
- package/dist/locales/nl/constants.js +8 -5
- package/dist/locales/nl/index.js +12 -3
- package/dist/locales/nl/parsers/NLCasualDateParser.js +4 -4
- package/dist/locales/nl/parsers/NLRelativeDateFormatParser.d.ts +7 -0
- package/dist/locales/nl/parsers/NLRelativeDateFormatParser.js +57 -0
- package/dist/locales/nl/parsers/NLTimeExpressionParser.d.ts +1 -0
- package/dist/locales/nl/parsers/NLTimeExpressionParser.js +3 -0
- package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.d.ts +9 -0
- package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.js +23 -0
- package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.d.ts +7 -0
- package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.js +25 -0
- package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.d.ts +9 -0
- package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.js +22 -0
- package/dist/locales/nl/parsers/NLTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/pt/parsers/PTCasualDateParser.js +4 -4
- package/dist/main.js +1078 -0
- package/dist/results.d.ts +12 -5
- package/dist/results.js +40 -17
- package/dist/timezone.d.ts +194 -0
- package/dist/timezone.js +207 -0
- package/dist/utils/dayjs.js +0 -2
- package/dist/utils/pattern.js +1 -1
- package/package.json +3 -3
- package/src/chrono.ts +21 -8
- package/src/common/casualReferences.ts +17 -18
- package/src/common/refiners/ForwardDateRefiner.ts +1 -1
- package/src/index.ts +19 -3
- package/src/locales/de/constants.ts +1 -1
- package/src/locales/de/parsers/DECasualDateParser.ts +2 -2
- package/src/locales/en/constants.ts +5 -5
- package/src/locales/en/parsers/ENCasualDateParser.ts +5 -5
- package/src/locales/en/parsers/ENCasualTimeParser.ts +1 -1
- package/src/locales/en/parsers/ENMonthNameLittleEndianParser.ts +9 -10
- package/src/locales/en/parsers/ENRelativeDateFormatParser.ts +3 -3
- package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +3 -4
- package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +1 -1
- package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +2 -2
- package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/fr/constants.ts +1 -1
- package/src/locales/fr/parsers/FRCasualDateParser.ts +4 -4
- package/src/locales/fr/parsers/FRTimeUnitAgoFormatParser.ts +1 -1
- package/src/locales/fr/parsers/FRTimeUnitRelativeFormatParser.ts +1 -1
- package/src/locales/fr/parsers/FRTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/ja/parsers/JPCasualDateParser.ts +3 -3
- package/src/locales/nl/constants.ts +11 -5
- package/src/locales/nl/index.ts +12 -3
- package/src/locales/nl/parsers/NLCasualDateParser.ts +4 -4
- package/src/locales/nl/parsers/NLRelativeDateFormatParser.ts +70 -0
- package/src/locales/nl/parsers/NLTimeExpressionParser.ts +4 -0
- package/src/locales/nl/parsers/NLTimeUnitAgoFormatParser.ts +26 -0
- package/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +27 -0
- package/src/locales/nl/parsers/NLTimeUnitLaterFormatParser.ts +27 -0
- package/src/locales/nl/parsers/NLTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/pt/parsers/PTCasualDateParser.ts +4 -4
- package/src/results.ts +52 -18
- package/src/timezone.ts +205 -0
- package/src/utils/dayjs.ts +0 -2
- package/src/utils/pattern.ts +1 -1
- package/test/en/en_month_name_little_endian.test.ts +10 -0
- package/test/en/en_relative.test.ts +30 -0
- package/test/en/en_slash.test.ts +11 -0
- package/test/en/en_timezone_exp.test.ts +7 -4
- package/test/en/en_weekday.test.ts +69 -25
- package/test/en/negative_cases.test.ts +2 -0
- package/test/nl/nl_relative.test.ts +212 -0
- package/test/nl/nl_time_units_ago.test.ts +243 -0
- package/test/nl/nl_time_units_casual_relative.test.ts +130 -0
- package/test/nl/nl_time_units_later.test.ts +250 -0
- package/test/result.test.ts +32 -13
- package/test/system_timezone.test.ts +100 -0
- package/test/test_util.ts +10 -7
|
@@ -4,5 +4,6 @@ import { ParsingContext } from "../../../chrono";
|
|
|
4
4
|
export default class NLTimeExpressionParser extends AbstractTimeExpressionParser {
|
|
5
5
|
primaryPrefix(): string;
|
|
6
6
|
followingPhase(): string;
|
|
7
|
+
primarySuffix(): string;
|
|
7
8
|
extractPrimaryTimeComponents(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | null;
|
|
8
9
|
}
|
|
@@ -8,6 +8,9 @@ class NLTimeExpressionParser extends AbstractTimeExpressionParser_1.AbstractTime
|
|
|
8
8
|
followingPhase() {
|
|
9
9
|
return "\\s*(?:\\-|\\–|\\~|\\〜|om|\\?)\\s*";
|
|
10
10
|
}
|
|
11
|
+
primarySuffix() {
|
|
12
|
+
return "(?:\\s*(?:uur))?(?!/)(?=\\W|$)";
|
|
13
|
+
}
|
|
11
14
|
extractPrimaryTimeComponents(context, match) {
|
|
12
15
|
if (match[0].match(/^\s*\d{4}\s*$/)) {
|
|
13
16
|
return null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
4
|
+
export default class NLTimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
private strictMode;
|
|
6
|
+
constructor(strictMode: boolean);
|
|
7
|
+
innerPattern(): RegExp;
|
|
8
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const results_1 = require("../../../results");
|
|
5
|
+
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
6
|
+
const timeunits_1 = require("../../../utils/timeunits");
|
|
7
|
+
const PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(?:geleden|voor|eerder)(?=(?:\\W|$))", "i");
|
|
8
|
+
const STRICT_PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "geleden(?=(?:\\W|$))", "i");
|
|
9
|
+
class NLTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
10
|
+
constructor(strictMode) {
|
|
11
|
+
super();
|
|
12
|
+
this.strictMode = strictMode;
|
|
13
|
+
}
|
|
14
|
+
innerPattern() {
|
|
15
|
+
return this.strictMode ? STRICT_PATTERN : PATTERN;
|
|
16
|
+
}
|
|
17
|
+
innerExtract(context, match) {
|
|
18
|
+
const timeUnits = constants_1.parseTimeUnits(match[1]);
|
|
19
|
+
const outputTimeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
20
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = NLTimeUnitAgoFormatParser;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
4
|
+
export default class NLTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
innerPattern(): RegExp;
|
|
6
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const results_1 = require("../../../results");
|
|
5
|
+
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
6
|
+
const timeunits_1 = require("../../../utils/timeunits");
|
|
7
|
+
const PATTERN = new RegExp(`(deze|vorige|afgelopen|komende|over|\\+|-)\\s*(${constants_1.TIME_UNITS_PATTERN})(?=\\W|$)`, "i");
|
|
8
|
+
class NLTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
9
|
+
innerPattern() {
|
|
10
|
+
return PATTERN;
|
|
11
|
+
}
|
|
12
|
+
innerExtract(context, match) {
|
|
13
|
+
const prefix = match[1].toLowerCase();
|
|
14
|
+
let timeUnits = constants_1.parseTimeUnits(match[2]);
|
|
15
|
+
switch (prefix) {
|
|
16
|
+
case "vorige":
|
|
17
|
+
case "afgelopen":
|
|
18
|
+
case "-":
|
|
19
|
+
timeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = NLTimeUnitCasualRelativeFormatParser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
4
|
+
export default class NLTimeUnitLaterFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
private strictMode;
|
|
6
|
+
constructor(strictMode: boolean);
|
|
7
|
+
innerPattern(): RegExp;
|
|
8
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const results_1 = require("../../../results");
|
|
5
|
+
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
6
|
+
const PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(later|na|vanaf nu|voortaan|vooruit|uit)" + "(?=(?:\\W|$))", "i");
|
|
7
|
+
const STRICT_PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(later|vanaf nu)" + "(?=(?:\\W|$))", "i");
|
|
8
|
+
const GROUP_NUM_TIMEUNITS = 1;
|
|
9
|
+
class NLTimeUnitLaterFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
10
|
+
constructor(strictMode) {
|
|
11
|
+
super();
|
|
12
|
+
this.strictMode = strictMode;
|
|
13
|
+
}
|
|
14
|
+
innerPattern() {
|
|
15
|
+
return this.strictMode ? STRICT_PATTERN : PATTERN;
|
|
16
|
+
}
|
|
17
|
+
innerExtract(context, match) {
|
|
18
|
+
const fragments = constants_1.parseTimeUnits(match[GROUP_NUM_TIMEUNITS]);
|
|
19
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, fragments);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = NLTimeUnitLaterFormatParser;
|
|
@@ -9,7 +9,7 @@ class NLTimeUnitWithinFormatParser extends AbstractParserWithWordBoundary_1.Abst
|
|
|
9
9
|
}
|
|
10
10
|
innerExtract(context, match) {
|
|
11
11
|
const timeUnits = constants_1.parseTimeUnits(match[1]);
|
|
12
|
-
return results_1.ParsingComponents.
|
|
12
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.default = NLTimeUnitWithinFormatParser;
|
|
@@ -30,14 +30,14 @@ class PTCasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParser
|
|
|
30
30
|
const component = context.createParsingComponents();
|
|
31
31
|
switch (lowerText) {
|
|
32
32
|
case "agora":
|
|
33
|
-
return references.now(context.
|
|
33
|
+
return references.now(context.reference);
|
|
34
34
|
case "hoje":
|
|
35
|
-
return references.today(context.
|
|
35
|
+
return references.today(context.reference);
|
|
36
36
|
case "amanha":
|
|
37
37
|
case "amanhã":
|
|
38
|
-
return references.tomorrow(context.
|
|
38
|
+
return references.tomorrow(context.reference);
|
|
39
39
|
case "ontem":
|
|
40
|
-
return references.yesterday(context.
|
|
40
|
+
return references.yesterday(context.reference);
|
|
41
41
|
}
|
|
42
42
|
return component;
|
|
43
43
|
}
|