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
package/dist/chrono.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParsingComponents, ParsingResult } from "./results";
|
|
2
|
-
import { Component, ParsedResult, ParsingOption } from "./index";
|
|
1
|
+
import { ReferenceWithTimezone, ParsingComponents, ParsingResult } from "./results";
|
|
2
|
+
import { Component, ParsedResult, ParsingOption, ParsingReference } from "./index";
|
|
3
3
|
import { AsyncDebugBlock, DebugHandler } from "./debugging";
|
|
4
4
|
export interface Configuration {
|
|
5
5
|
parsers: Parser[];
|
|
@@ -19,15 +19,16 @@ export declare class Chrono {
|
|
|
19
19
|
refiners: Array<Refiner>;
|
|
20
20
|
constructor(configuration?: Configuration);
|
|
21
21
|
clone(): Chrono;
|
|
22
|
-
parseDate(text: string, referenceDate?: Date, option?: ParsingOption): Date | null;
|
|
23
|
-
parse(text: string, referenceDate?: Date, option?: ParsingOption): ParsedResult[];
|
|
22
|
+
parseDate(text: string, referenceDate?: ParsingReference | Date, option?: ParsingOption): Date | null;
|
|
23
|
+
parse(text: string, referenceDate?: ParsingReference | Date, option?: ParsingOption): ParsedResult[];
|
|
24
24
|
private static executeParser;
|
|
25
25
|
}
|
|
26
26
|
export declare class ParsingContext implements DebugHandler {
|
|
27
27
|
readonly text: string;
|
|
28
|
-
readonly refDate: Date;
|
|
29
28
|
readonly option: ParsingOption;
|
|
30
|
-
|
|
29
|
+
readonly reference: ReferenceWithTimezone;
|
|
30
|
+
readonly refDate: Date;
|
|
31
|
+
constructor(text: string, refDate?: ParsingReference | Date, option?: ParsingOption);
|
|
31
32
|
createParsingComponents(components?: {
|
|
32
33
|
[c in Component]?: number;
|
|
33
34
|
} | ParsingComponents): ParsingComponents;
|
package/dist/chrono.js
CHANGED
|
@@ -20,7 +20,7 @@ class Chrono {
|
|
|
20
20
|
return results.length > 0 ? results[0].start.date() : null;
|
|
21
21
|
}
|
|
22
22
|
parse(text, referenceDate, option) {
|
|
23
|
-
const context = new ParsingContext(text, referenceDate
|
|
23
|
+
const context = new ParsingContext(text, referenceDate, option);
|
|
24
24
|
let results = [];
|
|
25
25
|
this.parsers.forEach((parser) => {
|
|
26
26
|
const parsedResults = Chrono.executeParser(context, parser);
|
|
@@ -72,20 +72,21 @@ exports.Chrono = Chrono;
|
|
|
72
72
|
class ParsingContext {
|
|
73
73
|
constructor(text, refDate, option) {
|
|
74
74
|
this.text = text;
|
|
75
|
-
this.
|
|
76
|
-
this.option = option;
|
|
75
|
+
this.reference = new results_1.ReferenceWithTimezone(refDate);
|
|
76
|
+
this.option = option !== null && option !== void 0 ? option : {};
|
|
77
|
+
this.refDate = this.reference.instant;
|
|
77
78
|
}
|
|
78
79
|
createParsingComponents(components) {
|
|
79
80
|
if (components instanceof results_1.ParsingComponents) {
|
|
80
81
|
return components;
|
|
81
82
|
}
|
|
82
|
-
return new results_1.ParsingComponents(this.
|
|
83
|
+
return new results_1.ParsingComponents(this.reference, components);
|
|
83
84
|
}
|
|
84
85
|
createParsingResult(index, textOrEndIndex, startComponents, endComponents) {
|
|
85
86
|
const text = typeof textOrEndIndex === "string" ? textOrEndIndex : this.text.substring(index, textOrEndIndex);
|
|
86
87
|
const start = startComponents ? this.createParsingComponents(startComponents) : null;
|
|
87
88
|
const end = endComponents ? this.createParsingComponents(endComponents) : null;
|
|
88
|
-
return new results_1.ParsingResult(this.
|
|
89
|
+
return new results_1.ParsingResult(this.reference, index, text, start, end);
|
|
89
90
|
}
|
|
90
91
|
debug(block) {
|
|
91
92
|
if (this.option.debug) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ParsingComponents } from "../results";
|
|
2
|
-
export declare function now(
|
|
3
|
-
export declare function today(
|
|
4
|
-
export declare function yesterday(
|
|
5
|
-
export declare function tomorrow(
|
|
6
|
-
export declare function tonight(
|
|
1
|
+
import { ParsingComponents, ReferenceWithTimezone } from "../results";
|
|
2
|
+
export declare function now(reference: ReferenceWithTimezone): ParsingComponents;
|
|
3
|
+
export declare function today(reference: ReferenceWithTimezone): ParsingComponents;
|
|
4
|
+
export declare function yesterday(reference: ReferenceWithTimezone): ParsingComponents;
|
|
5
|
+
export declare function tomorrow(reference: ReferenceWithTimezone): ParsingComponents;
|
|
6
|
+
export declare function tonight(reference: ReferenceWithTimezone, implyHour?: number): ParsingComponents;
|
|
@@ -8,41 +8,42 @@ const results_1 = require("../results");
|
|
|
8
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
9
|
const dayjs_2 = require("../utils/dayjs");
|
|
10
10
|
const index_1 = require("../index");
|
|
11
|
-
function now(
|
|
12
|
-
const targetDate = dayjs_1.default(
|
|
13
|
-
const component = new results_1.ParsingComponents(
|
|
11
|
+
function now(reference) {
|
|
12
|
+
const targetDate = dayjs_1.default(reference.instant);
|
|
13
|
+
const component = new results_1.ParsingComponents(reference, {});
|
|
14
14
|
dayjs_2.assignSimilarDate(component, targetDate);
|
|
15
15
|
dayjs_2.assignSimilarTime(component, targetDate);
|
|
16
|
+
component.assign("timezoneOffset", targetDate.utcOffset());
|
|
16
17
|
return component;
|
|
17
18
|
}
|
|
18
19
|
exports.now = now;
|
|
19
|
-
function today(
|
|
20
|
-
const targetDate = dayjs_1.default(
|
|
21
|
-
const component = new results_1.ParsingComponents(
|
|
20
|
+
function today(reference) {
|
|
21
|
+
const targetDate = dayjs_1.default(reference.instant);
|
|
22
|
+
const component = new results_1.ParsingComponents(reference, {});
|
|
22
23
|
dayjs_2.assignSimilarDate(component, targetDate);
|
|
23
24
|
dayjs_2.implySimilarTime(component, targetDate);
|
|
24
25
|
return component;
|
|
25
26
|
}
|
|
26
27
|
exports.today = today;
|
|
27
|
-
function yesterday(
|
|
28
|
-
let targetDate = dayjs_1.default(
|
|
29
|
-
const component = new results_1.ParsingComponents(
|
|
28
|
+
function yesterday(reference) {
|
|
29
|
+
let targetDate = dayjs_1.default(reference.instant);
|
|
30
|
+
const component = new results_1.ParsingComponents(reference, {});
|
|
30
31
|
targetDate = targetDate.add(-1, "day");
|
|
31
32
|
dayjs_2.assignSimilarDate(component, targetDate);
|
|
32
33
|
dayjs_2.implySimilarTime(component, targetDate);
|
|
33
34
|
return component;
|
|
34
35
|
}
|
|
35
36
|
exports.yesterday = yesterday;
|
|
36
|
-
function tomorrow(
|
|
37
|
-
const targetDate = dayjs_1.default(
|
|
38
|
-
const component = new results_1.ParsingComponents(
|
|
37
|
+
function tomorrow(reference) {
|
|
38
|
+
const targetDate = dayjs_1.default(reference.instant);
|
|
39
|
+
const component = new results_1.ParsingComponents(reference, {});
|
|
39
40
|
dayjs_2.assignTheNextDay(component, targetDate);
|
|
40
41
|
return component;
|
|
41
42
|
}
|
|
42
43
|
exports.tomorrow = tomorrow;
|
|
43
|
-
function tonight(
|
|
44
|
-
const targetDate = dayjs_1.default(
|
|
45
|
-
const component = new results_1.ParsingComponents(
|
|
44
|
+
function tonight(reference, implyHour = 22) {
|
|
45
|
+
const targetDate = dayjs_1.default(reference.instant);
|
|
46
|
+
const component = new results_1.ParsingComponents(reference, {});
|
|
46
47
|
component.imply("hour", implyHour);
|
|
47
48
|
component.imply("meridiem", index_1.Meridiem.PM);
|
|
48
49
|
dayjs_2.assignSimilarDate(component, targetDate);
|
|
@@ -26,7 +26,7 @@ class ForwardDateRefiner {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
if (result.start.isOnlyWeekdayComponent() && refMoment.isAfter(result.start.dayjs())) {
|
|
29
|
-
if (refMoment.day()
|
|
29
|
+
if (refMoment.day() >= result.start.get("weekday")) {
|
|
30
30
|
refMoment = refMoment.day(result.start.get("weekday") + 7);
|
|
31
31
|
}
|
|
32
32
|
else {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,13 @@ export { en, Chrono, Parser, Refiner };
|
|
|
4
4
|
export interface ParsingOption {
|
|
5
5
|
forwardDate?: boolean;
|
|
6
6
|
timezones?: {
|
|
7
|
-
string: number;
|
|
7
|
+
[tzKeyword: string]: number;
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
+
export interface ParsingReference {
|
|
11
|
+
instant?: Date;
|
|
12
|
+
timezone?: string | number;
|
|
13
|
+
}
|
|
10
14
|
export interface ParsedResult {
|
|
11
15
|
readonly refDate: Date;
|
|
12
16
|
readonly index: number;
|
|
@@ -33,5 +37,5 @@ import * as nl from "./locales/nl";
|
|
|
33
37
|
export { de, fr, ja, pt, nl };
|
|
34
38
|
export declare const strict: Chrono;
|
|
35
39
|
export declare const casual: Chrono;
|
|
36
|
-
export declare function parse(text: string, ref?: Date, option?: ParsingOption): ParsedResult[];
|
|
37
|
-
export declare function parseDate(text: string, ref?: Date, option?: ParsingOption): Date;
|
|
40
|
+
export declare function parse(text: string, ref?: ParsingReference | Date, option?: ParsingOption): ParsedResult[];
|
|
41
|
+
export declare function parseDate(text: string, ref?: ParsingReference | Date, option?: ParsingOption): Date;
|
|
@@ -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) {
|
|
@@ -43,10 +43,10 @@ class DECasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParser
|
|
|
43
43
|
let component = context.createParsingComponents();
|
|
44
44
|
switch (dateKeyword) {
|
|
45
45
|
case "jetzt":
|
|
46
|
-
component = references.now(context.
|
|
46
|
+
component = references.now(context.reference);
|
|
47
47
|
break;
|
|
48
48
|
case "heute":
|
|
49
|
-
component = references.today(context.
|
|
49
|
+
component = references.today(context.reference);
|
|
50
50
|
break;
|
|
51
51
|
case "morgen":
|
|
52
52
|
dayjs_2.assignTheNextDay(component, targetDate);
|
|
@@ -22,7 +22,7 @@ export declare const NUMBER_PATTERN: string;
|
|
|
22
22
|
export declare function parseNumberPattern(match: string): number;
|
|
23
23
|
export declare const ORDINAL_NUMBER_PATTERN: string;
|
|
24
24
|
export declare function parseOrdinalNumberPattern(match: string): number;
|
|
25
|
-
export declare const YEAR_PATTERN = "(?:[1-9][0-9]{0,3}\\s
|
|
25
|
+
export declare const YEAR_PATTERN = "(?:[1-9][0-9]{0,3}\\s{0,2}(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])";
|
|
26
26
|
export declare function parseYear(match: string): number;
|
|
27
27
|
export declare const TIME_UNITS_PATTERN: string;
|
|
28
28
|
export declare function parseTimeUnits(timeunitText: any): TimeUnits;
|
|
@@ -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
|
|
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) {
|
|
@@ -160,7 +160,7 @@ function parseOrdinalNumberPattern(match) {
|
|
|
160
160
|
return parseInt(num);
|
|
161
161
|
}
|
|
162
162
|
exports.parseOrdinalNumberPattern = parseOrdinalNumberPattern;
|
|
163
|
-
exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s
|
|
163
|
+
exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s{0,2}(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`;
|
|
164
164
|
function parseYear(match) {
|
|
165
165
|
if (/BE/i.test(match)) {
|
|
166
166
|
match = match.replace(/BE/i, "");
|
|
@@ -178,16 +178,16 @@ function parseYear(match) {
|
|
|
178
178
|
return years_1.findMostLikelyADYear(rawYearNumber);
|
|
179
179
|
}
|
|
180
180
|
exports.parseYear = parseYear;
|
|
181
|
-
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,
|
|
181
|
+
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,3}(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})`;
|
|
182
182
|
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i");
|
|
183
|
-
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern(`(?:(?:about|around)\\s
|
|
183
|
+
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_PATTERN);
|
|
184
184
|
function parseTimeUnits(timeunitText) {
|
|
185
185
|
const fragments = {};
|
|
186
186
|
let remainingText = timeunitText;
|
|
187
187
|
let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText);
|
|
188
188
|
while (match) {
|
|
189
189
|
collectDateTimeFragment(fragments, match);
|
|
190
|
-
remainingText = remainingText.substring(match[0].length);
|
|
190
|
+
remainingText = remainingText.substring(match[0].length).trim();
|
|
191
191
|
match = SINGLE_TIME_UNIT_REGEX.exec(remainingText);
|
|
192
192
|
}
|
|
193
193
|
return fragments;
|
|
@@ -37,17 +37,17 @@ class ENCasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParser
|
|
|
37
37
|
const component = context.createParsingComponents();
|
|
38
38
|
switch (lowerText) {
|
|
39
39
|
case "now":
|
|
40
|
-
return references.now(context.
|
|
40
|
+
return references.now(context.reference);
|
|
41
41
|
case "today":
|
|
42
|
-
return references.today(context.
|
|
42
|
+
return references.today(context.reference);
|
|
43
43
|
case "yesterday":
|
|
44
|
-
return references.yesterday(context.
|
|
44
|
+
return references.yesterday(context.reference);
|
|
45
45
|
case "tomorrow":
|
|
46
46
|
case "tmr":
|
|
47
47
|
case "tmrw":
|
|
48
|
-
return references.tomorrow(context.
|
|
48
|
+
return references.tomorrow(context.reference);
|
|
49
49
|
case "tonight":
|
|
50
|
-
return references.tonight(context.
|
|
50
|
+
return references.tonight(context.reference);
|
|
51
51
|
default:
|
|
52
52
|
if (lowerText.match(/last\s*night/)) {
|
|
53
53
|
if (targetDate.hour() > 6) {
|
|
@@ -7,7 +7,7 @@ const index_1 = require("../../../index");
|
|
|
7
7
|
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
8
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
9
|
const dayjs_2 = require("../../../utils/dayjs");
|
|
10
|
-
const PATTERN = /(?:this)?\s
|
|
10
|
+
const PATTERN = /(?:this)?\s{0,3}(morning|afternoon|evening|night|midnight|noon)(?=\W|$)/i;
|
|
11
11
|
class ENCasualTimeParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
12
12
|
innerPattern() {
|
|
13
13
|
return PATTERN;
|
|
@@ -6,18 +6,16 @@ const constants_2 = require("../constants");
|
|
|
6
6
|
const constants_3 = require("../constants");
|
|
7
7
|
const pattern_1 = require("../../../utils/pattern");
|
|
8
8
|
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
9
|
-
const PATTERN = new RegExp(
|
|
9
|
+
const PATTERN = new RegExp(`(?:on\\s{0,3})?` +
|
|
10
10
|
`(${constants_3.ORDINAL_NUMBER_PATTERN})` +
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
`(?:` +
|
|
12
|
+
`\\s{0,3}(?:to|\\-|\\–|until|through|till)?\\s{0,3}` +
|
|
13
13
|
`(${constants_3.ORDINAL_NUMBER_PATTERN})` +
|
|
14
14
|
")?" +
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
pattern_1.matchAnyPattern(constants_1.MONTH_DICTIONARY) +
|
|
18
|
-
")" +
|
|
15
|
+
`(?:-|/|\\s{0,3}(?:of)?\\s{0,3})` +
|
|
16
|
+
`(${pattern_1.matchAnyPattern(constants_1.MONTH_DICTIONARY)})` +
|
|
19
17
|
"(?:" +
|
|
20
|
-
|
|
18
|
+
`(?:-|/|,?\\s{0,3})` +
|
|
21
19
|
`(${constants_2.YEAR_PATTERN}(?![^\\s]\\d))` +
|
|
22
20
|
")?" +
|
|
23
21
|
"(?=\\W|$)", "i");
|
|
@@ -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());
|
|
@@ -4,8 +4,8 @@ const constants_1 = require("../constants");
|
|
|
4
4
|
const results_1 = require("../../../results");
|
|
5
5
|
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
6
6
|
const timeunits_1 = require("../../../utils/timeunits");
|
|
7
|
-
const PATTERN = new RegExp(
|
|
8
|
-
const STRICT_PATTERN = new RegExp(
|
|
7
|
+
const PATTERN = new RegExp(`(${constants_1.TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=(?:\\W|$))`, "i");
|
|
8
|
+
const STRICT_PATTERN = new RegExp(`(${constants_1.TIME_UNITS_PATTERN})\\s{0,5}ago(?=(?:\\W|$))`, "i");
|
|
9
9
|
class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
10
10
|
constructor(strictMode) {
|
|
11
11
|
super();
|
|
@@ -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;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const constants_1 = require("../constants");
|
|
4
4
|
const results_1 = require("../../../results");
|
|
5
5
|
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
6
|
-
const PATTERN = new RegExp(
|
|
6
|
+
const PATTERN = new RegExp(`(${constants_1.TIME_UNITS_PATTERN})\\s{0,5}(?:later|after|from now|henceforth|forward|out)` + "(?=(?:\\W|$))", "i");
|
|
7
7
|
const STRICT_PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(later|from now)" + "(?=(?:\\W|$))", "i");
|
|
8
8
|
const GROUP_NUM_TIMEUNITS = 1;
|
|
9
9
|
class ENTimeUnitLaterFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
@@ -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) {
|
|
@@ -37,13 +37,13 @@ class FRCasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParser
|
|
|
37
37
|
const component = context.createParsingComponents();
|
|
38
38
|
switch (lowerText) {
|
|
39
39
|
case "maintenant":
|
|
40
|
-
return references.now(context.
|
|
40
|
+
return references.now(context.reference);
|
|
41
41
|
case "aujourd'hui":
|
|
42
|
-
return references.today(context.
|
|
42
|
+
return references.today(context.reference);
|
|
43
43
|
case "hier":
|
|
44
|
-
return references.yesterday(context.
|
|
44
|
+
return references.yesterday(context.reference);
|
|
45
45
|
case "demain":
|
|
46
|
-
return references.tomorrow(context.
|
|
46
|
+
return references.tomorrow(context.reference);
|
|
47
47
|
default:
|
|
48
48
|
if (lowerText.match(/cette\s*nuit/)) {
|
|
49
49
|
dayjs_2.assignSimilarDate(component, targetDate);
|
|
@@ -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;
|
|
@@ -36,12 +36,12 @@ class JPCasualDateParser {
|
|
|
36
36
|
const components = context.createParsingComponents();
|
|
37
37
|
switch (text) {
|
|
38
38
|
case "昨日":
|
|
39
|
-
return references.yesterday(context.
|
|
39
|
+
return references.yesterday(context.reference);
|
|
40
40
|
case "明日":
|
|
41
|
-
return references.tomorrow(context.
|
|
41
|
+
return references.tomorrow(context.reference);
|
|
42
42
|
case "今日":
|
|
43
43
|
case "当日":
|
|
44
|
-
return references.today(context.
|
|
44
|
+
return references.today(context.reference);
|
|
45
45
|
}
|
|
46
46
|
if (text == "今夜" || text == "今夕" || text == "今晩") {
|
|
47
47
|
components.imply("hour", 22);
|
|
@@ -130,11 +130,14 @@ exports.TIME_UNIT_DICTIONARY = {
|
|
|
130
130
|
min: "minute",
|
|
131
131
|
mins: "minute",
|
|
132
132
|
minute: "minute",
|
|
133
|
+
minuut: "minute",
|
|
133
134
|
minuten: "minute",
|
|
135
|
+
minuutje: "minute",
|
|
134
136
|
h: "hour",
|
|
135
137
|
hr: "hour",
|
|
136
138
|
hrs: "hour",
|
|
137
139
|
uur: "hour",
|
|
140
|
+
u: "hour",
|
|
138
141
|
uren: "hour",
|
|
139
142
|
dag: "d",
|
|
140
143
|
dagen: "d",
|
|
@@ -146,19 +149,19 @@ exports.TIME_UNIT_DICTIONARY = {
|
|
|
146
149
|
jr: "year",
|
|
147
150
|
jaren: "year",
|
|
148
151
|
};
|
|
149
|
-
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]
|
|
152
|
+
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+[\\.,][0-9]+|halve?|half|paar)`;
|
|
150
153
|
function parseNumberPattern(match) {
|
|
151
154
|
const num = match.toLowerCase();
|
|
152
155
|
if (exports.INTEGER_WORD_DICTIONARY[num] !== undefined) {
|
|
153
156
|
return exports.INTEGER_WORD_DICTIONARY[num];
|
|
154
157
|
}
|
|
155
|
-
else if (num === "
|
|
156
|
-
return
|
|
158
|
+
else if (num === "paar") {
|
|
159
|
+
return 2;
|
|
157
160
|
}
|
|
158
|
-
else if (num.match(/halve?/)) {
|
|
161
|
+
else if (num === "half" || num.match(/halve?/)) {
|
|
159
162
|
return 0.5;
|
|
160
163
|
}
|
|
161
|
-
return parseFloat(num);
|
|
164
|
+
return parseFloat(num.replace(",", "."));
|
|
162
165
|
}
|
|
163
166
|
exports.parseNumberPattern = parseNumberPattern;
|
|
164
167
|
exports.ORDINAL_NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.ORDINAL_WORD_DICTIONARY)}|[0-9]{1,2}(?:ste|de)?)`;
|
package/dist/locales/nl/index.js
CHANGED
|
@@ -19,6 +19,10 @@ const NLSlashMonthFormatParser_1 = __importDefault(require("./parsers/NLSlashMon
|
|
|
19
19
|
const NLTimeExpressionParser_1 = __importDefault(require("./parsers/NLTimeExpressionParser"));
|
|
20
20
|
const NLCasualYearMonthDayParser_1 = __importDefault(require("./parsers/NLCasualYearMonthDayParser"));
|
|
21
21
|
const NLCasualDateTimeParser_1 = __importDefault(require("./parsers/NLCasualDateTimeParser"));
|
|
22
|
+
const NLTimeUnitCasualRelativeFormatParser_1 = __importDefault(require("./parsers/NLTimeUnitCasualRelativeFormatParser"));
|
|
23
|
+
const NLRelativeDateFormatParser_1 = __importDefault(require("./parsers/NLRelativeDateFormatParser"));
|
|
24
|
+
const NLTimeUnitAgoFormatParser_1 = __importDefault(require("./parsers/NLTimeUnitAgoFormatParser"));
|
|
25
|
+
const NLTimeUnitLaterFormatParser_1 = __importDefault(require("./parsers/NLTimeUnitLaterFormatParser"));
|
|
22
26
|
exports.casual = new chrono_1.Chrono(createCasualConfiguration());
|
|
23
27
|
exports.strict = new chrono_1.Chrono(createConfiguration(true));
|
|
24
28
|
function parse(text, ref, option) {
|
|
@@ -34,6 +38,9 @@ function createCasualConfiguration(littleEndian = true) {
|
|
|
34
38
|
option.parsers.unshift(new NLCasualDateParser_1.default());
|
|
35
39
|
option.parsers.unshift(new NLCasualTimeParser_1.default());
|
|
36
40
|
option.parsers.unshift(new NLCasualDateTimeParser_1.default());
|
|
41
|
+
option.parsers.unshift(new NLMonthNameParser_1.default());
|
|
42
|
+
option.parsers.unshift(new NLRelativeDateFormatParser_1.default());
|
|
43
|
+
option.parsers.unshift(new NLTimeUnitCasualRelativeFormatParser_1.default());
|
|
37
44
|
return option;
|
|
38
45
|
}
|
|
39
46
|
exports.createCasualConfiguration = createCasualConfiguration;
|
|
@@ -41,13 +48,15 @@ function createConfiguration(strictMode = true, littleEndian = true) {
|
|
|
41
48
|
return configurations_1.includeCommonConfiguration({
|
|
42
49
|
parsers: [
|
|
43
50
|
new SlashDateFormatParser_1.default(littleEndian),
|
|
51
|
+
new NLTimeUnitWithinFormatParser_1.default(),
|
|
44
52
|
new NLMonthNameMiddleEndianParser_1.default(),
|
|
45
53
|
new NLMonthNameParser_1.default(),
|
|
46
|
-
new NLTimeExpressionParser_1.default(),
|
|
47
|
-
new NLTimeUnitWithinFormatParser_1.default(),
|
|
48
|
-
new NLSlashMonthFormatParser_1.default(),
|
|
49
54
|
new NLWeekdayParser_1.default(),
|
|
50
55
|
new NLCasualYearMonthDayParser_1.default(),
|
|
56
|
+
new NLSlashMonthFormatParser_1.default(),
|
|
57
|
+
new NLTimeExpressionParser_1.default(strictMode),
|
|
58
|
+
new NLTimeUnitAgoFormatParser_1.default(strictMode),
|
|
59
|
+
new NLTimeUnitLaterFormatParser_1.default(strictMode),
|
|
51
60
|
],
|
|
52
61
|
refiners: [new NLMergeDateTimeRefiner_1.default(), new NLMergeDateRangeRefiner_1.default()],
|
|
53
62
|
}, strictMode);
|
|
@@ -30,14 +30,14 @@ class NLCasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParser
|
|
|
30
30
|
const component = context.createParsingComponents();
|
|
31
31
|
switch (lowerText) {
|
|
32
32
|
case "nu":
|
|
33
|
-
return references.now(context.
|
|
33
|
+
return references.now(context.reference);
|
|
34
34
|
case "vandaag":
|
|
35
|
-
return references.today(context.
|
|
35
|
+
return references.today(context.reference);
|
|
36
36
|
case "morgen":
|
|
37
37
|
case "morgend":
|
|
38
|
-
return references.tomorrow(context.
|
|
38
|
+
return references.tomorrow(context.reference);
|
|
39
39
|
case "gisteren":
|
|
40
|
-
return references.yesterday(context.
|
|
40
|
+
return references.yesterday(context.reference);
|
|
41
41
|
}
|
|
42
42
|
return component;
|
|
43
43
|
}
|
|
@@ -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 NLRelativeDateFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
innerPattern(): RegExp;
|
|
6
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents;
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 constants_1 = require("../constants");
|
|
7
|
+
const results_1 = require("../../../results");
|
|
8
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
|
+
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
|
10
|
+
const pattern_1 = require("../../../utils/pattern");
|
|
11
|
+
const PATTERN = new RegExp(`(dit|deze|komende|volgend|volgende|afgelopen|vorige)\\s*(${pattern_1.matchAnyPattern(constants_1.TIME_UNIT_DICTIONARY)})(?=\\s*)` +
|
|
12
|
+
"(?=\\W|$)", "i");
|
|
13
|
+
const MODIFIER_WORD_GROUP = 1;
|
|
14
|
+
const RELATIVE_WORD_GROUP = 2;
|
|
15
|
+
class NLRelativeDateFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
16
|
+
innerPattern() {
|
|
17
|
+
return PATTERN;
|
|
18
|
+
}
|
|
19
|
+
innerExtract(context, match) {
|
|
20
|
+
const modifier = match[MODIFIER_WORD_GROUP].toLowerCase();
|
|
21
|
+
const unitWord = match[RELATIVE_WORD_GROUP].toLowerCase();
|
|
22
|
+
const timeunit = constants_1.TIME_UNIT_DICTIONARY[unitWord];
|
|
23
|
+
if (modifier == "volgend" || modifier == "volgende" || modifier == "komende") {
|
|
24
|
+
const timeUnits = {};
|
|
25
|
+
timeUnits[timeunit] = 1;
|
|
26
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
27
|
+
}
|
|
28
|
+
if (modifier == "afgelopen" || modifier == "vorige") {
|
|
29
|
+
const timeUnits = {};
|
|
30
|
+
timeUnits[timeunit] = -1;
|
|
31
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
32
|
+
}
|
|
33
|
+
const components = context.createParsingComponents();
|
|
34
|
+
let date = dayjs_1.default(context.reference.instant);
|
|
35
|
+
if (unitWord.match(/week/i)) {
|
|
36
|
+
date = date.add(-date.get("d"), "d");
|
|
37
|
+
components.imply("day", date.date());
|
|
38
|
+
components.imply("month", date.month() + 1);
|
|
39
|
+
components.imply("year", date.year());
|
|
40
|
+
}
|
|
41
|
+
else if (unitWord.match(/maand/i)) {
|
|
42
|
+
date = date.add(-date.date() + 1, "d");
|
|
43
|
+
components.imply("day", date.date());
|
|
44
|
+
components.assign("year", date.year());
|
|
45
|
+
components.assign("month", date.month() + 1);
|
|
46
|
+
}
|
|
47
|
+
else if (unitWord.match(/jaar/i)) {
|
|
48
|
+
date = date.add(-date.date() + 1, "d");
|
|
49
|
+
date = date.add(-date.month(), "month");
|
|
50
|
+
components.imply("day", date.date());
|
|
51
|
+
components.imply("month", date.month() + 1);
|
|
52
|
+
components.assign("year", date.year());
|
|
53
|
+
}
|
|
54
|
+
return components;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = NLRelativeDateFormatParser;
|