chrono-node 2.3.2 → 2.3.6
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 +1 -1
- package/dist/common/casualReferences.js +3 -1
- package/dist/common/parsers/AbstractParserWithWordBoundary.js +2 -1
- package/dist/common/refiners/ExtractTimezoneAbbrRefiner.js +5 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/locales/de/constants.js +1 -1
- package/dist/locales/en/constants.js +1 -1
- package/dist/locales/en/parsers/ENRelativeDateFormatParser.js +3 -3
- package/dist/locales/en/parsers/ENTimeUnitAgoFormatParser.js +1 -1
- package/dist/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +1 -1
- package/dist/locales/en/parsers/ENTimeUnitLaterFormatParser.js +1 -1
- package/dist/locales/en/parsers/ENTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/fr/constants.js +1 -1
- 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/nl/parsers/NLRelativeDateFormatParser.js +3 -3
- package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.js +1 -1
- package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.js +1 -1
- package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.js +1 -1
- package/dist/locales/nl/parsers/NLTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/zh/hans/constants.d.ts +27 -0
- package/dist/locales/zh/hans/constants.js +51 -0
- package/dist/locales/zh/hans/index.d.ts +9 -0
- package/dist/locales/zh/hans/index.js +49 -0
- package/dist/locales/zh/hans/parsers/ZHHansCasualDateParser.d.ts +7 -0
- package/dist/locales/zh/hans/parsers/ZHHansCasualDateParser.js +138 -0
- package/dist/locales/zh/hans/parsers/ZHHansDateParser.d.ts +6 -0
- package/dist/locales/zh/hans/parsers/ZHHansDateParser.js +72 -0
- package/dist/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.d.ts +6 -0
- package/dist/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.js +78 -0
- package/dist/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.d.ts +7 -0
- package/dist/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.js +70 -0
- package/dist/locales/zh/hans/parsers/ZHHansTimeExpressionParser.d.ts +6 -0
- package/dist/locales/zh/hans/parsers/ZHHansTimeExpressionParser.js +438 -0
- package/dist/locales/zh/hans/parsers/ZHHansWeekdayParser.d.ts +7 -0
- package/dist/locales/zh/hans/parsers/ZHHansWeekdayParser.js +46 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.d.ts +4 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.js +12 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.d.ts +4 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.js +12 -0
- package/dist/locales/zh/hant/constants.d.ts +28 -0
- package/dist/locales/zh/hant/constants.js +52 -0
- package/dist/locales/zh/hant/index.d.ts +9 -0
- package/dist/locales/zh/hant/index.js +49 -0
- package/dist/locales/zh/hant/parsers/ZHHantCasualDateParser.d.ts +7 -0
- package/dist/locales/zh/hant/parsers/ZHHantCasualDateParser.js +138 -0
- package/dist/locales/zh/hant/parsers/ZHHantDateParser.d.ts +6 -0
- package/dist/locales/zh/hant/parsers/ZHHantDateParser.js +64 -0
- package/dist/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.d.ts +6 -0
- package/dist/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.js +78 -0
- package/dist/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.d.ts +7 -0
- package/dist/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.js +70 -0
- package/dist/locales/zh/hant/parsers/ZHHantTimeExpressionParser.d.ts +6 -0
- package/dist/locales/zh/hant/parsers/ZHHantTimeExpressionParser.js +438 -0
- package/dist/locales/zh/hant/parsers/ZHHantWeekdayParser.d.ts +7 -0
- package/dist/locales/zh/hant/parsers/ZHHantWeekdayParser.js +46 -0
- package/dist/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.d.ts +4 -0
- package/dist/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.js +12 -0
- package/dist/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.d.ts +4 -0
- package/dist/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.js +12 -0
- package/dist/locales/zh/index.d.ts +2 -0
- package/dist/locales/zh/index.js +16 -0
- package/dist/results.d.ts +2 -2
- package/dist/results.js +18 -12
- package/dist/timezone.d.ts +1 -1
- package/dist/timezone.js +3 -0
- package/dist/utils/dayjs.js +7 -0
- package/package.json +1 -1
- package/src/common/casualReferences.ts +3 -1
- package/src/common/parsers/AbstractParserWithWordBoundary.ts +1 -1
- package/src/common/refiners/ExtractTimezoneAbbrRefiner.ts +8 -0
- package/src/index.ts +2 -1
- package/src/locales/de/constants.ts +1 -1
- package/src/locales/en/constants.ts +1 -1
- package/src/locales/en/parsers/ENMonthNameLittleEndianParser.ts +0 -2
- package/src/locales/en/parsers/ENRelativeDateFormatParser.ts +3 -3
- package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +1 -1
- package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +1 -1
- package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +1 -1
- package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/fr/constants.ts +1 -1
- 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/nl/parsers/NLRelativeDateFormatParser.ts +3 -3
- package/src/locales/nl/parsers/NLTimeUnitAgoFormatParser.ts +1 -1
- package/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +1 -1
- package/src/locales/nl/parsers/NLTimeUnitLaterFormatParser.ts +1 -1
- package/src/locales/nl/parsers/NLTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/zh/hans/constants.ts +52 -0
- package/src/locales/zh/hans/index.ts +62 -0
- package/src/locales/zh/hans/parsers/ZHHansCasualDateParser.ts +128 -0
- package/src/locales/zh/hans/parsers/ZHHansDateParser.ts +75 -0
- package/src/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.ts +81 -0
- package/src/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.ts +69 -0
- package/src/locales/zh/hans/parsers/ZHHansTimeExpressionParser.ts +424 -0
- package/src/locales/zh/hans/parsers/ZHHansWeekdayParser.ts +46 -0
- package/src/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.ts +7 -0
- package/src/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.ts +7 -0
- package/src/locales/zh/hant/constants.ts +53 -0
- package/src/locales/zh/hant/index.ts +63 -0
- package/src/locales/zh/hant/parsers/ZHHantCasualDateParser.ts +128 -0
- package/src/locales/zh/hant/parsers/ZHHantDateParser.ts +68 -0
- package/src/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.ts +81 -0
- package/src/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.ts +69 -0
- package/src/locales/zh/hant/parsers/ZHHantTimeExpressionParser.ts +424 -0
- package/src/locales/zh/hant/parsers/ZHHantWeekdayParser.ts +46 -0
- package/src/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.ts +7 -0
- package/src/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.ts +7 -0
- package/src/locales/zh/index.ts +2 -0
- package/src/results.ts +22 -12
- package/src/timezone.ts +5 -1
- package/src/utils/dayjs.ts +6 -0
- package/test/en/en_casual.test.ts +11 -0
- package/test/en/en_month.test.ts +13 -0
- package/test/en/en_relative.test.ts +8 -0
- package/test/en/en_time_units_ago.test.ts +16 -0
- package/test/en/en_time_units_later.test.ts +6 -0
- package/test/en/en_timezone_exp.test.ts +85 -10
- package/test/en/negative_cases.test.ts +2 -0
- package/test/test_util.ts +5 -2
- package/test/zh/zh.test.ts +18 -0
- package/test/zh/zh_hans_casual.test.ts +228 -0
- package/test/zh/zh_hans_date.test.ts +102 -0
- package/test/zh/zh_hans_deadline.test.ts +136 -0
- package/test/zh/zh_hans_time_exp.test.ts +182 -0
- package/test/zh/zh_hans_weekday.test.ts +132 -0
- package/test/zh/zh_hant_casual.test.ts +246 -0
- package/test/zh/zh_hant_date.test.ts +102 -0
- package/test/zh/zh_hant_deadline.test.ts +136 -0
- package/test/zh/zh_hant_time_exp.test.ts +182 -0
- package/test/zh/zh_hant_weekday.test.ts +132 -0
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ const chrono = require('chrono-node');
|
|
|
37
37
|
### What's changed in the v2
|
|
38
38
|
For Users
|
|
39
39
|
* Chrono’s default now handles only international English. While in the previous version, it tried to parse with all known languages.
|
|
40
|
-
* The current fully supported languages are `en`, `ja`, and `
|
|
40
|
+
* The current fully supported languages are `en`, `ja`, `fr`, and `nl` (`de`, `pt`, and `zh.hant` are partially supported).
|
|
41
41
|
|
|
42
42
|
For contributors and advanced users
|
|
43
43
|
* The project is rewritten in TypeScript
|
|
@@ -13,7 +13,9 @@ function now(reference) {
|
|
|
13
13
|
const component = new results_1.ParsingComponents(reference, {});
|
|
14
14
|
dayjs_2.assignSimilarDate(component, targetDate);
|
|
15
15
|
dayjs_2.assignSimilarTime(component, targetDate);
|
|
16
|
-
|
|
16
|
+
if (reference.timezoneOffset !== null) {
|
|
17
|
+
component.assign("timezoneOffset", targetDate.utcOffset());
|
|
18
|
+
}
|
|
17
19
|
return component;
|
|
18
20
|
}
|
|
19
21
|
exports.now = now;
|
|
@@ -16,7 +16,8 @@ class AbstractParserWithWordBoundaryChecking {
|
|
|
16
16
|
return this.cachedPattern;
|
|
17
17
|
}
|
|
18
18
|
extract(context, match) {
|
|
19
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
const header = (_a = match[1]) !== null && _a !== void 0 ? _a : "";
|
|
20
21
|
match.index = match.index + header.length;
|
|
21
22
|
match[0] = match[0].substring(header.length);
|
|
22
23
|
for (let i = 2; i < match.length; i++) {
|
|
@@ -225,6 +225,11 @@ class ExtractTimezoneAbbrRefiner {
|
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
+
if (result.start.isOnlyDate()) {
|
|
229
|
+
if (timezoneAbbr != match[1]) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
228
233
|
result.text += match[0];
|
|
229
234
|
if (!result.start.isCertain("timezoneOffset")) {
|
|
230
235
|
result.start.assign("timezoneOffset", extractedTimezoneOffset);
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,8 @@ import * as fr from "./locales/fr";
|
|
|
34
34
|
import * as ja from "./locales/ja";
|
|
35
35
|
import * as pt from "./locales/pt";
|
|
36
36
|
import * as nl from "./locales/nl";
|
|
37
|
-
|
|
37
|
+
import * as zh from "./locales/zh";
|
|
38
|
+
export { de, fr, ja, pt, nl, zh };
|
|
38
39
|
export declare const strict: Chrono;
|
|
39
40
|
export declare const casual: Chrono;
|
|
40
41
|
export declare function parse(text: string, ref?: ParsingReference | Date, option?: ParsingOption): ParsedResult[];
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.parseDate = exports.parse = exports.casual = exports.strict = exports.nl = exports.pt = exports.ja = exports.fr = exports.de = exports.Meridiem = exports.Chrono = exports.en = void 0;
|
|
22
|
+
exports.parseDate = exports.parse = exports.casual = exports.strict = exports.zh = exports.nl = exports.pt = exports.ja = exports.fr = exports.de = exports.Meridiem = exports.Chrono = exports.en = void 0;
|
|
23
23
|
const en = __importStar(require("./locales/en"));
|
|
24
24
|
exports.en = en;
|
|
25
25
|
const chrono_1 = require("./chrono");
|
|
@@ -39,6 +39,8 @@ const pt = __importStar(require("./locales/pt"));
|
|
|
39
39
|
exports.pt = pt;
|
|
40
40
|
const nl = __importStar(require("./locales/nl"));
|
|
41
41
|
exports.nl = nl;
|
|
42
|
+
const zh = __importStar(require("./locales/zh"));
|
|
43
|
+
exports.zh = zh;
|
|
42
44
|
exports.strict = en.strict;
|
|
43
45
|
exports.casual = en.casual;
|
|
44
46
|
function parse(text, ref, option) {
|
|
@@ -100,7 +100,7 @@ exports.TIME_UNIT_DICTIONARY = {
|
|
|
100
100
|
year: "year",
|
|
101
101
|
years: "year",
|
|
102
102
|
};
|
|
103
|
-
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s*an?)?|an
|
|
103
|
+
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s*an?)?|an?\\b(?:\\s*few)?|few|several|a?\\s*couple\\s*(?:of)?)`;
|
|
104
104
|
function parseNumberPattern(match) {
|
|
105
105
|
const num = match.toLowerCase();
|
|
106
106
|
if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) {
|
|
@@ -126,7 +126,7 @@ exports.TIME_UNIT_DICTIONARY = {
|
|
|
126
126
|
year: "year",
|
|
127
127
|
years: "year",
|
|
128
128
|
};
|
|
129
|
-
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s{0,2}an?)?|an
|
|
129
|
+
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s{0,2}an?)?|an?\\b(?:\\s{0,2}few)?|few|several|a?\\s{0,2}couple\\s{0,2}(?:of)?)`;
|
|
130
130
|
function parseNumberPattern(match) {
|
|
131
131
|
const num = match.toLowerCase();
|
|
132
132
|
if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) {
|
|
@@ -22,15 +22,15 @@ class ENRelativeDateFormatParser extends AbstractParserWithWordBoundary_1.Abstra
|
|
|
22
22
|
if (modifier == "next") {
|
|
23
23
|
const timeUnits = {};
|
|
24
24
|
timeUnits[timeunit] = 1;
|
|
25
|
-
return results_1.ParsingComponents.
|
|
25
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
26
26
|
}
|
|
27
27
|
if (modifier == "last" || modifier == "past") {
|
|
28
28
|
const timeUnits = {};
|
|
29
29
|
timeUnits[timeunit] = -1;
|
|
30
|
-
return results_1.ParsingComponents.
|
|
30
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
31
31
|
}
|
|
32
32
|
const components = context.createParsingComponents();
|
|
33
|
-
let date = dayjs_1.default(context.
|
|
33
|
+
let date = dayjs_1.default(context.reference.instant);
|
|
34
34
|
if (unitWord.match(/week/i)) {
|
|
35
35
|
date = date.add(-date.get("d"), "d");
|
|
36
36
|
components.imply("day", date.date());
|
|
@@ -17,7 +17,7 @@ class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.Abstrac
|
|
|
17
17
|
innerExtract(context, match) {
|
|
18
18
|
const timeUnits = constants_1.parseTimeUnits(match[1]);
|
|
19
19
|
const outputTimeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
20
|
-
return results_1.ParsingComponents.
|
|
20
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.default = ENTimeUnitAgoFormatParser;
|
|
@@ -19,7 +19,7 @@ class ENTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundar
|
|
|
19
19
|
timeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
20
20
|
break;
|
|
21
21
|
}
|
|
22
|
-
return results_1.ParsingComponents.
|
|
22
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.default = ENTimeUnitCasualRelativeFormatParser;
|
|
@@ -16,7 +16,7 @@ class ENTimeUnitLaterFormatParser extends AbstractParserWithWordBoundary_1.Abstr
|
|
|
16
16
|
}
|
|
17
17
|
innerExtract(context, match) {
|
|
18
18
|
const fragments = constants_1.parseTimeUnits(match[GROUP_NUM_TIMEUNITS]);
|
|
19
|
-
return results_1.ParsingComponents.
|
|
19
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, fragments);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
exports.default = ENTimeUnitLaterFormatParser;
|
|
@@ -12,7 +12,7 @@ class ENTimeUnitWithinFormatParser extends AbstractParserWithWordBoundary_1.Abst
|
|
|
12
12
|
}
|
|
13
13
|
innerExtract(context, match) {
|
|
14
14
|
const timeUnits = constants_1.parseTimeUnits(match[1]);
|
|
15
|
-
return results_1.ParsingComponents.
|
|
15
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.default = ENTimeUnitWithinFormatParser;
|
|
@@ -98,7 +98,7 @@ exports.TIME_UNIT_DICTIONARY = {
|
|
|
98
98
|
"année": "year",
|
|
99
99
|
"années": "year",
|
|
100
100
|
};
|
|
101
|
-
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|une
|
|
101
|
+
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|une?\\b|quelques?|demi-?)`;
|
|
102
102
|
function parseNumberPattern(match) {
|
|
103
103
|
const num = match.toLowerCase();
|
|
104
104
|
if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) {
|
|
@@ -14,7 +14,7 @@ class FRTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.Abstrac
|
|
|
14
14
|
innerExtract(context, match) {
|
|
15
15
|
const timeUnits = constants_1.parseTimeUnits(match[1]);
|
|
16
16
|
const outputTimeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
17
|
-
return results_1.ParsingComponents.
|
|
17
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.default = FRTimeUnitAgoFormatParser;
|
|
@@ -29,7 +29,7 @@ class FRTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.Abstrac
|
|
|
29
29
|
if (/derni[eè]re?s?/.test(modifier) || /pass[ée]e?s?/.test(modifier) || /pr[ée]c[ée]dents?/.test(modifier)) {
|
|
30
30
|
timeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
31
31
|
}
|
|
32
|
-
return results_1.ParsingComponents.
|
|
32
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.default = FRTimeUnitAgoFormatParser;
|
|
@@ -9,7 +9,7 @@ class FRTimeUnitWithinFormatParser 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 = FRTimeUnitWithinFormatParser;
|
|
@@ -23,15 +23,15 @@ class NLRelativeDateFormatParser extends AbstractParserWithWordBoundary_1.Abstra
|
|
|
23
23
|
if (modifier == "volgend" || modifier == "volgende" || modifier == "komende") {
|
|
24
24
|
const timeUnits = {};
|
|
25
25
|
timeUnits[timeunit] = 1;
|
|
26
|
-
return results_1.ParsingComponents.
|
|
26
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
27
27
|
}
|
|
28
28
|
if (modifier == "afgelopen" || modifier == "vorige") {
|
|
29
29
|
const timeUnits = {};
|
|
30
30
|
timeUnits[timeunit] = -1;
|
|
31
|
-
return results_1.ParsingComponents.
|
|
31
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
32
32
|
}
|
|
33
33
|
const components = context.createParsingComponents();
|
|
34
|
-
let date = dayjs_1.default(context.
|
|
34
|
+
let date = dayjs_1.default(context.reference.instant);
|
|
35
35
|
if (unitWord.match(/week/i)) {
|
|
36
36
|
date = date.add(-date.get("d"), "d");
|
|
37
37
|
components.imply("day", date.date());
|
|
@@ -17,7 +17,7 @@ class NLTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.Abstrac
|
|
|
17
17
|
innerExtract(context, match) {
|
|
18
18
|
const timeUnits = constants_1.parseTimeUnits(match[1]);
|
|
19
19
|
const outputTimeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
20
|
-
return results_1.ParsingComponents.
|
|
20
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.default = NLTimeUnitAgoFormatParser;
|
|
@@ -19,7 +19,7 @@ class NLTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundar
|
|
|
19
19
|
timeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
20
20
|
break;
|
|
21
21
|
}
|
|
22
|
-
return results_1.ParsingComponents.
|
|
22
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.default = NLTimeUnitCasualRelativeFormatParser;
|
|
@@ -16,7 +16,7 @@ class NLTimeUnitLaterFormatParser extends AbstractParserWithWordBoundary_1.Abstr
|
|
|
16
16
|
}
|
|
17
17
|
innerExtract(context, match) {
|
|
18
18
|
const fragments = constants_1.parseTimeUnits(match[GROUP_NUM_TIMEUNITS]);
|
|
19
|
-
return results_1.ParsingComponents.
|
|
19
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, fragments);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const NUMBER: {
|
|
2
|
+
零: number;
|
|
3
|
+
〇: number;
|
|
4
|
+
一: number;
|
|
5
|
+
二: number;
|
|
6
|
+
两: number;
|
|
7
|
+
三: number;
|
|
8
|
+
四: number;
|
|
9
|
+
五: number;
|
|
10
|
+
六: number;
|
|
11
|
+
七: number;
|
|
12
|
+
八: number;
|
|
13
|
+
九: number;
|
|
14
|
+
十: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const WEEKDAY_OFFSET: {
|
|
17
|
+
天: number;
|
|
18
|
+
日: number;
|
|
19
|
+
一: number;
|
|
20
|
+
二: number;
|
|
21
|
+
三: number;
|
|
22
|
+
四: number;
|
|
23
|
+
五: number;
|
|
24
|
+
六: number;
|
|
25
|
+
};
|
|
26
|
+
export declare function zhStringToNumber(text: string): number;
|
|
27
|
+
export declare function zhStringToYear(text: string): number;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zhStringToYear = exports.zhStringToNumber = exports.WEEKDAY_OFFSET = exports.NUMBER = void 0;
|
|
4
|
+
exports.NUMBER = {
|
|
5
|
+
"零": 0,
|
|
6
|
+
"〇": 0,
|
|
7
|
+
"一": 1,
|
|
8
|
+
"二": 2,
|
|
9
|
+
"两": 2,
|
|
10
|
+
"三": 3,
|
|
11
|
+
"四": 4,
|
|
12
|
+
"五": 5,
|
|
13
|
+
"六": 6,
|
|
14
|
+
"七": 7,
|
|
15
|
+
"八": 8,
|
|
16
|
+
"九": 9,
|
|
17
|
+
"十": 10,
|
|
18
|
+
};
|
|
19
|
+
exports.WEEKDAY_OFFSET = {
|
|
20
|
+
"天": 0,
|
|
21
|
+
"日": 0,
|
|
22
|
+
"一": 1,
|
|
23
|
+
"二": 2,
|
|
24
|
+
"三": 3,
|
|
25
|
+
"四": 4,
|
|
26
|
+
"五": 5,
|
|
27
|
+
"六": 6,
|
|
28
|
+
};
|
|
29
|
+
function zhStringToNumber(text) {
|
|
30
|
+
let number = 0;
|
|
31
|
+
for (let i = 0; i < text.length; i++) {
|
|
32
|
+
const char = text[i];
|
|
33
|
+
if (char === "十") {
|
|
34
|
+
number = number === 0 ? exports.NUMBER[char] : number * exports.NUMBER[char];
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
number += exports.NUMBER[char];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return number;
|
|
41
|
+
}
|
|
42
|
+
exports.zhStringToNumber = zhStringToNumber;
|
|
43
|
+
function zhStringToYear(text) {
|
|
44
|
+
let string = "";
|
|
45
|
+
for (let i = 0; i < text.length; i++) {
|
|
46
|
+
const char = text[i];
|
|
47
|
+
string = string + exports.NUMBER[char];
|
|
48
|
+
}
|
|
49
|
+
return parseInt(string);
|
|
50
|
+
}
|
|
51
|
+
exports.zhStringToYear = zhStringToYear;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Chrono, Configuration } from "../../../chrono";
|
|
2
|
+
import { ParsedResult, ParsingOption } from "../../../index";
|
|
3
|
+
export declare const hans: Chrono;
|
|
4
|
+
export declare const casual: Chrono;
|
|
5
|
+
export declare const strict: Chrono;
|
|
6
|
+
export declare function parse(text: string, ref?: Date, option?: ParsingOption): ParsedResult[];
|
|
7
|
+
export declare function parseDate(text: string, ref?: Date, option?: ParsingOption): Date;
|
|
8
|
+
export declare function createCasualConfiguration(): Configuration;
|
|
9
|
+
export declare function createConfiguration(): Configuration;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = exports.hans = void 0;
|
|
7
|
+
const chrono_1 = require("../../../chrono");
|
|
8
|
+
const ExtractTimezoneOffsetRefiner_1 = __importDefault(require("../../../common/refiners/ExtractTimezoneOffsetRefiner"));
|
|
9
|
+
const configurations_1 = require("../../../configurations");
|
|
10
|
+
const ZHHansCasualDateParser_1 = __importDefault(require("./parsers/ZHHansCasualDateParser"));
|
|
11
|
+
const ZHHansDateParser_1 = __importDefault(require("./parsers/ZHHansDateParser"));
|
|
12
|
+
const ZHHansDeadlineFormatParser_1 = __importDefault(require("./parsers/ZHHansDeadlineFormatParser"));
|
|
13
|
+
const ZHHansRelationWeekdayParser_1 = __importDefault(require("./parsers/ZHHansRelationWeekdayParser"));
|
|
14
|
+
const ZHHansTimeExpressionParser_1 = __importDefault(require("./parsers/ZHHansTimeExpressionParser"));
|
|
15
|
+
const ZHHansWeekdayParser_1 = __importDefault(require("./parsers/ZHHansWeekdayParser"));
|
|
16
|
+
const ZHHansMergeDateRangeRefiner_1 = __importDefault(require("./refiners/ZHHansMergeDateRangeRefiner"));
|
|
17
|
+
const ZHHansMergeDateTimeRefiner_1 = __importDefault(require("./refiners/ZHHansMergeDateTimeRefiner"));
|
|
18
|
+
exports.hans = new chrono_1.Chrono(createCasualConfiguration());
|
|
19
|
+
exports.casual = new chrono_1.Chrono(createCasualConfiguration());
|
|
20
|
+
exports.strict = new chrono_1.Chrono(createConfiguration());
|
|
21
|
+
function parse(text, ref, option) {
|
|
22
|
+
return exports.casual.parse(text, ref, option);
|
|
23
|
+
}
|
|
24
|
+
exports.parse = parse;
|
|
25
|
+
function parseDate(text, ref, option) {
|
|
26
|
+
return exports.casual.parseDate(text, ref, option);
|
|
27
|
+
}
|
|
28
|
+
exports.parseDate = parseDate;
|
|
29
|
+
function createCasualConfiguration() {
|
|
30
|
+
const option = createConfiguration();
|
|
31
|
+
option.parsers.unshift(new ZHHansCasualDateParser_1.default());
|
|
32
|
+
return option;
|
|
33
|
+
}
|
|
34
|
+
exports.createCasualConfiguration = createCasualConfiguration;
|
|
35
|
+
function createConfiguration() {
|
|
36
|
+
const configuration = configurations_1.includeCommonConfiguration({
|
|
37
|
+
parsers: [
|
|
38
|
+
new ZHHansDateParser_1.default(),
|
|
39
|
+
new ZHHansRelationWeekdayParser_1.default(),
|
|
40
|
+
new ZHHansWeekdayParser_1.default(),
|
|
41
|
+
new ZHHansTimeExpressionParser_1.default(),
|
|
42
|
+
new ZHHansDeadlineFormatParser_1.default(),
|
|
43
|
+
],
|
|
44
|
+
refiners: [new ZHHansMergeDateRangeRefiner_1.default(), new ZHHansMergeDateTimeRefiner_1.default()],
|
|
45
|
+
});
|
|
46
|
+
configuration.refiners = configuration.refiners.filter((refiner) => !(refiner instanceof ExtractTimezoneOffsetRefiner_1.default));
|
|
47
|
+
return configuration;
|
|
48
|
+
}
|
|
49
|
+
exports.createConfiguration = createConfiguration;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../../chrono";
|
|
2
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../../common/parsers/AbstractParserWithWordBoundary";
|
|
3
|
+
import { ParsingComponents, ParsingResult } from "../../../../results";
|
|
4
|
+
export default class ZHHansCasualDateParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
innerPattern(context: ParsingContext): RegExp;
|
|
6
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | ParsingResult;
|
|
7
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
7
|
+
const AbstractParserWithWordBoundary_1 = require("../../../../common/parsers/AbstractParserWithWordBoundary");
|
|
8
|
+
const NOW_GROUP = 1;
|
|
9
|
+
const DAY_GROUP_1 = 2;
|
|
10
|
+
const TIME_GROUP_1 = 3;
|
|
11
|
+
const TIME_GROUP_2 = 4;
|
|
12
|
+
const DAY_GROUP_3 = 5;
|
|
13
|
+
const TIME_GROUP_3 = 6;
|
|
14
|
+
class ZHHansCasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
15
|
+
innerPattern(context) {
|
|
16
|
+
return new RegExp("(现在|立(?:刻|即)|即刻)|" +
|
|
17
|
+
"(今|明|前|大前|后|大后|昨)(早|晚)|" +
|
|
18
|
+
"(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" +
|
|
19
|
+
"(今|明|前|大前|后|大后|昨)(?:日|天)" +
|
|
20
|
+
"(?:[\\s|,|,]*)" +
|
|
21
|
+
"(?:(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?", "i");
|
|
22
|
+
}
|
|
23
|
+
innerExtract(context, match) {
|
|
24
|
+
const index = match.index;
|
|
25
|
+
const result = context.createParsingResult(index, match[0]);
|
|
26
|
+
const refMoment = dayjs_1.default(context.refDate);
|
|
27
|
+
let startMoment = refMoment;
|
|
28
|
+
if (match[NOW_GROUP]) {
|
|
29
|
+
result.start.imply("hour", refMoment.hour());
|
|
30
|
+
result.start.imply("minute", refMoment.minute());
|
|
31
|
+
result.start.imply("second", refMoment.second());
|
|
32
|
+
result.start.imply("millisecond", refMoment.millisecond());
|
|
33
|
+
}
|
|
34
|
+
else if (match[DAY_GROUP_1]) {
|
|
35
|
+
const day1 = match[DAY_GROUP_1];
|
|
36
|
+
const time1 = match[TIME_GROUP_1];
|
|
37
|
+
if (day1 == "明") {
|
|
38
|
+
if (refMoment.hour() > 1) {
|
|
39
|
+
startMoment = startMoment.add(1, "day");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (day1 == "昨") {
|
|
43
|
+
startMoment = startMoment.add(-1, "day");
|
|
44
|
+
}
|
|
45
|
+
else if (day1 == "前") {
|
|
46
|
+
startMoment = startMoment.add(-2, "day");
|
|
47
|
+
}
|
|
48
|
+
else if (day1 == "大前") {
|
|
49
|
+
startMoment = startMoment.add(-3, "day");
|
|
50
|
+
}
|
|
51
|
+
else if (day1 == "后") {
|
|
52
|
+
startMoment = startMoment.add(2, "day");
|
|
53
|
+
}
|
|
54
|
+
else if (day1 == "大后") {
|
|
55
|
+
startMoment = startMoment.add(3, "day");
|
|
56
|
+
}
|
|
57
|
+
if (time1 == "早") {
|
|
58
|
+
result.start.imply("hour", 6);
|
|
59
|
+
}
|
|
60
|
+
else if (time1 == "晚") {
|
|
61
|
+
result.start.imply("hour", 22);
|
|
62
|
+
result.start.imply("meridiem", 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (match[TIME_GROUP_2]) {
|
|
66
|
+
const timeString2 = match[TIME_GROUP_2];
|
|
67
|
+
const time2 = timeString2[0];
|
|
68
|
+
if (time2 == "早" || time2 == "上") {
|
|
69
|
+
result.start.imply("hour", 6);
|
|
70
|
+
}
|
|
71
|
+
else if (time2 == "下") {
|
|
72
|
+
result.start.imply("hour", 15);
|
|
73
|
+
result.start.imply("meridiem", 1);
|
|
74
|
+
}
|
|
75
|
+
else if (time2 == "中") {
|
|
76
|
+
result.start.imply("hour", 12);
|
|
77
|
+
result.start.imply("meridiem", 1);
|
|
78
|
+
}
|
|
79
|
+
else if (time2 == "夜" || time2 == "晚") {
|
|
80
|
+
result.start.imply("hour", 22);
|
|
81
|
+
result.start.imply("meridiem", 1);
|
|
82
|
+
}
|
|
83
|
+
else if (time2 == "凌") {
|
|
84
|
+
result.start.imply("hour", 0);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (match[DAY_GROUP_3]) {
|
|
88
|
+
const day3 = match[DAY_GROUP_3];
|
|
89
|
+
if (day3 == "明") {
|
|
90
|
+
if (refMoment.hour() > 1) {
|
|
91
|
+
startMoment = startMoment.add(1, "day");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (day3 == "昨") {
|
|
95
|
+
startMoment = startMoment.add(-1, "day");
|
|
96
|
+
}
|
|
97
|
+
else if (day3 == "前") {
|
|
98
|
+
startMoment = startMoment.add(-2, "day");
|
|
99
|
+
}
|
|
100
|
+
else if (day3 == "大前") {
|
|
101
|
+
startMoment = startMoment.add(-3, "day");
|
|
102
|
+
}
|
|
103
|
+
else if (day3 == "后") {
|
|
104
|
+
startMoment = startMoment.add(2, "day");
|
|
105
|
+
}
|
|
106
|
+
else if (day3 == "大后") {
|
|
107
|
+
startMoment = startMoment.add(3, "day");
|
|
108
|
+
}
|
|
109
|
+
const timeString3 = match[TIME_GROUP_3];
|
|
110
|
+
if (timeString3) {
|
|
111
|
+
const time3 = timeString3[0];
|
|
112
|
+
if (time3 == "早" || time3 == "上") {
|
|
113
|
+
result.start.imply("hour", 6);
|
|
114
|
+
}
|
|
115
|
+
else if (time3 == "下") {
|
|
116
|
+
result.start.imply("hour", 15);
|
|
117
|
+
result.start.imply("meridiem", 1);
|
|
118
|
+
}
|
|
119
|
+
else if (time3 == "中") {
|
|
120
|
+
result.start.imply("hour", 12);
|
|
121
|
+
result.start.imply("meridiem", 1);
|
|
122
|
+
}
|
|
123
|
+
else if (time3 == "夜" || time3 == "晚") {
|
|
124
|
+
result.start.imply("hour", 22);
|
|
125
|
+
result.start.imply("meridiem", 1);
|
|
126
|
+
}
|
|
127
|
+
else if (time3 == "凌") {
|
|
128
|
+
result.start.imply("hour", 0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
result.start.assign("day", startMoment.date());
|
|
133
|
+
result.start.assign("month", startMoment.month() + 1);
|
|
134
|
+
result.start.assign("year", startMoment.year());
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.default = ZHHansCasualDateParser;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../../chrono";
|
|
2
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../../common/parsers/AbstractParserWithWordBoundary";
|
|
3
|
+
export default class ZHHansDateParser extends AbstractParserWithWordBoundaryChecking {
|
|
4
|
+
innerPattern(): RegExp;
|
|
5
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): import("../../../../results").ParsingResult;
|
|
6
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
7
|
+
const AbstractParserWithWordBoundary_1 = require("../../../../common/parsers/AbstractParserWithWordBoundary");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const YEAR_GROUP = 1;
|
|
10
|
+
const MONTH_GROUP = 2;
|
|
11
|
+
const DAY_GROUP = 3;
|
|
12
|
+
class ZHHansDateParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
13
|
+
innerPattern() {
|
|
14
|
+
return new RegExp("(" +
|
|
15
|
+
"\\d{2,4}|" +
|
|
16
|
+
"[" +
|
|
17
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
18
|
+
"]{4}|" +
|
|
19
|
+
"[" +
|
|
20
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
21
|
+
"]{2}" +
|
|
22
|
+
")?" +
|
|
23
|
+
"(?:\\s*)" +
|
|
24
|
+
"(?:年)?" +
|
|
25
|
+
"(?:[\\s|,|,]*)" +
|
|
26
|
+
"(" +
|
|
27
|
+
"\\d{1,2}|" +
|
|
28
|
+
"[" +
|
|
29
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
30
|
+
"]{1,3}" +
|
|
31
|
+
")" +
|
|
32
|
+
"(?:\\s*)" +
|
|
33
|
+
"(?:月)" +
|
|
34
|
+
"(?:\\s*)" +
|
|
35
|
+
"(" +
|
|
36
|
+
"\\d{1,2}|" +
|
|
37
|
+
"[" +
|
|
38
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
39
|
+
"]{1,3}" +
|
|
40
|
+
")?" +
|
|
41
|
+
"(?:\\s*)" +
|
|
42
|
+
"(?:日|号)?");
|
|
43
|
+
}
|
|
44
|
+
innerExtract(context, match) {
|
|
45
|
+
const startMoment = dayjs_1.default(context.refDate);
|
|
46
|
+
const result = context.createParsingResult(match.index, match[0]);
|
|
47
|
+
let month = parseInt(match[MONTH_GROUP]);
|
|
48
|
+
if (isNaN(month))
|
|
49
|
+
month = constants_1.zhStringToNumber(match[MONTH_GROUP]);
|
|
50
|
+
result.start.assign("month", month);
|
|
51
|
+
if (match[DAY_GROUP]) {
|
|
52
|
+
let day = parseInt(match[DAY_GROUP]);
|
|
53
|
+
if (isNaN(day))
|
|
54
|
+
day = constants_1.zhStringToNumber(match[DAY_GROUP]);
|
|
55
|
+
result.start.assign("day", day);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
result.start.imply("day", startMoment.date());
|
|
59
|
+
}
|
|
60
|
+
if (match[YEAR_GROUP]) {
|
|
61
|
+
let year = parseInt(match[YEAR_GROUP]);
|
|
62
|
+
if (isNaN(year))
|
|
63
|
+
year = constants_1.zhStringToYear(match[YEAR_GROUP]);
|
|
64
|
+
result.start.assign("year", year);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
result.start.imply("year", startMoment.year());
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = ZHHansDateParser;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../../chrono";
|
|
2
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../../common/parsers/AbstractParserWithWordBoundary";
|
|
3
|
+
export default class ZHHansDeadlineFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
4
|
+
innerPattern(): RegExp;
|
|
5
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): import("../../../../results").ParsingResult;
|
|
6
|
+
}
|