chrono-node 2.3.5 → 2.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/refiners/ExtractTimezoneAbbrRefiner.js +5 -0
- package/dist/locales/zh/hans/constants.d.ts +27 -0
- package/dist/locales/zh/hans/constants.js +51 -0
- package/dist/locales/zh/hans/index.d.ts +9 -0
- package/dist/locales/zh/hans/index.js +49 -0
- package/dist/locales/zh/hans/parsers/ZHHansCasualDateParser.d.ts +7 -0
- package/dist/locales/zh/hans/parsers/ZHHansCasualDateParser.js +138 -0
- package/dist/locales/zh/hans/parsers/ZHHansDateParser.d.ts +6 -0
- package/dist/locales/zh/hans/parsers/ZHHansDateParser.js +72 -0
- package/dist/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.d.ts +6 -0
- package/dist/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.js +78 -0
- package/dist/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.d.ts +7 -0
- package/dist/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.js +70 -0
- package/dist/locales/zh/hans/parsers/ZHHansTimeExpressionParser.d.ts +6 -0
- package/dist/locales/zh/hans/parsers/ZHHansTimeExpressionParser.js +438 -0
- package/dist/locales/zh/hans/parsers/ZHHansWeekdayParser.d.ts +7 -0
- package/dist/locales/zh/hans/parsers/ZHHansWeekdayParser.js +46 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.d.ts +4 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.js +12 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.d.ts +4 -0
- package/dist/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.js +12 -0
- package/dist/locales/zh/hant/index.d.ts +9 -0
- package/dist/locales/zh/hant/index.js +49 -0
- package/dist/locales/zh/index.d.ts +2 -9
- package/dist/locales/zh/index.js +13 -46
- package/package.json +1 -1
- package/src/common/refiners/ExtractTimezoneAbbrRefiner.ts +8 -0
- package/src/locales/en/parsers/ENMonthNameLittleEndianParser.ts +0 -2
- package/src/locales/zh/hans/constants.ts +52 -0
- package/src/locales/zh/hans/index.ts +62 -0
- package/src/locales/zh/hans/parsers/ZHHansCasualDateParser.ts +128 -0
- package/src/locales/zh/hans/parsers/ZHHansDateParser.ts +75 -0
- package/src/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.ts +81 -0
- package/src/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.ts +69 -0
- package/src/locales/zh/hans/parsers/ZHHansTimeExpressionParser.ts +424 -0
- package/src/locales/zh/hans/parsers/ZHHansWeekdayParser.ts +46 -0
- package/src/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.ts +7 -0
- package/src/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.ts +7 -0
- package/src/locales/zh/hant/index.ts +63 -0
- package/src/locales/zh/index.ts +2 -63
- package/test/en/en_month.test.ts +13 -0
- package/test/zh/zh_hans_casual.test.ts +228 -0
- package/test/zh/zh_hans_date.test.ts +102 -0
- package/test/zh/zh_hans_deadline.test.ts +136 -0
- package/test/zh/zh_hans_time_exp.test.ts +182 -0
- package/test/zh/zh_hans_weekday.test.ts +132 -0
- package/test/zh/zh_hant_date.test.ts +0 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
7
|
+
const AbstractParserWithWordBoundary_1 = require("../../../../common/parsers/AbstractParserWithWordBoundary");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const FIRST_REG_PATTERN = new RegExp("(?:从|自)?" +
|
|
10
|
+
"(?:" +
|
|
11
|
+
"(今|明|前|大前|后|大后|昨)(早|朝|晚)|" +
|
|
12
|
+
"(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" +
|
|
13
|
+
"(今|明|前|大前|后|大后|昨)(?:日|天)" +
|
|
14
|
+
"(?:[\\s,,]*)" +
|
|
15
|
+
"(?:(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?" +
|
|
16
|
+
")?" +
|
|
17
|
+
"(?:[\\s,,]*)" +
|
|
18
|
+
"(?:(\\d+|[" +
|
|
19
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
20
|
+
"]+)(?:\\s*)(?:点|时|:|:)" +
|
|
21
|
+
"(?:\\s*)" +
|
|
22
|
+
"(\\d+|半|正|整|[" +
|
|
23
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
24
|
+
"]+)?(?:\\s*)(?:分|:|:)?" +
|
|
25
|
+
"(?:\\s*)" +
|
|
26
|
+
"(\\d+|[" +
|
|
27
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
28
|
+
"]+)?(?:\\s*)(?:秒)?)" +
|
|
29
|
+
"(?:\\s*(A.M.|P.M.|AM?|PM?))?", "i");
|
|
30
|
+
const SECOND_REG_PATTERN = new RegExp("(?:^\\s*(?:到|至|\\-|\\–|\\~|\\〜)\\s*)" +
|
|
31
|
+
"(?:" +
|
|
32
|
+
"(今|明|前|大前|后|大后|昨)(早|朝|晚)|" +
|
|
33
|
+
"(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨))|" +
|
|
34
|
+
"(今|明|前|大前|后|大后|昨)(?:日|天)" +
|
|
35
|
+
"(?:[\\s,,]*)" +
|
|
36
|
+
"(?:(上(?:午)|早(?:上)|下(?:午)|晚(?:上)|夜(?:晚)?|中(?:午)|凌(?:晨)))?" +
|
|
37
|
+
")?" +
|
|
38
|
+
"(?:[\\s,,]*)" +
|
|
39
|
+
"(?:(\\d+|[" +
|
|
40
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
41
|
+
"]+)(?:\\s*)(?:点|时|:|:)" +
|
|
42
|
+
"(?:\\s*)" +
|
|
43
|
+
"(\\d+|半|正|整|[" +
|
|
44
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
45
|
+
"]+)?(?:\\s*)(?:分|:|:)?" +
|
|
46
|
+
"(?:\\s*)" +
|
|
47
|
+
"(\\d+|[" +
|
|
48
|
+
Object.keys(constants_1.NUMBER).join("") +
|
|
49
|
+
"]+)?(?:\\s*)(?:秒)?)" +
|
|
50
|
+
"(?:\\s*(A.M.|P.M.|AM?|PM?))?", "i");
|
|
51
|
+
const DAY_GROUP_1 = 1;
|
|
52
|
+
const ZH_AM_PM_HOUR_GROUP_1 = 2;
|
|
53
|
+
const ZH_AM_PM_HOUR_GROUP_2 = 3;
|
|
54
|
+
const DAY_GROUP_3 = 4;
|
|
55
|
+
const ZH_AM_PM_HOUR_GROUP_3 = 5;
|
|
56
|
+
const HOUR_GROUP = 6;
|
|
57
|
+
const MINUTE_GROUP = 7;
|
|
58
|
+
const SECOND_GROUP = 8;
|
|
59
|
+
const AM_PM_HOUR_GROUP = 9;
|
|
60
|
+
class ZHHansTimeExpressionParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
61
|
+
innerPattern() {
|
|
62
|
+
return FIRST_REG_PATTERN;
|
|
63
|
+
}
|
|
64
|
+
innerExtract(context, match) {
|
|
65
|
+
if (match.index > 0 && context.text[match.index - 1].match(/\w/)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const refMoment = dayjs_1.default(context.refDate);
|
|
69
|
+
const result = context.createParsingResult(match.index, match[0]);
|
|
70
|
+
const startMoment = refMoment.clone();
|
|
71
|
+
if (match[DAY_GROUP_1]) {
|
|
72
|
+
const day1 = match[DAY_GROUP_1];
|
|
73
|
+
if (day1 == "明") {
|
|
74
|
+
if (refMoment.hour() > 1) {
|
|
75
|
+
startMoment.add(1, "day");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (day1 == "昨") {
|
|
79
|
+
startMoment.add(-1, "day");
|
|
80
|
+
}
|
|
81
|
+
else if (day1 == "前") {
|
|
82
|
+
startMoment.add(-2, "day");
|
|
83
|
+
}
|
|
84
|
+
else if (day1 == "大前") {
|
|
85
|
+
startMoment.add(-3, "day");
|
|
86
|
+
}
|
|
87
|
+
else if (day1 == "后") {
|
|
88
|
+
startMoment.add(2, "day");
|
|
89
|
+
}
|
|
90
|
+
else if (day1 == "大后") {
|
|
91
|
+
startMoment.add(3, "day");
|
|
92
|
+
}
|
|
93
|
+
result.start.assign("day", startMoment.date());
|
|
94
|
+
result.start.assign("month", startMoment.month() + 1);
|
|
95
|
+
result.start.assign("year", startMoment.year());
|
|
96
|
+
}
|
|
97
|
+
else if (match[DAY_GROUP_3]) {
|
|
98
|
+
const day3 = match[DAY_GROUP_3];
|
|
99
|
+
if (day3 == "明") {
|
|
100
|
+
startMoment.add(1, "day");
|
|
101
|
+
}
|
|
102
|
+
else if (day3 == "昨") {
|
|
103
|
+
startMoment.add(-1, "day");
|
|
104
|
+
}
|
|
105
|
+
else if (day3 == "前") {
|
|
106
|
+
startMoment.add(-2, "day");
|
|
107
|
+
}
|
|
108
|
+
else if (day3 == "大前") {
|
|
109
|
+
startMoment.add(-3, "day");
|
|
110
|
+
}
|
|
111
|
+
else if (day3 == "后") {
|
|
112
|
+
startMoment.add(2, "day");
|
|
113
|
+
}
|
|
114
|
+
else if (day3 == "大后") {
|
|
115
|
+
startMoment.add(3, "day");
|
|
116
|
+
}
|
|
117
|
+
result.start.assign("day", startMoment.date());
|
|
118
|
+
result.start.assign("month", startMoment.month() + 1);
|
|
119
|
+
result.start.assign("year", startMoment.year());
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
result.start.imply("day", startMoment.date());
|
|
123
|
+
result.start.imply("month", startMoment.month() + 1);
|
|
124
|
+
result.start.imply("year", startMoment.year());
|
|
125
|
+
}
|
|
126
|
+
let hour = 0;
|
|
127
|
+
let minute = 0;
|
|
128
|
+
let meridiem = -1;
|
|
129
|
+
if (match[SECOND_GROUP]) {
|
|
130
|
+
let second = parseInt(match[SECOND_GROUP]);
|
|
131
|
+
if (isNaN(second)) {
|
|
132
|
+
second = constants_1.zhStringToNumber(match[SECOND_GROUP]);
|
|
133
|
+
}
|
|
134
|
+
if (second >= 60)
|
|
135
|
+
return null;
|
|
136
|
+
result.start.assign("second", second);
|
|
137
|
+
}
|
|
138
|
+
hour = parseInt(match[HOUR_GROUP]);
|
|
139
|
+
if (isNaN(hour)) {
|
|
140
|
+
hour = constants_1.zhStringToNumber(match[HOUR_GROUP]);
|
|
141
|
+
}
|
|
142
|
+
if (match[MINUTE_GROUP]) {
|
|
143
|
+
if (match[MINUTE_GROUP] == "半") {
|
|
144
|
+
minute = 30;
|
|
145
|
+
}
|
|
146
|
+
else if (match[MINUTE_GROUP] == "正" || match[MINUTE_GROUP] == "整") {
|
|
147
|
+
minute = 0;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
minute = parseInt(match[MINUTE_GROUP]);
|
|
151
|
+
if (isNaN(minute)) {
|
|
152
|
+
minute = constants_1.zhStringToNumber(match[MINUTE_GROUP]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (hour > 100) {
|
|
157
|
+
minute = hour % 100;
|
|
158
|
+
hour = Math.floor(hour / 100);
|
|
159
|
+
}
|
|
160
|
+
if (minute >= 60) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
if (hour > 24) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (hour >= 12) {
|
|
167
|
+
meridiem = 1;
|
|
168
|
+
}
|
|
169
|
+
if (match[AM_PM_HOUR_GROUP]) {
|
|
170
|
+
if (hour > 12)
|
|
171
|
+
return null;
|
|
172
|
+
const ampm = match[AM_PM_HOUR_GROUP][0].toLowerCase();
|
|
173
|
+
if (ampm == "a") {
|
|
174
|
+
meridiem = 0;
|
|
175
|
+
if (hour == 12)
|
|
176
|
+
hour = 0;
|
|
177
|
+
}
|
|
178
|
+
if (ampm == "p") {
|
|
179
|
+
meridiem = 1;
|
|
180
|
+
if (hour != 12)
|
|
181
|
+
hour += 12;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (match[ZH_AM_PM_HOUR_GROUP_1]) {
|
|
185
|
+
const zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1];
|
|
186
|
+
const zhAMPM1 = zhAMPMString1[0];
|
|
187
|
+
if (zhAMPM1 == "早") {
|
|
188
|
+
meridiem = 0;
|
|
189
|
+
if (hour == 12)
|
|
190
|
+
hour = 0;
|
|
191
|
+
}
|
|
192
|
+
else if (zhAMPM1 == "晚") {
|
|
193
|
+
meridiem = 1;
|
|
194
|
+
if (hour != 12)
|
|
195
|
+
hour += 12;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (match[ZH_AM_PM_HOUR_GROUP_2]) {
|
|
199
|
+
const zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2];
|
|
200
|
+
const zhAMPM2 = zhAMPMString2[0];
|
|
201
|
+
if (zhAMPM2 == "上" || zhAMPM2 == "早" || zhAMPM2 == "凌") {
|
|
202
|
+
meridiem = 0;
|
|
203
|
+
if (hour == 12)
|
|
204
|
+
hour = 0;
|
|
205
|
+
}
|
|
206
|
+
else if (zhAMPM2 == "下" || zhAMPM2 == "晚") {
|
|
207
|
+
meridiem = 1;
|
|
208
|
+
if (hour != 12)
|
|
209
|
+
hour += 12;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (match[ZH_AM_PM_HOUR_GROUP_3]) {
|
|
213
|
+
const zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3];
|
|
214
|
+
const zhAMPM3 = zhAMPMString3[0];
|
|
215
|
+
if (zhAMPM3 == "上" || zhAMPM3 == "早" || zhAMPM3 == "凌") {
|
|
216
|
+
meridiem = 0;
|
|
217
|
+
if (hour == 12)
|
|
218
|
+
hour = 0;
|
|
219
|
+
}
|
|
220
|
+
else if (zhAMPM3 == "下" || zhAMPM3 == "晚") {
|
|
221
|
+
meridiem = 1;
|
|
222
|
+
if (hour != 12)
|
|
223
|
+
hour += 12;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
result.start.assign("hour", hour);
|
|
227
|
+
result.start.assign("minute", minute);
|
|
228
|
+
if (meridiem >= 0) {
|
|
229
|
+
result.start.assign("meridiem", meridiem);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
if (hour < 12) {
|
|
233
|
+
result.start.imply("meridiem", 0);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
result.start.imply("meridiem", 1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
match = SECOND_REG_PATTERN.exec(context.text.substring(result.index + result.text.length));
|
|
240
|
+
if (!match) {
|
|
241
|
+
if (result.text.match(/^\d+$/)) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
const endMoment = startMoment.clone();
|
|
247
|
+
result.end = context.createParsingComponents();
|
|
248
|
+
if (match[DAY_GROUP_1]) {
|
|
249
|
+
const day1 = match[DAY_GROUP_1];
|
|
250
|
+
if (day1 == "明") {
|
|
251
|
+
if (refMoment.hour() > 1) {
|
|
252
|
+
endMoment.add(1, "day");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (day1 == "昨") {
|
|
256
|
+
endMoment.add(-1, "day");
|
|
257
|
+
}
|
|
258
|
+
else if (day1 == "前") {
|
|
259
|
+
endMoment.add(-2, "day");
|
|
260
|
+
}
|
|
261
|
+
else if (day1 == "大前") {
|
|
262
|
+
endMoment.add(-3, "day");
|
|
263
|
+
}
|
|
264
|
+
else if (day1 == "后") {
|
|
265
|
+
endMoment.add(2, "day");
|
|
266
|
+
}
|
|
267
|
+
else if (day1 == "大后") {
|
|
268
|
+
endMoment.add(3, "day");
|
|
269
|
+
}
|
|
270
|
+
result.end.assign("day", endMoment.date());
|
|
271
|
+
result.end.assign("month", endMoment.month() + 1);
|
|
272
|
+
result.end.assign("year", endMoment.year());
|
|
273
|
+
}
|
|
274
|
+
else if (match[DAY_GROUP_3]) {
|
|
275
|
+
const day3 = match[DAY_GROUP_3];
|
|
276
|
+
if (day3 == "明") {
|
|
277
|
+
endMoment.add(1, "day");
|
|
278
|
+
}
|
|
279
|
+
else if (day3 == "昨") {
|
|
280
|
+
endMoment.add(-1, "day");
|
|
281
|
+
}
|
|
282
|
+
else if (day3 == "前") {
|
|
283
|
+
endMoment.add(-2, "day");
|
|
284
|
+
}
|
|
285
|
+
else if (day3 == "大前") {
|
|
286
|
+
endMoment.add(-3, "day");
|
|
287
|
+
}
|
|
288
|
+
else if (day3 == "后") {
|
|
289
|
+
endMoment.add(2, "day");
|
|
290
|
+
}
|
|
291
|
+
else if (day3 == "大后") {
|
|
292
|
+
endMoment.add(3, "day");
|
|
293
|
+
}
|
|
294
|
+
result.end.assign("day", endMoment.date());
|
|
295
|
+
result.end.assign("month", endMoment.month() + 1);
|
|
296
|
+
result.end.assign("year", endMoment.year());
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
result.end.imply("day", endMoment.date());
|
|
300
|
+
result.end.imply("month", endMoment.month() + 1);
|
|
301
|
+
result.end.imply("year", endMoment.year());
|
|
302
|
+
}
|
|
303
|
+
hour = 0;
|
|
304
|
+
minute = 0;
|
|
305
|
+
meridiem = -1;
|
|
306
|
+
if (match[SECOND_GROUP]) {
|
|
307
|
+
let second = parseInt(match[SECOND_GROUP]);
|
|
308
|
+
if (isNaN(second)) {
|
|
309
|
+
second = constants_1.zhStringToNumber(match[SECOND_GROUP]);
|
|
310
|
+
}
|
|
311
|
+
if (second >= 60)
|
|
312
|
+
return null;
|
|
313
|
+
result.end.assign("second", second);
|
|
314
|
+
}
|
|
315
|
+
hour = parseInt(match[HOUR_GROUP]);
|
|
316
|
+
if (isNaN(hour)) {
|
|
317
|
+
hour = constants_1.zhStringToNumber(match[HOUR_GROUP]);
|
|
318
|
+
}
|
|
319
|
+
if (match[MINUTE_GROUP]) {
|
|
320
|
+
if (match[MINUTE_GROUP] == "半") {
|
|
321
|
+
minute = 30;
|
|
322
|
+
}
|
|
323
|
+
else if (match[MINUTE_GROUP] == "正" || match[MINUTE_GROUP] == "整") {
|
|
324
|
+
minute = 0;
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
minute = parseInt(match[MINUTE_GROUP]);
|
|
328
|
+
if (isNaN(minute)) {
|
|
329
|
+
minute = constants_1.zhStringToNumber(match[MINUTE_GROUP]);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else if (hour > 100) {
|
|
334
|
+
minute = hour % 100;
|
|
335
|
+
hour = Math.floor(hour / 100);
|
|
336
|
+
}
|
|
337
|
+
if (minute >= 60) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
if (hour > 24) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
if (hour >= 12) {
|
|
344
|
+
meridiem = 1;
|
|
345
|
+
}
|
|
346
|
+
if (match[AM_PM_HOUR_GROUP]) {
|
|
347
|
+
if (hour > 12)
|
|
348
|
+
return null;
|
|
349
|
+
const ampm = match[AM_PM_HOUR_GROUP][0].toLowerCase();
|
|
350
|
+
if (ampm == "a") {
|
|
351
|
+
meridiem = 0;
|
|
352
|
+
if (hour == 12)
|
|
353
|
+
hour = 0;
|
|
354
|
+
}
|
|
355
|
+
if (ampm == "p") {
|
|
356
|
+
meridiem = 1;
|
|
357
|
+
if (hour != 12)
|
|
358
|
+
hour += 12;
|
|
359
|
+
}
|
|
360
|
+
if (!result.start.isCertain("meridiem")) {
|
|
361
|
+
if (meridiem == 0) {
|
|
362
|
+
result.start.imply("meridiem", 0);
|
|
363
|
+
if (result.start.get("hour") == 12) {
|
|
364
|
+
result.start.assign("hour", 0);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
result.start.imply("meridiem", 1);
|
|
369
|
+
if (result.start.get("hour") != 12) {
|
|
370
|
+
result.start.assign("hour", result.start.get("hour") + 12);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else if (match[ZH_AM_PM_HOUR_GROUP_1]) {
|
|
376
|
+
const zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1];
|
|
377
|
+
const zhAMPM1 = zhAMPMString1[0];
|
|
378
|
+
if (zhAMPM1 == "早") {
|
|
379
|
+
meridiem = 0;
|
|
380
|
+
if (hour == 12)
|
|
381
|
+
hour = 0;
|
|
382
|
+
}
|
|
383
|
+
else if (zhAMPM1 == "晚") {
|
|
384
|
+
meridiem = 1;
|
|
385
|
+
if (hour != 12)
|
|
386
|
+
hour += 12;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else if (match[ZH_AM_PM_HOUR_GROUP_2]) {
|
|
390
|
+
const zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2];
|
|
391
|
+
const zhAMPM2 = zhAMPMString2[0];
|
|
392
|
+
if (zhAMPM2 == "上" || zhAMPM2 == "早" || zhAMPM2 == "凌") {
|
|
393
|
+
meridiem = 0;
|
|
394
|
+
if (hour == 12)
|
|
395
|
+
hour = 0;
|
|
396
|
+
}
|
|
397
|
+
else if (zhAMPM2 == "下" || zhAMPM2 == "晚") {
|
|
398
|
+
meridiem = 1;
|
|
399
|
+
if (hour != 12)
|
|
400
|
+
hour += 12;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else if (match[ZH_AM_PM_HOUR_GROUP_3]) {
|
|
404
|
+
const zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3];
|
|
405
|
+
const zhAMPM3 = zhAMPMString3[0];
|
|
406
|
+
if (zhAMPM3 == "上" || zhAMPM3 == "早" || zhAMPM3 == "凌") {
|
|
407
|
+
meridiem = 0;
|
|
408
|
+
if (hour == 12)
|
|
409
|
+
hour = 0;
|
|
410
|
+
}
|
|
411
|
+
else if (zhAMPM3 == "下" || zhAMPM3 == "晚") {
|
|
412
|
+
meridiem = 1;
|
|
413
|
+
if (hour != 12)
|
|
414
|
+
hour += 12;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
result.text = result.text + match[0];
|
|
418
|
+
result.end.assign("hour", hour);
|
|
419
|
+
result.end.assign("minute", minute);
|
|
420
|
+
if (meridiem >= 0) {
|
|
421
|
+
result.end.assign("meridiem", meridiem);
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
const startAtPM = result.start.isCertain("meridiem") && result.start.get("meridiem") == 1;
|
|
425
|
+
if (startAtPM && result.start.get("hour") > hour) {
|
|
426
|
+
result.end.imply("meridiem", 0);
|
|
427
|
+
}
|
|
428
|
+
else if (hour > 12) {
|
|
429
|
+
result.end.imply("meridiem", 1);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (result.end.date().getTime() < result.start.date().getTime()) {
|
|
433
|
+
result.end.imply("day", result.end.get("day") + 1);
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
exports.default = ZHHansTimeExpressionParser;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../../chrono";
|
|
2
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../../common/parsers/AbstractParserWithWordBoundary";
|
|
3
|
+
import { ParsingResult } from "../../../../results";
|
|
4
|
+
export default class ZHHansWeekdayParser extends AbstractParserWithWordBoundaryChecking {
|
|
5
|
+
innerPattern(): RegExp;
|
|
6
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingResult;
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
7
|
+
const AbstractParserWithWordBoundary_1 = require("../../../../common/parsers/AbstractParserWithWordBoundary");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const PATTERN = new RegExp("(?:星期|礼拜|周)(?<weekday>" + Object.keys(constants_1.WEEKDAY_OFFSET).join("|") + ")");
|
|
10
|
+
class ZHHansWeekdayParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
|
11
|
+
innerPattern() {
|
|
12
|
+
return PATTERN;
|
|
13
|
+
}
|
|
14
|
+
innerExtract(context, match) {
|
|
15
|
+
const result = context.createParsingResult(match.index, match[0]);
|
|
16
|
+
const dayOfWeek = match.groups.weekday;
|
|
17
|
+
const offset = constants_1.WEEKDAY_OFFSET[dayOfWeek];
|
|
18
|
+
if (offset === undefined)
|
|
19
|
+
return null;
|
|
20
|
+
let startMoment = dayjs_1.default(context.refDate);
|
|
21
|
+
const startMomentFixed = false;
|
|
22
|
+
const refOffset = startMoment.day();
|
|
23
|
+
if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) {
|
|
24
|
+
startMoment = startMoment.day(offset - 7);
|
|
25
|
+
}
|
|
26
|
+
else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) {
|
|
27
|
+
startMoment = startMoment.day(offset + 7);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
startMoment = startMoment.day(offset);
|
|
31
|
+
}
|
|
32
|
+
result.start.assign("weekday", offset);
|
|
33
|
+
if (startMomentFixed) {
|
|
34
|
+
result.start.assign("day", startMoment.date());
|
|
35
|
+
result.start.assign("month", startMoment.month() + 1);
|
|
36
|
+
result.start.assign("year", startMoment.year());
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
result.start.imply("day", startMoment.date());
|
|
40
|
+
result.start.imply("month", startMoment.month() + 1);
|
|
41
|
+
result.start.imply("year", startMoment.year());
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = ZHHansWeekdayParser;
|
|
@@ -0,0 +1,12 @@
|
|
|
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 AbstractMergeDateRangeRefiner_1 = __importDefault(require("../../../../common/refiners/AbstractMergeDateRangeRefiner"));
|
|
7
|
+
class ZHHansMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1.default {
|
|
8
|
+
patternBetween() {
|
|
9
|
+
return /^\s*(至|到|-|~|~|-|ー)\s*$/i;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = ZHHansMergeDateRangeRefiner;
|
|
@@ -0,0 +1,12 @@
|
|
|
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 AbstractMergeDateTimeRefiner_1 = __importDefault(require("../../../../common/refiners/AbstractMergeDateTimeRefiner"));
|
|
7
|
+
class ZHHansMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1.default {
|
|
8
|
+
patternBetween() {
|
|
9
|
+
return /^\s*$/i;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = ZHHansMergeDateTimeRefiner;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Chrono, Configuration } from "../../../chrono";
|
|
2
|
+
import { ParsedResult, ParsingOption } from "../../../index";
|
|
3
|
+
export declare const hant: Chrono;
|
|
4
|
+
export declare const casual: Chrono;
|
|
5
|
+
export declare const strict: Chrono;
|
|
6
|
+
export declare function parse(text: string, ref?: Date, option?: ParsingOption): ParsedResult[];
|
|
7
|
+
export declare function parseDate(text: string, ref?: Date, option?: ParsingOption): Date;
|
|
8
|
+
export declare function createCasualConfiguration(): Configuration;
|
|
9
|
+
export declare function createConfiguration(): Configuration;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createConfiguration = exports.createCasualConfiguration = exports.parseDate = exports.parse = exports.strict = exports.casual = exports.hant = void 0;
|
|
7
|
+
const chrono_1 = require("../../../chrono");
|
|
8
|
+
const ExtractTimezoneOffsetRefiner_1 = __importDefault(require("../../../common/refiners/ExtractTimezoneOffsetRefiner"));
|
|
9
|
+
const configurations_1 = require("../../../configurations");
|
|
10
|
+
const ZHHantCasualDateParser_1 = __importDefault(require("./parsers/ZHHantCasualDateParser"));
|
|
11
|
+
const ZHHantDateParser_1 = __importDefault(require("./parsers/ZHHantDateParser"));
|
|
12
|
+
const ZHHantDeadlineFormatParser_1 = __importDefault(require("./parsers/ZHHantDeadlineFormatParser"));
|
|
13
|
+
const ZHHantRelationWeekdayParser_1 = __importDefault(require("./parsers/ZHHantRelationWeekdayParser"));
|
|
14
|
+
const ZHHantTimeExpressionParser_1 = __importDefault(require("./parsers/ZHHantTimeExpressionParser"));
|
|
15
|
+
const ZHHantWeekdayParser_1 = __importDefault(require("./parsers/ZHHantWeekdayParser"));
|
|
16
|
+
const ZHHantMergeDateRangeRefiner_1 = __importDefault(require("./refiners/ZHHantMergeDateRangeRefiner"));
|
|
17
|
+
const ZHHantMergeDateTimeRefiner_1 = __importDefault(require("./refiners/ZHHantMergeDateTimeRefiner"));
|
|
18
|
+
exports.hant = new chrono_1.Chrono(createCasualConfiguration());
|
|
19
|
+
exports.casual = new chrono_1.Chrono(createCasualConfiguration());
|
|
20
|
+
exports.strict = new chrono_1.Chrono(createConfiguration());
|
|
21
|
+
function parse(text, ref, option) {
|
|
22
|
+
return exports.casual.parse(text, ref, option);
|
|
23
|
+
}
|
|
24
|
+
exports.parse = parse;
|
|
25
|
+
function parseDate(text, ref, option) {
|
|
26
|
+
return exports.casual.parseDate(text, ref, option);
|
|
27
|
+
}
|
|
28
|
+
exports.parseDate = parseDate;
|
|
29
|
+
function createCasualConfiguration() {
|
|
30
|
+
const option = createConfiguration();
|
|
31
|
+
option.parsers.unshift(new ZHHantCasualDateParser_1.default());
|
|
32
|
+
return option;
|
|
33
|
+
}
|
|
34
|
+
exports.createCasualConfiguration = createCasualConfiguration;
|
|
35
|
+
function createConfiguration() {
|
|
36
|
+
const configuration = configurations_1.includeCommonConfiguration({
|
|
37
|
+
parsers: [
|
|
38
|
+
new ZHHantDateParser_1.default(),
|
|
39
|
+
new ZHHantRelationWeekdayParser_1.default(),
|
|
40
|
+
new ZHHantWeekdayParser_1.default(),
|
|
41
|
+
new ZHHantTimeExpressionParser_1.default(),
|
|
42
|
+
new ZHHantDeadlineFormatParser_1.default(),
|
|
43
|
+
],
|
|
44
|
+
refiners: [new ZHHantMergeDateRangeRefiner_1.default(), new ZHHantMergeDateTimeRefiner_1.default()],
|
|
45
|
+
});
|
|
46
|
+
configuration.refiners = configuration.refiners.filter((refiner) => !(refiner instanceof ExtractTimezoneOffsetRefiner_1.default));
|
|
47
|
+
return configuration;
|
|
48
|
+
}
|
|
49
|
+
exports.createConfiguration = createConfiguration;
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const hant: Chrono;
|
|
4
|
-
export declare const casual: Chrono;
|
|
5
|
-
export declare const strict: Chrono;
|
|
6
|
-
export declare function parse(text: string, ref?: Date, option?: ParsingOption): ParsedResult[];
|
|
7
|
-
export declare function parseDate(text: string, ref?: Date, option?: ParsingOption): Date;
|
|
8
|
-
export declare function createCasualConfiguration(): Configuration;
|
|
9
|
-
export declare function createConfiguration(): Configuration;
|
|
1
|
+
export * from "./hant";
|
|
2
|
+
export { hans } from "./hans";
|
package/dist/locales/zh/index.js
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
4
11
|
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const ZHHantCasualDateParser_1 = __importDefault(require("./hant/parsers/ZHHantCasualDateParser"));
|
|
11
|
-
const ZHHantDateParser_1 = __importDefault(require("./hant/parsers/ZHHantDateParser"));
|
|
12
|
-
const ZHHantDeadlineFormatParser_1 = __importDefault(require("./hant/parsers/ZHHantDeadlineFormatParser"));
|
|
13
|
-
const ZHHantRelationWeekdayParser_1 = __importDefault(require("./hant/parsers/ZHHantRelationWeekdayParser"));
|
|
14
|
-
const ZHHantTimeExpressionParser_1 = __importDefault(require("./hant/parsers/ZHHantTimeExpressionParser"));
|
|
15
|
-
const ZHHantWeekdayParser_1 = __importDefault(require("./hant/parsers/ZHHantWeekdayParser"));
|
|
16
|
-
const ZHHantMergeDateRangeRefiner_1 = __importDefault(require("./hant/refiners/ZHHantMergeDateRangeRefiner"));
|
|
17
|
-
const ZHHantMergeDateTimeRefiner_1 = __importDefault(require("./hant/refiners/ZHHantMergeDateTimeRefiner"));
|
|
18
|
-
exports.hant = new chrono_1.Chrono(createCasualConfiguration());
|
|
19
|
-
exports.casual = new chrono_1.Chrono(createCasualConfiguration());
|
|
20
|
-
exports.strict = new chrono_1.Chrono(createConfiguration());
|
|
21
|
-
function parse(text, ref, option) {
|
|
22
|
-
return exports.casual.parse(text, ref, option);
|
|
23
|
-
}
|
|
24
|
-
exports.parse = parse;
|
|
25
|
-
function parseDate(text, ref, option) {
|
|
26
|
-
return exports.casual.parseDate(text, ref, option);
|
|
27
|
-
}
|
|
28
|
-
exports.parseDate = parseDate;
|
|
29
|
-
function createCasualConfiguration() {
|
|
30
|
-
const option = createConfiguration();
|
|
31
|
-
option.parsers.unshift(new ZHHantCasualDateParser_1.default());
|
|
32
|
-
return option;
|
|
33
|
-
}
|
|
34
|
-
exports.createCasualConfiguration = createCasualConfiguration;
|
|
35
|
-
function createConfiguration() {
|
|
36
|
-
const configuration = configurations_1.includeCommonConfiguration({
|
|
37
|
-
parsers: [
|
|
38
|
-
new ZHHantDateParser_1.default(),
|
|
39
|
-
new ZHHantRelationWeekdayParser_1.default(),
|
|
40
|
-
new ZHHantWeekdayParser_1.default(),
|
|
41
|
-
new ZHHantTimeExpressionParser_1.default(),
|
|
42
|
-
new ZHHantDeadlineFormatParser_1.default(),
|
|
43
|
-
],
|
|
44
|
-
refiners: [new ZHHantMergeDateRangeRefiner_1.default(), new ZHHantMergeDateTimeRefiner_1.default()],
|
|
45
|
-
});
|
|
46
|
-
configuration.refiners = configuration.refiners.filter((refiner) => !(refiner instanceof ExtractTimezoneOffsetRefiner_1.default));
|
|
47
|
-
return configuration;
|
|
48
|
-
}
|
|
49
|
-
exports.createConfiguration = createConfiguration;
|
|
13
|
+
exports.hans = void 0;
|
|
14
|
+
__exportStar(require("./hant"), exports);
|
|
15
|
+
var hans_1 = require("./hans");
|
|
16
|
+
Object.defineProperty(exports, "hans", { enumerable: true, get: function () { return hans_1.hans; } });
|