chrono-node 2.3.7 → 2.3.8
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/dist/common/refiners/ExtractTimezoneAbbrRefiner.js +1 -1
- package/dist/locales/de/constants.d.ts +3 -3
- package/dist/locales/de/constants.js +38 -20
- package/dist/locales/de/index.js +4 -0
- package/dist/locales/de/parsers/DESpecificTimeExpressionParser.d.ts +7 -0
- package/dist/locales/de/parsers/DESpecificTimeExpressionParser.js +114 -0
- package/dist/locales/de/parsers/DETimeExpressionParser.d.ts +0 -1
- package/dist/locales/de/parsers/DETimeExpressionParser.js +3 -21
- package/dist/locales/de/parsers/DETimeUnitRelativeFormatParser.d.ts +8 -0
- package/dist/locales/de/parsers/DETimeUnitRelativeFormatParser.js +34 -0
- package/dist/locales/en/constants.d.ts +2 -2
- package/dist/locales/en/constants.js +3 -0
- package/dist/results.d.ts +1 -1
- package/dist/results.js +1 -2
- package/dist/timezone.d.ts +1 -1
- package/dist/timezone.js +2 -2
- package/package.json +1 -1
- package/src/common/refiners/ExtractTimezoneAbbrRefiner.ts +3 -1
- package/src/locales/de/constants.ts +42 -22
- package/src/locales/de/index.ts +4 -0
- package/src/locales/de/parsers/DESpecificTimeExpressionParser.ts +150 -0
- package/src/locales/de/parsers/DETimeExpressionParser.ts +4 -23
- package/src/locales/de/parsers/DETimeUnitRelativeFormatParser.ts +42 -0
- package/src/locales/en/constants.ts +5 -2
- package/src/results.ts +2 -3
- package/src/timezone.ts +3 -3
- package/test/de/de_month_name_little_endian.test.ts +12 -0
- package/test/de/de_time_exp.test.ts +59 -0
- package/test/de/de_time_units_casual_relative.test.ts +108 -0
- package/test/de/de_year.test.ts +147 -0
- package/test/en/en_relative.test.ts +41 -2
- package/test/en/en_time_units_ago.test.ts +3 -3
- package/test/en/en_time_units_within.test.ts +2 -2
- package/test/en/en_timezone_exp.test.ts +3 -3
- package/test/fr/fr_time_units_ago.test.ts +3 -3
- package/test/fr/fr_time_units_within.test.ts +2 -2
- package/test/nl/nl_relative.test.ts +2 -2
- package/test/nl/nl_time_units_ago.test.ts +3 -3
- package/test/system_timezone.test.ts +22 -0
|
@@ -214,7 +214,7 @@ class ExtractTimezoneAbbrRefiner {
|
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
216
|
context.debug(() => {
|
|
217
|
-
console.log(`Extracting timezone: '${timezoneAbbr}' into
|
|
217
|
+
console.log(`Extracting timezone: '${timezoneAbbr}' into: ${extractedTimezoneOffset} for: ${result.start}`);
|
|
218
218
|
});
|
|
219
219
|
const currentTimezoneOffset = result.start.get("timezoneOffset");
|
|
220
220
|
if (currentTimezoneOffset !== null && extractedTimezoneOffset != currentTimezoneOffset) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpUnitType } from "dayjs";
|
|
1
|
+
import { OpUnitType, QUnitType } from "dayjs";
|
|
2
2
|
import { TimeUnits } from "../../utils/timeunits";
|
|
3
3
|
export declare const WEEKDAY_DICTIONARY: {
|
|
4
4
|
[word: string]: number;
|
|
@@ -10,11 +10,11 @@ export declare const INTEGER_WORD_DICTIONARY: {
|
|
|
10
10
|
[word: string]: number;
|
|
11
11
|
};
|
|
12
12
|
export declare const TIME_UNIT_DICTIONARY: {
|
|
13
|
-
[word: string]: OpUnitType;
|
|
13
|
+
[word: string]: OpUnitType | QUnitType;
|
|
14
14
|
};
|
|
15
15
|
export declare const NUMBER_PATTERN: string;
|
|
16
16
|
export declare function parseNumberPattern(match: string): number;
|
|
17
|
-
export declare const YEAR_PATTERN = "(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*C(?:hr)
|
|
17
|
+
export declare const YEAR_PATTERN = "(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*(?:C(?:hr)?|(?:u\\.?|d\\.?(?:\\s*g\\.?)?)?\\s*Z)\\.?|\\s*(?:u\\.?|d\\.?(?:\\s*g\\.)?)\\s*Z\\.?)?)";
|
|
18
18
|
export declare function parseYear(match: string): number;
|
|
19
19
|
export declare const TIME_UNITS_PATTERN: string;
|
|
20
20
|
export declare function parseTimeUnits(timeunitText: any): TimeUnits;
|
|
@@ -21,9 +21,12 @@ exports.WEEKDAY_DICTIONARY = {
|
|
|
21
21
|
};
|
|
22
22
|
exports.MONTH_DICTIONARY = {
|
|
23
23
|
"januar": 1,
|
|
24
|
+
"jänner": 1,
|
|
25
|
+
"janner": 1,
|
|
24
26
|
"jan": 1,
|
|
25
27
|
"jan.": 1,
|
|
26
28
|
"februar": 2,
|
|
29
|
+
"feber": 2,
|
|
27
30
|
"feb": 2,
|
|
28
31
|
"feb.": 2,
|
|
29
32
|
"märz": 3,
|
|
@@ -62,6 +65,10 @@ exports.MONTH_DICTIONARY = {
|
|
|
62
65
|
};
|
|
63
66
|
exports.INTEGER_WORD_DICTIONARY = {
|
|
64
67
|
"eins": 1,
|
|
68
|
+
"eine": 1,
|
|
69
|
+
"einem": 1,
|
|
70
|
+
"einen": 1,
|
|
71
|
+
"einer": 1,
|
|
65
72
|
"zwei": 2,
|
|
66
73
|
"drei": 3,
|
|
67
74
|
"vier": 4,
|
|
@@ -77,28 +84,36 @@ exports.INTEGER_WORD_DICTIONARY = {
|
|
|
77
84
|
"zwoelf": 12,
|
|
78
85
|
};
|
|
79
86
|
exports.TIME_UNIT_DICTIONARY = {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
sek: "second",
|
|
88
|
+
sekunde: "second",
|
|
89
|
+
sekunden: "second",
|
|
83
90
|
min: "minute",
|
|
84
|
-
mins: "minute",
|
|
85
91
|
minute: "minute",
|
|
86
|
-
|
|
92
|
+
minuten: "minute",
|
|
87
93
|
h: "hour",
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
std: "hour",
|
|
95
|
+
stunde: "hour",
|
|
96
|
+
stunden: "hour",
|
|
97
|
+
tag: "d",
|
|
98
|
+
tage: "d",
|
|
99
|
+
tagen: "d",
|
|
100
|
+
woche: "week",
|
|
101
|
+
wochen: "week",
|
|
102
|
+
monat: "month",
|
|
103
|
+
monate: "month",
|
|
104
|
+
monaten: "month",
|
|
105
|
+
monats: "month",
|
|
106
|
+
quartal: "quarter",
|
|
107
|
+
quartals: "quarter",
|
|
108
|
+
quartale: "quarter",
|
|
109
|
+
quartalen: "quarter",
|
|
110
|
+
a: "year",
|
|
111
|
+
j: "year",
|
|
112
|
+
jr: "year",
|
|
113
|
+
jahr: "year",
|
|
114
|
+
jahre: "year",
|
|
115
|
+
jahren: "year",
|
|
116
|
+
jahres: "year",
|
|
102
117
|
};
|
|
103
118
|
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
119
|
function parseNumberPattern(match) {
|
|
@@ -124,7 +139,7 @@ function parseNumberPattern(match) {
|
|
|
124
139
|
return parseFloat(num);
|
|
125
140
|
}
|
|
126
141
|
exports.parseNumberPattern = parseNumberPattern;
|
|
127
|
-
exports.YEAR_PATTERN = `(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*C(?:hr)
|
|
142
|
+
exports.YEAR_PATTERN = `(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*(?:C(?:hr)?|(?:u\\.?|d\\.?(?:\\s*g\\.?)?)?\\s*Z)\\.?|\\s*(?:u\\.?|d\\.?(?:\\s*g\\.)?)\\s*Z\\.?)?)`;
|
|
128
143
|
function parseYear(match) {
|
|
129
144
|
if (/v/i.test(match)) {
|
|
130
145
|
return -parseInt(match.replace(/[^0-9]+/gi, ""));
|
|
@@ -132,6 +147,9 @@ function parseYear(match) {
|
|
|
132
147
|
if (/n/i.test(match)) {
|
|
133
148
|
return parseInt(match.replace(/[^0-9]+/gi, ""));
|
|
134
149
|
}
|
|
150
|
+
if (/z/i.test(match)) {
|
|
151
|
+
return parseInt(match.replace(/[^0-9]+/gi, ""));
|
|
152
|
+
}
|
|
135
153
|
const rawYearNumber = parseInt(match);
|
|
136
154
|
return years_1.findMostLikelyADYear(rawYearNumber);
|
|
137
155
|
}
|
package/dist/locales/de/index.js
CHANGED
|
@@ -10,11 +10,13 @@ const SlashDateFormatParser_1 = __importDefault(require("../../common/parsers/Sl
|
|
|
10
10
|
const ISOFormatParser_1 = __importDefault(require("../../common/parsers/ISOFormatParser"));
|
|
11
11
|
const DETimeExpressionParser_1 = __importDefault(require("./parsers/DETimeExpressionParser"));
|
|
12
12
|
const DEWeekdayParser_1 = __importDefault(require("./parsers/DEWeekdayParser"));
|
|
13
|
+
const DESpecificTimeExpressionParser_1 = __importDefault(require("./parsers/DESpecificTimeExpressionParser"));
|
|
13
14
|
const DEMergeDateRangeRefiner_1 = __importDefault(require("./refiners/DEMergeDateRangeRefiner"));
|
|
14
15
|
const DEMergeDateTimeRefiner_1 = __importDefault(require("./refiners/DEMergeDateTimeRefiner"));
|
|
15
16
|
const DECasualDateParser_1 = __importDefault(require("./parsers/DECasualDateParser"));
|
|
16
17
|
const DECasualTimeParser_1 = __importDefault(require("./parsers/DECasualTimeParser"));
|
|
17
18
|
const DEMonthNameLittleEndianParser_1 = __importDefault(require("./parsers/DEMonthNameLittleEndianParser"));
|
|
19
|
+
const DETimeUnitRelativeFormatParser_1 = __importDefault(require("./parsers/DETimeUnitRelativeFormatParser"));
|
|
18
20
|
exports.casual = new chrono_1.Chrono(createCasualConfiguration());
|
|
19
21
|
exports.strict = new chrono_1.Chrono(createConfiguration(true));
|
|
20
22
|
function parse(text, ref, option) {
|
|
@@ -29,6 +31,7 @@ function createCasualConfiguration(littleEndian = true) {
|
|
|
29
31
|
const option = createConfiguration(false, littleEndian);
|
|
30
32
|
option.parsers.unshift(new DECasualTimeParser_1.default());
|
|
31
33
|
option.parsers.unshift(new DECasualDateParser_1.default());
|
|
34
|
+
option.parsers.unshift(new DETimeUnitRelativeFormatParser_1.default());
|
|
32
35
|
return option;
|
|
33
36
|
}
|
|
34
37
|
exports.createCasualConfiguration = createCasualConfiguration;
|
|
@@ -38,6 +41,7 @@ function createConfiguration(strictMode = true, littleEndian = true) {
|
|
|
38
41
|
new ISOFormatParser_1.default(),
|
|
39
42
|
new SlashDateFormatParser_1.default(littleEndian),
|
|
40
43
|
new DETimeExpressionParser_1.default(),
|
|
44
|
+
new DESpecificTimeExpressionParser_1.default(),
|
|
41
45
|
new DEMonthNameLittleEndianParser_1.default(),
|
|
42
46
|
new DEWeekdayParser_1.default(),
|
|
43
47
|
],
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Parser, ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingResult } from "../../../results";
|
|
3
|
+
export default class DESpecificTimeExpressionParser implements Parser {
|
|
4
|
+
pattern(context: any): RegExp;
|
|
5
|
+
extract(context: ParsingContext, match: RegExpMatchArray): ParsingResult | null;
|
|
6
|
+
private static extractTimeComponent;
|
|
7
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("../../../index");
|
|
4
|
+
const FIRST_REG_PATTERN = new RegExp("(^|\\s|T)" +
|
|
5
|
+
"(?:(?:um|von)\\s*)?" +
|
|
6
|
+
"(\\d{1,2})(?:h|:)?" +
|
|
7
|
+
"(?:(\\d{1,2})(?:m|:)?)?" +
|
|
8
|
+
"(?:(\\d{1,2})(?:s)?)?" +
|
|
9
|
+
"(?:\\s*Uhr)?" +
|
|
10
|
+
"(?:\\s*(morgens|vormittags|nachmittags|abends|nachts|am\\s+(?:Morgen|Vormittag|Nachmittag|Abend)|in\\s+der\\s+Nacht))?" +
|
|
11
|
+
"(?=\\W|$)", "i");
|
|
12
|
+
const SECOND_REG_PATTERN = new RegExp("^\\s*(\\-|\\–|\\~|\\〜|bis(?:\\s+um)?|\\?)\\s*" +
|
|
13
|
+
"(\\d{1,2})(?:h|:)?" +
|
|
14
|
+
"(?:(\\d{1,2})(?:m|:)?)?" +
|
|
15
|
+
"(?:(\\d{1,2})(?:s)?)?" +
|
|
16
|
+
"(?:\\s*Uhr)?" +
|
|
17
|
+
"(?:\\s*(morgens|vormittags|nachmittags|abends|nachts|am\\s+(?:Morgen|Vormittag|Nachmittag|Abend)|in\\s+der\\s+Nacht))?" +
|
|
18
|
+
"(?=\\W|$)", "i");
|
|
19
|
+
const HOUR_GROUP = 2;
|
|
20
|
+
const MINUTE_GROUP = 3;
|
|
21
|
+
const SECOND_GROUP = 4;
|
|
22
|
+
const AM_PM_HOUR_GROUP = 5;
|
|
23
|
+
class DESpecificTimeExpressionParser {
|
|
24
|
+
pattern(context) {
|
|
25
|
+
return FIRST_REG_PATTERN;
|
|
26
|
+
}
|
|
27
|
+
extract(context, match) {
|
|
28
|
+
const result = context.createParsingResult(match.index + match[1].length, match[0].substring(match[1].length));
|
|
29
|
+
if (result.text.match(/^\d{4}$/)) {
|
|
30
|
+
match.index += match[0].length;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
result.start = DESpecificTimeExpressionParser.extractTimeComponent(result.start.clone(), match);
|
|
34
|
+
if (!result.start) {
|
|
35
|
+
match.index += match[0].length;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const remainingText = context.text.substring(match.index + match[0].length);
|
|
39
|
+
const secondMatch = SECOND_REG_PATTERN.exec(remainingText);
|
|
40
|
+
if (secondMatch) {
|
|
41
|
+
result.end = DESpecificTimeExpressionParser.extractTimeComponent(result.start.clone(), secondMatch);
|
|
42
|
+
if (result.end) {
|
|
43
|
+
result.text += secondMatch[0];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
static extractTimeComponent(extractingComponents, match) {
|
|
49
|
+
let hour = 0;
|
|
50
|
+
let minute = 0;
|
|
51
|
+
let meridiem = null;
|
|
52
|
+
hour = parseInt(match[HOUR_GROUP]);
|
|
53
|
+
if (match[MINUTE_GROUP] != null) {
|
|
54
|
+
minute = parseInt(match[MINUTE_GROUP]);
|
|
55
|
+
}
|
|
56
|
+
if (minute >= 60 || hour > 24) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (hour >= 12) {
|
|
60
|
+
meridiem = index_1.Meridiem.PM;
|
|
61
|
+
}
|
|
62
|
+
if (match[AM_PM_HOUR_GROUP] != null) {
|
|
63
|
+
if (hour > 12)
|
|
64
|
+
return null;
|
|
65
|
+
const ampm = match[AM_PM_HOUR_GROUP].toLowerCase();
|
|
66
|
+
if (ampm.match(/morgen|vormittag/)) {
|
|
67
|
+
meridiem = index_1.Meridiem.AM;
|
|
68
|
+
if (hour == 12) {
|
|
69
|
+
hour = 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (ampm.match(/nachmittag|abend/)) {
|
|
73
|
+
meridiem = index_1.Meridiem.PM;
|
|
74
|
+
if (hour != 12) {
|
|
75
|
+
hour += 12;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (ampm.match(/nacht/)) {
|
|
79
|
+
if (hour == 12) {
|
|
80
|
+
meridiem = index_1.Meridiem.AM;
|
|
81
|
+
hour = 0;
|
|
82
|
+
}
|
|
83
|
+
else if (hour < 6) {
|
|
84
|
+
meridiem = index_1.Meridiem.AM;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
meridiem = index_1.Meridiem.PM;
|
|
88
|
+
hour += 12;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
extractingComponents.assign("hour", hour);
|
|
93
|
+
extractingComponents.assign("minute", minute);
|
|
94
|
+
if (meridiem !== null) {
|
|
95
|
+
extractingComponents.assign("meridiem", meridiem);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (hour < 12) {
|
|
99
|
+
extractingComponents.imply("meridiem", index_1.Meridiem.AM);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
extractingComponents.imply("meridiem", index_1.Meridiem.PM);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (match[SECOND_GROUP] != null) {
|
|
106
|
+
const second = parseInt(match[SECOND_GROUP]);
|
|
107
|
+
if (second >= 60)
|
|
108
|
+
return null;
|
|
109
|
+
extractingComponents.assign("second", second);
|
|
110
|
+
}
|
|
111
|
+
return extractingComponents;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.default = DESpecificTimeExpressionParser;
|
|
@@ -4,6 +4,5 @@ import { ParsingContext } from "../../../chrono";
|
|
|
4
4
|
export default class DETimeExpressionParser extends AbstractTimeExpressionParser {
|
|
5
5
|
primaryPrefix(): string;
|
|
6
6
|
followingPhase(): string;
|
|
7
|
-
primarySuffix(): string;
|
|
8
7
|
extractPrimaryTimeComponents(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | null;
|
|
9
8
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const AbstractTimeExpressionParser_1 = require("../../../common/parsers/AbstractTimeExpressionParser");
|
|
4
|
-
const index_1 = require("../../../index");
|
|
5
4
|
class DETimeExpressionParser extends AbstractTimeExpressionParser_1.AbstractTimeExpressionParser {
|
|
6
5
|
primaryPrefix() {
|
|
7
6
|
return "(?:(?:um|von)\\s*)?";
|
|
@@ -9,28 +8,11 @@ class DETimeExpressionParser extends AbstractTimeExpressionParser_1.AbstractTime
|
|
|
9
8
|
followingPhase() {
|
|
10
9
|
return "\\s*(?:\\-|\\–|\\~|\\〜|bis)\\s*";
|
|
11
10
|
}
|
|
12
|
-
primarySuffix() {
|
|
13
|
-
return "(?:\\s*uhr)?(?:\\s*(?:morgens|vormittags|nachmittags|abends|nachts))?(?=\\W|$)";
|
|
14
|
-
}
|
|
15
11
|
extractPrimaryTimeComponents(context, match) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (match[0].endsWith("morgens") || match[0].endsWith("vormittags")) {
|
|
19
|
-
components.assign("meridiem", index_1.Meridiem.AM);
|
|
20
|
-
const hour = components.get("hour");
|
|
21
|
-
if (hour < 12) {
|
|
22
|
-
components.assign("hour", components.get("hour"));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (match[0].endsWith("nachmittags") || match[0].endsWith("abends") || match[0].endsWith("nachts")) {
|
|
26
|
-
components.assign("meridiem", index_1.Meridiem.PM);
|
|
27
|
-
const hour = components.get("hour");
|
|
28
|
-
if (hour < 12) {
|
|
29
|
-
components.assign("hour", components.get("hour") + 12);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
12
|
+
if (match[0].match(/^\s*\d{4}\s*$/)) {
|
|
13
|
+
return null;
|
|
32
14
|
}
|
|
33
|
-
return
|
|
15
|
+
return super.extractPrimaryTimeComponents(context, match);
|
|
34
16
|
}
|
|
35
17
|
}
|
|
36
18
|
exports.default = DETimeExpressionParser;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
4
|
+
export default class DETimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
constructor();
|
|
6
|
+
innerPattern(): RegExp;
|
|
7
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents;
|
|
8
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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_1 = require("../../../utils/pattern");
|
|
8
|
+
class DETimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
innerPattern() {
|
|
13
|
+
return new RegExp(`(?:\\s*((?:nächste|kommende|folgende|letzte|vergangene|vorige|vor(?:her|an)gegangene)(?:s|n|m|r)?|vor|in)\\s*)?` +
|
|
14
|
+
`(${constants_1.NUMBER_PATTERN})?` +
|
|
15
|
+
`(?:\\s*(nächste|kommende|folgende|letzte|vergangene|vorige|vor(?:her|an)gegangene)(?:s|n|m|r)?)?` +
|
|
16
|
+
`\\s*(${pattern_1.matchAnyPattern(constants_1.TIME_UNIT_DICTIONARY)})`, "i");
|
|
17
|
+
}
|
|
18
|
+
innerExtract(context, match) {
|
|
19
|
+
const num = match[2] ? constants_1.parseNumberPattern(match[2]) : 1;
|
|
20
|
+
const unit = constants_1.TIME_UNIT_DICTIONARY[match[4].toLowerCase()];
|
|
21
|
+
let timeUnits = {};
|
|
22
|
+
timeUnits[unit] = num;
|
|
23
|
+
let modifier = match[1] || match[3] || "";
|
|
24
|
+
modifier = modifier.toLowerCase();
|
|
25
|
+
if (!modifier) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (/vor/.test(modifier) || /letzte/.test(modifier) || /vergangen/.test(modifier)) {
|
|
29
|
+
timeUnits = timeunits_1.reverseTimeUnits(timeUnits);
|
|
30
|
+
}
|
|
31
|
+
return results_1.ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = DETimeUnitAgoFormatParser;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpUnitType } from "dayjs";
|
|
1
|
+
import { OpUnitType, QUnitType } from "dayjs";
|
|
2
2
|
import { TimeUnits } from "../../utils/timeunits";
|
|
3
3
|
export declare const WEEKDAY_DICTIONARY: {
|
|
4
4
|
[word: string]: number;
|
|
@@ -16,7 +16,7 @@ export declare const ORDINAL_WORD_DICTIONARY: {
|
|
|
16
16
|
[word: string]: number;
|
|
17
17
|
};
|
|
18
18
|
export declare const TIME_UNIT_DICTIONARY: {
|
|
19
|
-
[word: string]: OpUnitType;
|
|
19
|
+
[word: string]: OpUnitType | QUnitType;
|
|
20
20
|
};
|
|
21
21
|
export declare const NUMBER_PATTERN: string;
|
|
22
22
|
export declare function parseNumberPattern(match: string): number;
|
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?: number;
|
|
5
|
+
readonly timezoneOffset?: number | null;
|
|
6
6
|
constructor(input?: ParsingReference | Date);
|
|
7
7
|
}
|
|
8
8
|
export declare class ParsingComponents implements ParsedComponents {
|
package/dist/results.js
CHANGED
|
@@ -15,7 +15,6 @@ class ReferenceWithTimezone {
|
|
|
15
15
|
input = input !== null && input !== void 0 ? input : new Date();
|
|
16
16
|
if (input instanceof Date) {
|
|
17
17
|
this.instant = input;
|
|
18
|
-
this.timezoneOffset = -input.getTimezoneOffset();
|
|
19
18
|
}
|
|
20
19
|
else {
|
|
21
20
|
this.instant = (_a = input.instant) !== null && _a !== void 0 ? _a : new Date();
|
|
@@ -113,7 +112,7 @@ class ParsingComponents {
|
|
|
113
112
|
return true;
|
|
114
113
|
}
|
|
115
114
|
toString() {
|
|
116
|
-
return `[ParsingComponents {knownValues: ${JSON.stringify(this.knownValues)}, impliedValues: ${JSON.stringify(this.impliedValues)}}]`;
|
|
115
|
+
return `[ParsingComponents {knownValues: ${JSON.stringify(this.knownValues)}, impliedValues: ${JSON.stringify(this.impliedValues)}}, reference: ${JSON.stringify(this.reference)}]`;
|
|
117
116
|
}
|
|
118
117
|
dayjs() {
|
|
119
118
|
return dayjs_1.default(this.date());
|
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
|
|
194
|
+
export declare function toTimezoneOffset(timezoneInput?: string | number): number | null;
|
package/dist/timezone.js
CHANGED
|
@@ -196,12 +196,12 @@ exports.TIMEZONE_ABBR_MAP = {
|
|
|
196
196
|
};
|
|
197
197
|
function toTimezoneOffset(timezoneInput) {
|
|
198
198
|
var _a;
|
|
199
|
-
if (timezoneInput === null) {
|
|
199
|
+
if (timezoneInput === null || timezoneInput === undefined) {
|
|
200
200
|
return null;
|
|
201
201
|
}
|
|
202
202
|
if (typeof timezoneInput === "number") {
|
|
203
203
|
return timezoneInput;
|
|
204
204
|
}
|
|
205
|
-
return (_a = exports.TIMEZONE_ABBR_MAP[timezoneInput]) !== null && _a !== void 0 ? _a :
|
|
205
|
+
return (_a = exports.TIMEZONE_ABBR_MAP[timezoneInput]) !== null && _a !== void 0 ? _a : null;
|
|
206
206
|
}
|
|
207
207
|
exports.toTimezoneOffset = toTimezoneOffset;
|
package/package.json
CHANGED
|
@@ -221,7 +221,9 @@ export default class ExtractTimezoneAbbrRefiner implements Refiner {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
context.debug(() => {
|
|
224
|
-
console.log(
|
|
224
|
+
console.log(
|
|
225
|
+
`Extracting timezone: '${timezoneAbbr}' into: ${extractedTimezoneOffset} for: ${result.start}`
|
|
226
|
+
);
|
|
225
227
|
});
|
|
226
228
|
|
|
227
229
|
const currentTimezoneOffset = result.start.get("timezoneOffset");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpUnitType } from "dayjs";
|
|
1
|
+
import { OpUnitType, QUnitType } from "dayjs";
|
|
2
2
|
import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern";
|
|
3
3
|
import { findMostLikelyADYear } from "../../calculation/years";
|
|
4
4
|
import { TimeUnits } from "../../utils/timeunits";
|
|
@@ -22,9 +22,12 @@ export const WEEKDAY_DICTIONARY: { [word: string]: number } = {
|
|
|
22
22
|
|
|
23
23
|
export const MONTH_DICTIONARY: { [word: string]: number } = {
|
|
24
24
|
"januar": 1,
|
|
25
|
+
"jänner": 1,
|
|
26
|
+
"janner": 1,
|
|
25
27
|
"jan": 1,
|
|
26
28
|
"jan.": 1,
|
|
27
29
|
"februar": 2,
|
|
30
|
+
"feber": 2,
|
|
28
31
|
"feb": 2,
|
|
29
32
|
"feb.": 2,
|
|
30
33
|
"märz": 3,
|
|
@@ -64,6 +67,10 @@ export const MONTH_DICTIONARY: { [word: string]: number } = {
|
|
|
64
67
|
|
|
65
68
|
export const INTEGER_WORD_DICTIONARY: { [word: string]: number } = {
|
|
66
69
|
"eins": 1,
|
|
70
|
+
"eine": 1,
|
|
71
|
+
"einem": 1,
|
|
72
|
+
"einen": 1,
|
|
73
|
+
"einer": 1,
|
|
67
74
|
"zwei": 2,
|
|
68
75
|
"drei": 3,
|
|
69
76
|
"vier": 4,
|
|
@@ -79,29 +86,37 @@ export const INTEGER_WORD_DICTIONARY: { [word: string]: number } = {
|
|
|
79
86
|
"zwoelf": 12,
|
|
80
87
|
};
|
|
81
88
|
|
|
82
|
-
export const TIME_UNIT_DICTIONARY: { [word: string]: OpUnitType } = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
export const TIME_UNIT_DICTIONARY: { [word: string]: OpUnitType | QUnitType } = {
|
|
90
|
+
sek: "second",
|
|
91
|
+
sekunde: "second",
|
|
92
|
+
sekunden: "second",
|
|
86
93
|
min: "minute",
|
|
87
|
-
mins: "minute",
|
|
88
94
|
minute: "minute",
|
|
89
|
-
|
|
95
|
+
minuten: "minute",
|
|
90
96
|
h: "hour",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
std: "hour",
|
|
98
|
+
stunde: "hour",
|
|
99
|
+
stunden: "hour",
|
|
100
|
+
tag: "d",
|
|
101
|
+
tage: "d",
|
|
102
|
+
tagen: "d",
|
|
103
|
+
woche: "week",
|
|
104
|
+
wochen: "week",
|
|
105
|
+
monat: "month",
|
|
106
|
+
monate: "month",
|
|
107
|
+
monaten: "month",
|
|
108
|
+
monats: "month",
|
|
109
|
+
quartal: "quarter",
|
|
110
|
+
quartals: "quarter",
|
|
111
|
+
quartale: "quarter",
|
|
112
|
+
quartalen: "quarter",
|
|
113
|
+
a: "year",
|
|
114
|
+
j: "year",
|
|
115
|
+
jr: "year",
|
|
116
|
+
jahr: "year",
|
|
117
|
+
jahre: "year",
|
|
118
|
+
jahren: "year",
|
|
119
|
+
jahres: "year",
|
|
105
120
|
};
|
|
106
121
|
|
|
107
122
|
//-----------------------------
|
|
@@ -131,7 +146,7 @@ export function parseNumberPattern(match: string): number {
|
|
|
131
146
|
|
|
132
147
|
//-----------------------------
|
|
133
148
|
|
|
134
|
-
export const YEAR_PATTERN = `(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*C(?:hr)
|
|
149
|
+
export const YEAR_PATTERN = `(?:[0-9]{1,4}(?:\\s*[vn]\\.?\\s*(?:C(?:hr)?|(?:u\\.?|d\\.?(?:\\s*g\\.?)?)?\\s*Z)\\.?|\\s*(?:u\\.?|d\\.?(?:\\s*g\\.)?)\\s*Z\\.?)?)`;
|
|
135
150
|
export function parseYear(match: string): number {
|
|
136
151
|
if (/v/i.test(match)) {
|
|
137
152
|
// v.Chr.
|
|
@@ -143,6 +158,11 @@ export function parseYear(match: string): number {
|
|
|
143
158
|
return parseInt(match.replace(/[^0-9]+/gi, ""));
|
|
144
159
|
}
|
|
145
160
|
|
|
161
|
+
if (/z/i.test(match)) {
|
|
162
|
+
// n.Chr. as "uZ" or "dgZ"
|
|
163
|
+
return parseInt(match.replace(/[^0-9]+/gi, ""));
|
|
164
|
+
}
|
|
165
|
+
|
|
146
166
|
const rawYearNumber = parseInt(match);
|
|
147
167
|
return findMostLikelyADYear(rawYearNumber);
|
|
148
168
|
}
|
package/src/locales/de/index.ts
CHANGED
|
@@ -5,11 +5,13 @@ import SlashDateFormatParser from "../../common/parsers/SlashDateFormatParser";
|
|
|
5
5
|
import ISOFormatParser from "../../common/parsers/ISOFormatParser";
|
|
6
6
|
import DETimeExpressionParser from "./parsers/DETimeExpressionParser";
|
|
7
7
|
import DEWeekdayParser from "./parsers/DEWeekdayParser";
|
|
8
|
+
import DESpecificTimeExpressionParser from "./parsers/DESpecificTimeExpressionParser";
|
|
8
9
|
import DEMergeDateRangeRefiner from "./refiners/DEMergeDateRangeRefiner";
|
|
9
10
|
import DEMergeDateTimeRefiner from "./refiners/DEMergeDateTimeRefiner";
|
|
10
11
|
import DECasualDateParser from "./parsers/DECasualDateParser";
|
|
11
12
|
import DECasualTimeParser from "./parsers/DECasualTimeParser";
|
|
12
13
|
import DEMonthNameLittleEndianParser from "./parsers/DEMonthNameLittleEndianParser";
|
|
14
|
+
import DETimeUnitRelativeFormatParser from "./parsers/DETimeUnitRelativeFormatParser";
|
|
13
15
|
|
|
14
16
|
// Shortcuts
|
|
15
17
|
export const casual = new Chrono(createCasualConfiguration());
|
|
@@ -27,6 +29,7 @@ export function createCasualConfiguration(littleEndian = true): Configuration {
|
|
|
27
29
|
const option = createConfiguration(false, littleEndian);
|
|
28
30
|
option.parsers.unshift(new DECasualTimeParser());
|
|
29
31
|
option.parsers.unshift(new DECasualDateParser());
|
|
32
|
+
option.parsers.unshift(new DETimeUnitRelativeFormatParser());
|
|
30
33
|
return option;
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -37,6 +40,7 @@ export function createConfiguration(strictMode = true, littleEndian = true): Con
|
|
|
37
40
|
new ISOFormatParser(),
|
|
38
41
|
new SlashDateFormatParser(littleEndian),
|
|
39
42
|
new DETimeExpressionParser(),
|
|
43
|
+
new DESpecificTimeExpressionParser(),
|
|
40
44
|
new DEMonthNameLittleEndianParser(),
|
|
41
45
|
new DEWeekdayParser(),
|
|
42
46
|
],
|