chrono-node 2.3.0 → 2.3.4
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/benchmark/benchmark.js +4 -0
- package/dist/common/casualReferences.js +3 -1
- package/dist/common/refiners/ForwardDateRefiner.js +1 -1
- package/dist/locales/de/constants.js +1 -1
- package/dist/locales/en/constants.d.ts +1 -1
- package/dist/locales/en/constants.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/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/constants.js +8 -5
- package/dist/locales/nl/index.js +12 -3
- 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/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/pattern.js +1 -1
- package/package.json +1 -1
- package/src/common/casualReferences.ts +3 -1
- package/src/common/refiners/ForwardDateRefiner.ts +1 -1
- package/src/locales/de/constants.ts +1 -1
- package/src/locales/en/constants.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/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/constants.ts +11 -5
- package/src/locales/nl/index.ts +12 -3
- 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/results.ts +22 -12
- package/src/timezone.ts +5 -1
- package/src/utils/pattern.ts +1 -1
- package/test/en/en_casual.test.ts +11 -0
- package/test/en/en_month_name_little_endian.test.ts +10 -0
- package/test/en/en_relative.test.ts +8 -0
- package/test/en/en_slash.test.ts +11 -0
- package/test/en/en_timezone_exp.test.ts +85 -10
- 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/test_util.ts +5 -2
package/benchmark/benchmark.js
CHANGED
|
@@ -12,6 +12,10 @@ b.suite(
|
|
|
12
12
|
chrono.en.parseDate("11/12/2021");
|
|
13
13
|
}),
|
|
14
14
|
|
|
15
|
+
b.add("Parsing a long repeated space", () => {
|
|
16
|
+
chrono.parse(`second ${" ".repeat(1000)} fourth ${" ".repeat(1000)} jum`);
|
|
17
|
+
}),
|
|
18
|
+
|
|
15
19
|
b.cycle(),
|
|
16
20
|
b.complete(),
|
|
17
21
|
b.save({ file: "chrono", format: "chart.html" })
|
|
@@ -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;
|
|
@@ -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 {
|
|
@@ -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) {
|
|
@@ -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;
|
|
@@ -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) {
|
|
@@ -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;
|
|
@@ -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);
|
|
@@ -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;
|
|
@@ -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;
|
package/dist/results.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Component, ParsedComponents, ParsedResult, ParsingReference } from "./i
|
|
|
2
2
|
import dayjs, { OpUnitType, QUnitType } from "dayjs";
|
|
3
3
|
export declare class ReferenceWithTimezone {
|
|
4
4
|
readonly instant: Date;
|
|
5
|
-
readonly timezoneOffset
|
|
5
|
+
readonly timezoneOffset?: number;
|
|
6
6
|
constructor(input?: ParsingReference | Date);
|
|
7
7
|
}
|
|
8
8
|
export declare class ParsingComponents implements ParsedComponents {
|
|
@@ -29,7 +29,7 @@ export declare class ParsingComponents implements ParsedComponents {
|
|
|
29
29
|
date(): Date;
|
|
30
30
|
private dateWithoutTimezoneAdjustment;
|
|
31
31
|
private getSystemTimezoneAdjustmentMinute;
|
|
32
|
-
static
|
|
32
|
+
static createRelativeFromReference(reference: ReferenceWithTimezone, fragments: {
|
|
33
33
|
[c in OpUnitType | QUnitType]?: number;
|
|
34
34
|
}): ParsingComponents;
|
|
35
35
|
}
|
package/dist/results.js
CHANGED
|
@@ -11,7 +11,7 @@ const timezone_1 = require("./timezone");
|
|
|
11
11
|
dayjs_1.default.extend(quarterOfYear_1.default);
|
|
12
12
|
class ReferenceWithTimezone {
|
|
13
13
|
constructor(input) {
|
|
14
|
-
var _a
|
|
14
|
+
var _a;
|
|
15
15
|
input = input !== null && input !== void 0 ? input : new Date();
|
|
16
16
|
if (input instanceof Date) {
|
|
17
17
|
this.instant = input;
|
|
@@ -19,7 +19,7 @@ class ReferenceWithTimezone {
|
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
this.instant = (_a = input.instant) !== null && _a !== void 0 ? _a : new Date();
|
|
22
|
-
this.timezoneOffset = timezone_1.toTimezoneOffset(
|
|
22
|
+
this.timezoneOffset = timezone_1.toTimezoneOffset(input.timezone);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -120,34 +120,40 @@ class ParsingComponents {
|
|
|
120
120
|
}
|
|
121
121
|
date() {
|
|
122
122
|
const date = this.dateWithoutTimezoneAdjustment();
|
|
123
|
-
return new Date(date.getTime() + this.getSystemTimezoneAdjustmentMinute() * 60000);
|
|
123
|
+
return new Date(date.getTime() + this.getSystemTimezoneAdjustmentMinute(date) * 60000);
|
|
124
124
|
}
|
|
125
125
|
dateWithoutTimezoneAdjustment() {
|
|
126
126
|
const date = new Date(this.get("year"), this.get("month") - 1, this.get("day"), this.get("hour"), this.get("minute"), this.get("second"), this.get("millisecond"));
|
|
127
127
|
date.setFullYear(this.get("year"));
|
|
128
128
|
return date;
|
|
129
129
|
}
|
|
130
|
-
getSystemTimezoneAdjustmentMinute() {
|
|
131
|
-
var _a;
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
getSystemTimezoneAdjustmentMinute(date) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
if (!date || date.getTime() < 0) {
|
|
133
|
+
date = new Date();
|
|
134
|
+
}
|
|
135
|
+
const currentTimezoneOffset = -date.getTimezoneOffset();
|
|
136
|
+
const targetTimezoneOffset = (_b = (_a = this.get("timezoneOffset")) !== null && _a !== void 0 ? _a : this.reference.timezoneOffset) !== null && _b !== void 0 ? _b : currentTimezoneOffset;
|
|
134
137
|
return currentTimezoneOffset - targetTimezoneOffset;
|
|
135
138
|
}
|
|
136
|
-
static
|
|
137
|
-
let date = dayjs_1.default(
|
|
139
|
+
static createRelativeFromReference(reference, fragments) {
|
|
140
|
+
let date = dayjs_1.default(reference.instant);
|
|
138
141
|
for (const key in fragments) {
|
|
139
142
|
date = date.add(fragments[key], key);
|
|
140
143
|
}
|
|
141
|
-
const reference = new ReferenceWithTimezone(refInstant);
|
|
142
144
|
const components = new ParsingComponents(reference);
|
|
143
145
|
if (fragments["hour"] || fragments["minute"] || fragments["second"]) {
|
|
144
146
|
dayjs_2.assignSimilarTime(components, date);
|
|
145
147
|
dayjs_2.assignSimilarDate(components, date);
|
|
146
|
-
|
|
148
|
+
if (reference.timezoneOffset !== null) {
|
|
149
|
+
components.assign("timezoneOffset", -reference.instant.getTimezoneOffset());
|
|
150
|
+
}
|
|
147
151
|
}
|
|
148
152
|
else {
|
|
149
153
|
dayjs_2.implySimilarTime(components, date);
|
|
150
|
-
|
|
154
|
+
if (reference.timezoneOffset !== null) {
|
|
155
|
+
components.imply("timezoneOffset", -reference.instant.getTimezoneOffset());
|
|
156
|
+
}
|
|
151
157
|
if (fragments["d"]) {
|
|
152
158
|
components.assign("day", date.date());
|
|
153
159
|
components.assign("month", date.month() + 1);
|
package/dist/timezone.d.ts
CHANGED
|
@@ -191,4 +191,4 @@ export declare const TIMEZONE_ABBR_MAP: {
|
|
|
191
191
|
YEKST: number;
|
|
192
192
|
YEKT: number;
|
|
193
193
|
};
|
|
194
|
-
export declare function toTimezoneOffset(timezoneInput: string | number): number;
|
|
194
|
+
export declare function toTimezoneOffset(timezoneInput: string | number): number | null;
|