chrono-node 2.3.1 → 2.3.5

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.
Files changed (97) hide show
  1. package/README.md +1 -1
  2. package/dist/common/casualReferences.js +3 -1
  3. package/dist/common/parsers/AbstractParserWithWordBoundary.js +2 -1
  4. package/dist/common/refiners/ForwardDateRefiner.js +1 -1
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.js +3 -1
  7. package/dist/locales/de/constants.js +1 -1
  8. package/dist/locales/en/constants.js +1 -1
  9. package/dist/locales/en/parsers/ENRelativeDateFormatParser.js +3 -3
  10. package/dist/locales/en/parsers/ENTimeUnitAgoFormatParser.js +1 -1
  11. package/dist/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +1 -1
  12. package/dist/locales/en/parsers/ENTimeUnitLaterFormatParser.js +1 -1
  13. package/dist/locales/en/parsers/ENTimeUnitWithinFormatParser.js +1 -1
  14. package/dist/locales/fr/constants.js +1 -1
  15. package/dist/locales/fr/parsers/FRTimeUnitAgoFormatParser.js +1 -1
  16. package/dist/locales/fr/parsers/FRTimeUnitRelativeFormatParser.js +1 -1
  17. package/dist/locales/fr/parsers/FRTimeUnitWithinFormatParser.js +1 -1
  18. package/dist/locales/nl/parsers/NLRelativeDateFormatParser.js +3 -3
  19. package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.js +1 -1
  20. package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.js +1 -1
  21. package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.js +1 -1
  22. package/dist/locales/nl/parsers/NLTimeUnitWithinFormatParser.js +1 -1
  23. package/dist/locales/zh/hant/constants.d.ts +28 -0
  24. package/dist/locales/zh/hant/constants.js +52 -0
  25. package/dist/locales/zh/hant/parsers/ZHHantCasualDateParser.d.ts +7 -0
  26. package/dist/locales/zh/hant/parsers/ZHHantCasualDateParser.js +138 -0
  27. package/dist/locales/zh/hant/parsers/ZHHantDateParser.d.ts +6 -0
  28. package/dist/locales/zh/hant/parsers/ZHHantDateParser.js +64 -0
  29. package/dist/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.d.ts +6 -0
  30. package/dist/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.js +78 -0
  31. package/dist/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.d.ts +7 -0
  32. package/dist/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.js +70 -0
  33. package/dist/locales/zh/hant/parsers/ZHHantTimeExpressionParser.d.ts +6 -0
  34. package/dist/locales/zh/hant/parsers/ZHHantTimeExpressionParser.js +438 -0
  35. package/dist/locales/zh/hant/parsers/ZHHantWeekdayParser.d.ts +7 -0
  36. package/dist/locales/zh/hant/parsers/ZHHantWeekdayParser.js +46 -0
  37. package/dist/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.d.ts +4 -0
  38. package/dist/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.js +12 -0
  39. package/dist/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.d.ts +4 -0
  40. package/dist/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.js +12 -0
  41. package/dist/locales/zh/index.d.ts +9 -0
  42. package/dist/locales/zh/index.js +49 -0
  43. package/dist/results.d.ts +2 -2
  44. package/dist/results.js +18 -12
  45. package/dist/timezone.d.ts +1 -1
  46. package/dist/timezone.js +3 -0
  47. package/dist/utils/dayjs.js +7 -0
  48. package/package.json +1 -1
  49. package/src/common/casualReferences.ts +3 -1
  50. package/src/common/parsers/AbstractParserWithWordBoundary.ts +1 -1
  51. package/src/common/refiners/ForwardDateRefiner.ts +1 -1
  52. package/src/index.ts +2 -1
  53. package/src/locales/de/constants.ts +1 -1
  54. package/src/locales/en/constants.ts +1 -1
  55. package/src/locales/en/parsers/ENRelativeDateFormatParser.ts +3 -3
  56. package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +1 -1
  57. package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +1 -1
  58. package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +1 -1
  59. package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +1 -1
  60. package/src/locales/fr/constants.ts +1 -1
  61. package/src/locales/fr/parsers/FRTimeUnitAgoFormatParser.ts +1 -1
  62. package/src/locales/fr/parsers/FRTimeUnitRelativeFormatParser.ts +1 -1
  63. package/src/locales/fr/parsers/FRTimeUnitWithinFormatParser.ts +1 -1
  64. package/src/locales/nl/parsers/NLRelativeDateFormatParser.ts +3 -3
  65. package/src/locales/nl/parsers/NLTimeUnitAgoFormatParser.ts +1 -1
  66. package/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +1 -1
  67. package/src/locales/nl/parsers/NLTimeUnitLaterFormatParser.ts +1 -1
  68. package/src/locales/nl/parsers/NLTimeUnitWithinFormatParser.ts +1 -1
  69. package/src/locales/zh/hant/constants.ts +53 -0
  70. package/src/locales/zh/hant/parsers/ZHHantCasualDateParser.ts +128 -0
  71. package/src/locales/zh/hant/parsers/ZHHantDateParser.ts +68 -0
  72. package/src/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.ts +81 -0
  73. package/src/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.ts +69 -0
  74. package/src/locales/zh/hant/parsers/ZHHantTimeExpressionParser.ts +424 -0
  75. package/src/locales/zh/hant/parsers/ZHHantWeekdayParser.ts +46 -0
  76. package/src/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.ts +7 -0
  77. package/src/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.ts +7 -0
  78. package/src/locales/zh/index.ts +63 -0
  79. package/src/results.ts +22 -12
  80. package/src/timezone.ts +5 -1
  81. package/src/utils/dayjs.ts +6 -0
  82. package/test/en/en_casual.test.ts +11 -0
  83. package/test/en/en_month_name_little_endian.test.ts +10 -0
  84. package/test/en/en_relative.test.ts +8 -0
  85. package/test/en/en_slash.test.ts +11 -0
  86. package/test/en/en_time_units_ago.test.ts +16 -0
  87. package/test/en/en_time_units_later.test.ts +6 -0
  88. package/test/en/en_timezone_exp.test.ts +85 -10
  89. package/test/en/en_weekday.test.ts +69 -25
  90. package/test/en/negative_cases.test.ts +2 -0
  91. package/test/test_util.ts +5 -2
  92. package/test/zh/zh.test.ts +18 -0
  93. package/test/zh/zh_hant_casual.test.ts +246 -0
  94. package/test/zh/zh_hant_date.test.ts +103 -0
  95. package/test/zh/zh_hant_deadline.test.ts +136 -0
  96. package/test/zh/zh_hant_time_exp.test.ts +182 -0
  97. package/test/zh/zh_hant_weekday.test.ts +132 -0
@@ -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 ZHHantRelationWeekdayParser extends AbstractParserWithWordBoundaryChecking {
5
+ innerPattern(): RegExp;
6
+ innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingResult;
7
+ }
@@ -0,0 +1,70 @@
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("(?<prefix>上|今|下|這|呢)(?:個)?(?:星期|禮拜|週)(?<weekday>" + Object.keys(constants_1.WEEKDAY_OFFSET).join("|") + ")");
10
+ class ZHHantRelationWeekdayParser 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 modifier = null;
21
+ const prefix = match.groups.prefix;
22
+ if (prefix == "上") {
23
+ modifier = "last";
24
+ }
25
+ else if (prefix == "下") {
26
+ modifier = "next";
27
+ }
28
+ else if (prefix == "今" || prefix == "這" || prefix == "呢") {
29
+ modifier = "this";
30
+ }
31
+ let startMoment = dayjs_1.default(context.refDate);
32
+ let startMomentFixed = false;
33
+ const refOffset = startMoment.day();
34
+ if (modifier == "last" || modifier == "past") {
35
+ startMoment = startMoment.day(offset - 7);
36
+ startMomentFixed = true;
37
+ }
38
+ else if (modifier == "next") {
39
+ startMoment = startMoment.day(offset + 7);
40
+ startMomentFixed = true;
41
+ }
42
+ else if (modifier == "this") {
43
+ startMoment = startMoment.day(offset);
44
+ }
45
+ else {
46
+ if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) {
47
+ startMoment = startMoment.day(offset - 7);
48
+ }
49
+ else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) {
50
+ startMoment = startMoment.day(offset + 7);
51
+ }
52
+ else {
53
+ startMoment = startMoment.day(offset);
54
+ }
55
+ }
56
+ result.start.assign("weekday", offset);
57
+ if (startMomentFixed) {
58
+ result.start.assign("day", startMoment.date());
59
+ result.start.assign("month", startMoment.month() + 1);
60
+ result.start.assign("year", startMoment.year());
61
+ }
62
+ else {
63
+ result.start.imply("day", startMoment.date());
64
+ result.start.imply("month", startMoment.month() + 1);
65
+ result.start.imply("year", startMoment.year());
66
+ }
67
+ return result;
68
+ }
69
+ }
70
+ exports.default = ZHHantRelationWeekdayParser;
@@ -0,0 +1,6 @@
1
+ import { ParsingContext } from "../../../../chrono";
2
+ import { AbstractParserWithWordBoundaryChecking } from "../../../../common/parsers/AbstractParserWithWordBoundary";
3
+ export default class ZHHantTimeExpressionParser extends AbstractParserWithWordBoundaryChecking {
4
+ innerPattern(): RegExp;
5
+ innerExtract(context: ParsingContext, match: RegExpMatchArray): import("../../../../results").ParsingResult;
6
+ }
@@ -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 ZHHantTimeExpressionParser 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
+ var day1 = match[DAY_GROUP_1];
73
+ if (day1 == "明" || day1 == "聽") {
74
+ if (refMoment.hour() > 1) {
75
+ startMoment.add(1, "day");
76
+ }
77
+ }
78
+ else if (day1 == "昨" || day1 == "尋" || 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
+ var day3 = match[DAY_GROUP_3];
99
+ if (day3 == "明" || day3 == "聽") {
100
+ startMoment.add(1, "day");
101
+ }
102
+ else if (day3 == "昨" || day3 == "尋" || 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
+ var 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
+ var 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
+ var zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1];
186
+ var zhAMPM1 = zhAMPMString1[0];
187
+ if (zhAMPM1 == "朝" || 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
+ var zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2];
200
+ var zhAMPM2 = zhAMPMString2[0];
201
+ if (zhAMPM2 == "上" || zhAMPM2 == "朝" || zhAMPM2 == "早" || zhAMPM2 == "凌") {
202
+ meridiem = 0;
203
+ if (hour == 12)
204
+ hour = 0;
205
+ }
206
+ else if (zhAMPM2 == "下" || 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
+ var zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3];
214
+ var zhAMPM3 = zhAMPMString3[0];
215
+ if (zhAMPM3 == "上" || zhAMPM3 == "朝" || zhAMPM3 == "早" || zhAMPM3 == "凌") {
216
+ meridiem = 0;
217
+ if (hour == 12)
218
+ hour = 0;
219
+ }
220
+ else if (zhAMPM3 == "下" || 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
+ var day1 = match[DAY_GROUP_1];
250
+ if (day1 == "明" || day1 == "聽") {
251
+ if (refMoment.hour() > 1) {
252
+ endMoment.add(1, "day");
253
+ }
254
+ }
255
+ else if (day1 == "昨" || day1 == "尋" || 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
+ var day3 = match[DAY_GROUP_3];
276
+ if (day3 == "明" || day3 == "聽") {
277
+ endMoment.add(1, "day");
278
+ }
279
+ else if (day3 == "昨" || day3 == "尋" || 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
+ var 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
+ var 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
+ var zhAMPMString1 = match[ZH_AM_PM_HOUR_GROUP_1];
377
+ var zhAMPM1 = zhAMPMString1[0];
378
+ if (zhAMPM1 == "朝" || 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
+ var zhAMPMString2 = match[ZH_AM_PM_HOUR_GROUP_2];
391
+ var zhAMPM2 = zhAMPMString2[0];
392
+ if (zhAMPM2 == "上" || zhAMPM2 == "朝" || zhAMPM2 == "早" || zhAMPM2 == "凌") {
393
+ meridiem = 0;
394
+ if (hour == 12)
395
+ hour = 0;
396
+ }
397
+ else if (zhAMPM2 == "下" || 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
+ var zhAMPMString3 = match[ZH_AM_PM_HOUR_GROUP_3];
405
+ var zhAMPM3 = zhAMPMString3[0];
406
+ if (zhAMPM3 == "上" || zhAMPM3 == "朝" || zhAMPM3 == "早" || zhAMPM3 == "凌") {
407
+ meridiem = 0;
408
+ if (hour == 12)
409
+ hour = 0;
410
+ }
411
+ else if (zhAMPM3 == "下" || 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 = ZHHantTimeExpressionParser;
@@ -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 ZHHantWeekdayParser 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 ZHHantWeekdayParser 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 = ZHHantWeekdayParser;
@@ -0,0 +1,4 @@
1
+ import AbstractMergeDateRangeRefiner from "../../../../common/refiners/AbstractMergeDateRangeRefiner";
2
+ export default class ZHHantMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner {
3
+ patternBetween(): RegExp;
4
+ }
@@ -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 ZHHantMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner_1.default {
8
+ patternBetween() {
9
+ return /^\s*(至|到|\-|\~|~|-|ー)\s*$/i;
10
+ }
11
+ }
12
+ exports.default = ZHHantMergeDateRangeRefiner;
@@ -0,0 +1,4 @@
1
+ import AbstractMergeDateTimeRefiner from "../../../../common/refiners/AbstractMergeDateTimeRefiner";
2
+ export default class ZHHantMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner {
3
+ patternBetween(): RegExp;
4
+ }
@@ -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 ZHHantMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner_1.default {
8
+ patternBetween() {
9
+ return /^\s*$/i;
10
+ }
11
+ }
12
+ exports.default = ZHHantMergeDateTimeRefiner;
@@ -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("./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;