chrono-node 2.7.8 → 2.7.9

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 (149) hide show
  1. package/dist/cjs/locales/en/parsers/ENCasualDateParser.js +4 -1
  2. package/dist/cjs/locales/en/parsers/ENCasualDateParser.js.map +1 -1
  3. package/dist/cjs/locales/it/constants.d.ts +28 -0
  4. package/dist/cjs/locales/it/constants.js +165 -0
  5. package/dist/cjs/locales/it/constants.js.map +1 -0
  6. package/dist/cjs/locales/it/index.d.ts +9 -0
  7. package/dist/cjs/locales/it/index.js +66 -0
  8. package/dist/cjs/locales/it/index.js.map +1 -0
  9. package/dist/cjs/locales/it/parsers/ITCasualDateParser.d.ts +7 -0
  10. package/dist/cjs/locales/it/parsers/ITCasualDateParser.js +65 -0
  11. package/dist/cjs/locales/it/parsers/ITCasualDateParser.js.map +1 -0
  12. package/dist/cjs/locales/it/parsers/ITCasualTimeParser.d.ts +6 -0
  13. package/dist/cjs/locales/it/parsers/ITCasualTimeParser.js +47 -0
  14. package/dist/cjs/locales/it/parsers/ITCasualTimeParser.js.map +1 -0
  15. package/dist/cjs/locales/it/parsers/ITCasualYearMonthDayParser.d.ts +10 -0
  16. package/dist/cjs/locales/it/parsers/ITCasualYearMonthDayParser.js +35 -0
  17. package/dist/cjs/locales/it/parsers/ITCasualYearMonthDayParser.js.map +1 -0
  18. package/dist/cjs/locales/it/parsers/ITMonthNameLittleEndianParser.d.ts +7 -0
  19. package/dist/cjs/locales/it/parsers/ITMonthNameLittleEndianParser.js +57 -0
  20. package/dist/cjs/locales/it/parsers/ITMonthNameLittleEndianParser.js.map +1 -0
  21. package/dist/cjs/locales/it/parsers/ITMonthNameMiddleEndianParser.d.ts +6 -0
  22. package/dist/cjs/locales/it/parsers/ITMonthNameMiddleEndianParser.js +59 -0
  23. package/dist/cjs/locales/it/parsers/ITMonthNameMiddleEndianParser.js.map +1 -0
  24. package/dist/cjs/locales/it/parsers/ITMonthNameParser.d.ts +6 -0
  25. package/dist/cjs/locales/it/parsers/ITMonthNameParser.js +43 -0
  26. package/dist/cjs/locales/it/parsers/ITMonthNameParser.js.map +1 -0
  27. package/dist/cjs/locales/it/parsers/ITRelativeDateFormatParser.d.ts +7 -0
  28. package/dist/cjs/locales/it/parsers/ITRelativeDateFormatParser.js +57 -0
  29. package/dist/cjs/locales/it/parsers/ITRelativeDateFormatParser.js.map +1 -0
  30. package/dist/cjs/locales/it/parsers/ITSlashMonthFormatParser.d.ts +7 -0
  31. package/dist/cjs/locales/it/parsers/ITSlashMonthFormatParser.js +18 -0
  32. package/dist/cjs/locales/it/parsers/ITSlashMonthFormatParser.js.map +1 -0
  33. package/dist/cjs/locales/it/parsers/ITTimeExpressionParser.d.ts +10 -0
  34. package/dist/cjs/locales/it/parsers/ITTimeExpressionParser.js +50 -0
  35. package/dist/cjs/locales/it/parsers/ITTimeExpressionParser.js.map +1 -0
  36. package/dist/cjs/locales/it/parsers/ITTimeUnitAgoFormatParser.d.ts +9 -0
  37. package/dist/cjs/locales/it/parsers/ITTimeUnitAgoFormatParser.js +24 -0
  38. package/dist/cjs/locales/it/parsers/ITTimeUnitAgoFormatParser.js.map +1 -0
  39. package/dist/cjs/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.d.ts +7 -0
  40. package/dist/cjs/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js +26 -0
  41. package/dist/cjs/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js.map +1 -0
  42. package/dist/cjs/locales/it/parsers/ITTimeUnitLaterFormatParser.d.ts +9 -0
  43. package/dist/cjs/locales/it/parsers/ITTimeUnitLaterFormatParser.js +23 -0
  44. package/dist/cjs/locales/it/parsers/ITTimeUnitLaterFormatParser.js.map +1 -0
  45. package/dist/cjs/locales/it/parsers/ITTimeUnitWithinFormatParser.d.ts +7 -0
  46. package/dist/cjs/locales/it/parsers/ITTimeUnitWithinFormatParser.js +19 -0
  47. package/dist/cjs/locales/it/parsers/ITTimeUnitWithinFormatParser.js.map +1 -0
  48. package/dist/cjs/locales/it/parsers/ITWeekdayParser.d.ts +7 -0
  49. package/dist/cjs/locales/it/parsers/ITWeekdayParser.js +43 -0
  50. package/dist/cjs/locales/it/parsers/ITWeekdayParser.js.map +1 -0
  51. package/dist/cjs/locales/it/refiners/ITMergeDateRangeRefiner.d.ts +4 -0
  52. package/dist/cjs/locales/it/refiners/ITMergeDateRangeRefiner.js +13 -0
  53. package/dist/cjs/locales/it/refiners/ITMergeDateRangeRefiner.js.map +1 -0
  54. package/dist/cjs/locales/it/refiners/ITMergeDateTimeRefiner.d.ts +4 -0
  55. package/dist/cjs/locales/it/refiners/ITMergeDateTimeRefiner.js +13 -0
  56. package/dist/cjs/locales/it/refiners/ITMergeDateTimeRefiner.js.map +1 -0
  57. package/dist/cjs/locales/it/refiners/ITMergeRelativeDateRefiner.d.ts +7 -0
  58. package/dist/cjs/locales/it/refiners/ITMergeRelativeDateRefiner.js +36 -0
  59. package/dist/cjs/locales/it/refiners/ITMergeRelativeDateRefiner.js.map +1 -0
  60. package/dist/cjs/locales/ja/parsers/JPCasualDateParser.js +4 -4
  61. package/dist/cjs/locales/ja/refiners/JPMergeDateRangeRefiner.js +1 -1
  62. package/dist/cjs/locales/ja/refiners/JPMergeDateRangeRefiner.js.map +1 -1
  63. package/dist/esm/locales/en/parsers/ENCasualDateParser.js +4 -1
  64. package/dist/esm/locales/en/parsers/ENCasualDateParser.js.map +1 -1
  65. package/dist/esm/locales/it/constants.d.ts +28 -0
  66. package/dist/esm/locales/it/constants.js +200 -0
  67. package/dist/esm/locales/it/constants.js.map +1 -0
  68. package/dist/esm/locales/it/index.d.ts +9 -0
  69. package/dist/esm/locales/it/index.js +56 -0
  70. package/dist/esm/locales/it/index.js.map +1 -0
  71. package/dist/esm/locales/it/parsers/ITCasualDateParser.d.ts +7 -0
  72. package/dist/esm/locales/it/parsers/ITCasualDateParser.js +40 -0
  73. package/dist/esm/locales/it/parsers/ITCasualDateParser.js.map +1 -0
  74. package/dist/esm/locales/it/parsers/ITCasualTimeParser.d.ts +6 -0
  75. package/dist/esm/locales/it/parsers/ITCasualTimeParser.js +41 -0
  76. package/dist/esm/locales/it/parsers/ITCasualTimeParser.js.map +1 -0
  77. package/dist/esm/locales/it/parsers/ITCasualYearMonthDayParser.d.ts +10 -0
  78. package/dist/esm/locales/it/parsers/ITCasualYearMonthDayParser.js +32 -0
  79. package/dist/esm/locales/it/parsers/ITCasualYearMonthDayParser.js.map +1 -0
  80. package/dist/esm/locales/it/parsers/ITMonthNameLittleEndianParser.d.ts +7 -0
  81. package/dist/esm/locales/it/parsers/ITMonthNameLittleEndianParser.js +54 -0
  82. package/dist/esm/locales/it/parsers/ITMonthNameLittleEndianParser.js.map +1 -0
  83. package/dist/esm/locales/it/parsers/ITMonthNameMiddleEndianParser.d.ts +6 -0
  84. package/dist/esm/locales/it/parsers/ITMonthNameMiddleEndianParser.js +56 -0
  85. package/dist/esm/locales/it/parsers/ITMonthNameMiddleEndianParser.js.map +1 -0
  86. package/dist/esm/locales/it/parsers/ITMonthNameParser.d.ts +6 -0
  87. package/dist/esm/locales/it/parsers/ITMonthNameParser.js +40 -0
  88. package/dist/esm/locales/it/parsers/ITMonthNameParser.js.map +1 -0
  89. package/dist/esm/locales/it/parsers/ITRelativeDateFormatParser.d.ts +7 -0
  90. package/dist/esm/locales/it/parsers/ITRelativeDateFormatParser.js +51 -0
  91. package/dist/esm/locales/it/parsers/ITRelativeDateFormatParser.js.map +1 -0
  92. package/dist/esm/locales/it/parsers/ITSlashMonthFormatParser.d.ts +7 -0
  93. package/dist/esm/locales/it/parsers/ITSlashMonthFormatParser.js +15 -0
  94. package/dist/esm/locales/it/parsers/ITSlashMonthFormatParser.js.map +1 -0
  95. package/dist/esm/locales/it/parsers/ITTimeExpressionParser.d.ts +10 -0
  96. package/dist/esm/locales/it/parsers/ITTimeExpressionParser.js +47 -0
  97. package/dist/esm/locales/it/parsers/ITTimeExpressionParser.js.map +1 -0
  98. package/dist/esm/locales/it/parsers/ITTimeUnitAgoFormatParser.d.ts +9 -0
  99. package/dist/esm/locales/it/parsers/ITTimeUnitAgoFormatParser.js +21 -0
  100. package/dist/esm/locales/it/parsers/ITTimeUnitAgoFormatParser.js.map +1 -0
  101. package/dist/esm/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.d.ts +7 -0
  102. package/dist/esm/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js +23 -0
  103. package/dist/esm/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js.map +1 -0
  104. package/dist/esm/locales/it/parsers/ITTimeUnitLaterFormatParser.d.ts +9 -0
  105. package/dist/esm/locales/it/parsers/ITTimeUnitLaterFormatParser.js +20 -0
  106. package/dist/esm/locales/it/parsers/ITTimeUnitLaterFormatParser.js.map +1 -0
  107. package/dist/esm/locales/it/parsers/ITTimeUnitWithinFormatParser.d.ts +7 -0
  108. package/dist/esm/locales/it/parsers/ITTimeUnitWithinFormatParser.js +16 -0
  109. package/dist/esm/locales/it/parsers/ITTimeUnitWithinFormatParser.js.map +1 -0
  110. package/dist/esm/locales/it/parsers/ITWeekdayParser.d.ts +7 -0
  111. package/dist/esm/locales/it/parsers/ITWeekdayParser.js +40 -0
  112. package/dist/esm/locales/it/parsers/ITWeekdayParser.js.map +1 -0
  113. package/dist/esm/locales/it/refiners/ITMergeDateRangeRefiner.d.ts +4 -0
  114. package/dist/esm/locales/it/refiners/ITMergeDateRangeRefiner.js +7 -0
  115. package/dist/esm/locales/it/refiners/ITMergeDateRangeRefiner.js.map +1 -0
  116. package/dist/esm/locales/it/refiners/ITMergeDateTimeRefiner.d.ts +4 -0
  117. package/dist/esm/locales/it/refiners/ITMergeDateTimeRefiner.js +7 -0
  118. package/dist/esm/locales/it/refiners/ITMergeDateTimeRefiner.js.map +1 -0
  119. package/dist/esm/locales/it/refiners/ITMergeRelativeDateRefiner.d.ts +7 -0
  120. package/dist/esm/locales/it/refiners/ITMergeRelativeDateRefiner.js +33 -0
  121. package/dist/esm/locales/it/refiners/ITMergeRelativeDateRefiner.js.map +1 -0
  122. package/dist/esm/locales/ja/parsers/JPCasualDateParser.js +4 -4
  123. package/dist/esm/locales/ja/refiners/JPMergeDateRangeRefiner.js +1 -1
  124. package/dist/esm/locales/ja/refiners/JPMergeDateRangeRefiner.js.map +1 -1
  125. package/package.json +1 -1
  126. package/src/locales/en/parsers/ENCasualDateParser.ts +5 -1
  127. package/src/locales/it/constants.ts +230 -0
  128. package/src/locales/it/index.ts +99 -0
  129. package/src/locales/it/parsers/ITCasualDateParser.ts +53 -0
  130. package/src/locales/it/parsers/ITCasualTimeParser.ts +50 -0
  131. package/src/locales/it/parsers/ITCasualYearMonthDayParser.ts +49 -0
  132. package/src/locales/it/parsers/ITMonthNameLittleEndianParser.ts +69 -0
  133. package/src/locales/it/parsers/ITMonthNameMiddleEndianParser.ts +78 -0
  134. package/src/locales/it/parsers/ITMonthNameParser.ts +62 -0
  135. package/src/locales/it/parsers/ITRelativeDateFormatParser.ts +71 -0
  136. package/src/locales/it/parsers/ITSlashMonthFormatParser.ts +26 -0
  137. package/src/locales/it/parsers/ITTimeExpressionParser.ts +55 -0
  138. package/src/locales/it/parsers/ITTimeUnitAgoFormatParser.ts +25 -0
  139. package/src/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.ts +30 -0
  140. package/src/locales/it/parsers/ITTimeUnitLaterFormatParser.ts +27 -0
  141. package/src/locales/it/parsers/ITTimeUnitWithinFormatParser.ts +26 -0
  142. package/src/locales/it/parsers/ITWeekdayParser.ts +47 -0
  143. package/src/locales/it/refiners/ITMergeDateRangeRefiner.ts +17 -0
  144. package/src/locales/it/refiners/ITMergeDateTimeRefiner.ts +13 -0
  145. package/src/locales/it/refiners/ITMergeRelativeDateRefiner.ts +58 -0
  146. package/src/locales/ja/parsers/JPCasualDateParser.ts +4 -4
  147. package/src/locales/ja/refiners/JPMergeDateRangeRefiner.ts +1 -1
  148. package/test/ja/ja_casual.test.ts +8 -0
  149. package/test/ja/ja_standard.test.ts +19 -0
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "preset": "ts-jest"
16
16
  },
17
17
  "license": "MIT",
18
- "version": "2.7.8",
18
+ "version": "2.7.9",
19
19
  "directories": {
20
20
  "source": "./src",
21
21
  "test": "./test"
@@ -5,7 +5,7 @@ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/
5
5
  import { assignSimilarDate } from "../../../utils/dayjs";
6
6
  import * as references from "../../../common/casualReferences";
7
7
 
8
- const PATTERN = /(now|today|tonight|tomorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i;
8
+ const PATTERN = /(now|today|tonight|tomorrow|overmorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i;
9
9
 
10
10
  export default class ENCasualDateParser extends AbstractParserWithWordBoundaryChecking {
11
11
  innerPattern(context: ParsingContext): RegExp {
@@ -40,6 +40,10 @@ export default class ENCasualDateParser extends AbstractParserWithWordBoundaryCh
40
40
  component = references.tonight(context.reference);
41
41
  break;
42
42
 
43
+ case "overmorrow":
44
+ component = references.theDayAfter(context.reference, 2);
45
+ break;
46
+
43
47
  default:
44
48
  if (lowerText.match(/last\s*night/)) {
45
49
  if (targetDate.hour() > 6) {
@@ -0,0 +1,230 @@
1
+ import { OpUnitType, QUnitType } from "dayjs";
2
+ import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern";
3
+ import { findMostLikelyADYear } from "../../calculation/years";
4
+ import { TimeUnits } from "../../utils/timeunits";
5
+
6
+ export const WEEKDAY_DICTIONARY: { [word: string]: number } = {
7
+ "domenica": 0,
8
+ "dom": 0,
9
+ "lunedì": 1,
10
+ "lun": 1,
11
+ "martedì": 2,
12
+ "mar": 2,
13
+ "mercoledì": 3,
14
+ "merc": 3,
15
+ "giovedì": 4,
16
+ "giov": 4,
17
+ "venerdì": 5,
18
+ "ven": 5,
19
+ "sabato": 6,
20
+ "sab": 6,
21
+ };
22
+
23
+ export const FULL_MONTH_NAME_DICTIONARY: { [word: string]: number } = {};
24
+
25
+ export const MONTH_DICTIONARY: { [word: string]: number } = {
26
+ ...FULL_MONTH_NAME_DICTIONARY,
27
+ "gennaio": 1,
28
+ "gen": 1,
29
+ "gen.": 1,
30
+ "febbraio": 2,
31
+ "feb": 2,
32
+ "feb.": 2,
33
+ "febraio": 2,
34
+ "febb": 2,
35
+ "febb.": 2,
36
+ "marzo": 3,
37
+ "mar": 3,
38
+ "mar.": 3,
39
+ "aprile": 4,
40
+ "apr": 4,
41
+ "apr.": 4,
42
+ "maggio": 5,
43
+ "mag": 5,
44
+ "giugno": 6,
45
+ "giu": 6,
46
+ "luglio": 7,
47
+ "lug": 7,
48
+ "lugl": 7,
49
+ "lug.": 7,
50
+ "agosto": 8,
51
+ "ago": 8,
52
+ "settembre": 9,
53
+ "set": 9,
54
+ "set.": 9,
55
+ "sett": 9,
56
+ "sett.": 9,
57
+ "ottobre": 10,
58
+ "ott": 10,
59
+ "ott.": 10,
60
+ "novembre": 11,
61
+ "nov": 11,
62
+ "nov.": 11,
63
+ "dicembre": 12,
64
+ "dic": 12,
65
+ "dice": 12,
66
+ "dic.": 12,
67
+ };
68
+
69
+ export const INTEGER_WORD_DICTIONARY: { [word: string]: number } = {
70
+ "uno": 1,
71
+ "due": 2,
72
+ "tre": 3,
73
+ "quattro": 4,
74
+ "cinque": 5,
75
+ "sei": 6,
76
+ "sette": 7,
77
+ "otto": 8,
78
+ "nove": 9,
79
+ "dieci": 10,
80
+ "undici": 11,
81
+ "dodici": 12,
82
+ };
83
+
84
+ export const ORDINAL_WORD_DICTIONARY: { [word: string]: number } = {
85
+ "primo": 1,
86
+ "secondo": 2,
87
+ "terzo": 3,
88
+ "quarto": 4,
89
+ "quinto": 5,
90
+ "sesto": 6,
91
+ "settimo": 7,
92
+ "ottavo": 8,
93
+ "nono": 9,
94
+ "decimo": 10,
95
+ "undicesimo": 11,
96
+ "dodicesimo": 12,
97
+ "tredicesimo": 13,
98
+ "quattordicesimo": 14,
99
+ "quindicesimo": 15,
100
+ "sedicesimo": 16,
101
+ "diciassettesimo": 17,
102
+ "diciottesimo": 18,
103
+ "diciannovesimo": 19,
104
+ "ventesimo": 20,
105
+ "ventunesimo": 21,
106
+ "ventiduesimo": 22,
107
+ "ventitreesimo": 23,
108
+ "ventiquattresimo": 24,
109
+ "venticinquesimo": 25,
110
+ "ventiseiesimo": 26,
111
+ "ventisettesimo": 27,
112
+ "ventottesimo": 28,
113
+ "ventinovesimo": 29,
114
+ "trentesimo": 30,
115
+ "trentunesimo": 31,
116
+ };
117
+
118
+ export const TIME_UNIT_DICTIONARY: { [word: string]: OpUnitType | QUnitType } = {
119
+ "sec": "second",
120
+ "secondo": "second",
121
+ "secondi": "second",
122
+ "min": "minute",
123
+ "mins": "minute",
124
+ "minuti": "minute",
125
+ "h": "hour",
126
+ "hr": "hour",
127
+ "o": "hour",
128
+ "ora": "hour",
129
+ "ore": "hour",
130
+ "giorno": "d",
131
+ "giorni": "d",
132
+ "settimana": "week",
133
+ "settimane": "week",
134
+ "mese": "month",
135
+ "trimestre": "quarter",
136
+ "trimestri": "quarter",
137
+ "anni": "year",
138
+ "anno": "year",
139
+ };
140
+
141
+ //-----------------------------
142
+
143
+ export const NUMBER_PATTERN = `(?:${matchAnyPattern(
144
+ INTEGER_WORD_DICTIONARY
145
+ )}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s{0,2}un?)?|un?\\b(?:\\s{0,2}qualcuno)?|qualcuno|molti|a?\\s{0,2}alcuni\\s{0,2}(?:of)?)`;
146
+
147
+ export function parseNumberPattern(match: string): number {
148
+ const num = match.toLowerCase();
149
+ if (INTEGER_WORD_DICTIONARY[num] !== undefined) {
150
+ return INTEGER_WORD_DICTIONARY[num];
151
+ } else if (num === "un" || num === "una") {
152
+ return 1;
153
+ } else if (num.match(/alcuni/)) {
154
+ return 3;
155
+ } else if (num.match(/metá/)) {
156
+ return 0.5;
157
+ } else if (num.match(/paio/)) {
158
+ return 2;
159
+ } else if (num.match(/molti/)) {
160
+ return 7;
161
+ }
162
+
163
+ return parseFloat(num);
164
+ }
165
+
166
+ //-----------------------------
167
+
168
+ export const ORDINAL_NUMBER_PATTERN = `(?:${matchAnyPattern(
169
+ ORDINAL_WORD_DICTIONARY
170
+ )}|[0-9]{1,2}(?:mo|ndo|rzo|simo|esimo)?)`;
171
+ export function parseOrdinalNumberPattern(match: string): number {
172
+ let num = match.toLowerCase();
173
+ if (ORDINAL_WORD_DICTIONARY[num] !== undefined) {
174
+ return ORDINAL_WORD_DICTIONARY[num];
175
+ }
176
+
177
+ num = num.replace(/(?:imo|ndo|rzo|rto|nto|sto|tavo|nono|cimo|timo|esimo)$/i, "");
178
+ return parseInt(num);
179
+ }
180
+
181
+ //-----------------------------
182
+
183
+ export 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])`;
184
+ export function parseYear(match: string): number {
185
+ if (/BE/i.test(match)) {
186
+ // Buddhist Era
187
+ match = match.replace(/BE/i, "");
188
+ return parseInt(match) - 543;
189
+ }
190
+
191
+ if (/BCE?/i.test(match)) {
192
+ // Before Christ, Before Common Era
193
+ match = match.replace(/BCE?/i, "");
194
+ return -parseInt(match);
195
+ }
196
+
197
+ if (/(AD|CE)/i.test(match)) {
198
+ // Anno Domini, Common Era
199
+ match = match.replace(/(AD|CE)/i, "");
200
+ return parseInt(match);
201
+ }
202
+
203
+ const rawYearNumber = parseInt(match);
204
+ return findMostLikelyADYear(rawYearNumber);
205
+ }
206
+
207
+ //-----------------------------
208
+
209
+ const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,3}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})`;
210
+ const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i");
211
+
212
+ export const TIME_UNITS_PATTERN = repeatedTimeunitPattern(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_PATTERN);
213
+
214
+ export function parseTimeUnits(timeunitText): TimeUnits {
215
+ const fragments = {};
216
+ let remainingText = timeunitText;
217
+ let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText);
218
+ while (match) {
219
+ collectDateTimeFragment(fragments, match);
220
+ remainingText = remainingText.substring(match[0].length).trim();
221
+ match = SINGLE_TIME_UNIT_REGEX.exec(remainingText);
222
+ }
223
+ return fragments;
224
+ }
225
+
226
+ function collectDateTimeFragment(fragments, match) {
227
+ const num = parseNumberPattern(match[1]);
228
+ const unit = TIME_UNIT_DICTIONARY[match[2].toLowerCase()];
229
+ fragments[unit] = num;
230
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Chrono components for Italian support (*parsers*, *refiners*, and *configuration*)
3
+ *
4
+ * @module
5
+ */
6
+
7
+ import ENTimeUnitWithinFormatParser from "./parsers/ITTimeUnitWithinFormatParser";
8
+ import ENMonthNameLittleEndianParser from "./parsers/ITMonthNameLittleEndianParser";
9
+ import ENMonthNameMiddleEndianParser from "./parsers/ITMonthNameMiddleEndianParser";
10
+ import ENMonthNameParser from "./parsers/ITMonthNameParser";
11
+ import ENCasualYearMonthDayParser from "./parsers/ITCasualYearMonthDayParser";
12
+ import ENSlashMonthFormatParser from "./parsers/ITSlashMonthFormatParser";
13
+ import ENTimeExpressionParser from "./parsers/ITTimeExpressionParser";
14
+ import ENTimeUnitAgoFormatParser from "./parsers/ITTimeUnitAgoFormatParser";
15
+ import ENTimeUnitLaterFormatParser from "./parsers/ITTimeUnitLaterFormatParser";
16
+ import ENMergeDateRangeRefiner from "./refiners/ITMergeDateRangeRefiner";
17
+ import ENMergeDateTimeRefiner from "./refiners/ITMergeDateTimeRefiner";
18
+
19
+ import { includeCommonConfiguration } from "../../configurations";
20
+ import ENCasualDateParser from "./parsers/ITCasualDateParser";
21
+ import ENCasualTimeParser from "./parsers/ITCasualTimeParser";
22
+ import ENWeekdayParser from "./parsers/ITWeekdayParser";
23
+ import ENRelativeDateFormatParser from "./parsers/ITRelativeDateFormatParser";
24
+
25
+ import { ParsedResult, ParsingOption } from "../../index";
26
+ import { Chrono, Configuration } from "../../chrono";
27
+ import SlashDateFormatParser from "../../common/parsers/SlashDateFormatParser";
28
+ import ENTimeUnitCasualRelativeFormatParser from "./parsers/ITTimeUnitCasualRelativeFormatParser";
29
+ import ENMergeRelativeDateRefiner from "./refiners/ITMergeRelativeDateRefiner";
30
+
31
+ /**
32
+ * Chrono object configured for parsing *casual* Italian
33
+ */
34
+ export const casual = new Chrono(createCasualConfiguration(false));
35
+
36
+ /**
37
+ * Chrono object configured for parsing *strict* Italian
38
+ */
39
+ export const strict = new Chrono(createConfiguration(true, false));
40
+
41
+ /**
42
+ * Chrono object configured for parsing Italian
43
+ */
44
+ export const GB = new Chrono(createConfiguration(false, true));
45
+
46
+ /**
47
+ * A shortcut for en.casual.parse()
48
+ */
49
+ export function parse(text: string, ref?: Date, option?: ParsingOption): ParsedResult[] {
50
+ return casual.parse(text, ref, option);
51
+ }
52
+
53
+ /**
54
+ * A shortcut for en.casual.parseDate()
55
+ */
56
+ export function parseDate(text: string, ref?: Date, option?: ParsingOption): Date {
57
+ return casual.parseDate(text, ref, option);
58
+ }
59
+
60
+ /**
61
+ * Create a default *casual* {@Link Configuration} for Italian chrono.
62
+ * It calls {@Link createConfiguration} and includes additional parsers.
63
+ */
64
+ export function createCasualConfiguration(littleEndian = false): Configuration {
65
+ const option = createConfiguration(false, littleEndian);
66
+ option.parsers.unshift(new ENCasualDateParser());
67
+ option.parsers.unshift(new ENCasualTimeParser());
68
+ option.parsers.unshift(new ENMonthNameParser());
69
+ option.parsers.unshift(new ENRelativeDateFormatParser());
70
+ option.parsers.unshift(new ENTimeUnitCasualRelativeFormatParser());
71
+ return option;
72
+ }
73
+
74
+ /**
75
+ * Create a default {@Link Configuration} for Italian chrono
76
+ *
77
+ * @param strictMode If the timeunit mentioning should be strict, not casual
78
+ * @param littleEndian If format should be date-first/littleEndian (e.g. en_UK), not month-first/middleEndian (e.g. en_US)
79
+ */
80
+ export function createConfiguration(strictMode = true, littleEndian = false): Configuration {
81
+ return includeCommonConfiguration(
82
+ {
83
+ parsers: [
84
+ new SlashDateFormatParser(littleEndian),
85
+ new ENTimeUnitWithinFormatParser(),
86
+ new ENMonthNameLittleEndianParser(),
87
+ new ENMonthNameMiddleEndianParser(),
88
+ new ENWeekdayParser(),
89
+ new ENCasualYearMonthDayParser(),
90
+ new ENSlashMonthFormatParser(),
91
+ new ENTimeExpressionParser(strictMode),
92
+ new ENTimeUnitAgoFormatParser(strictMode),
93
+ new ENTimeUnitLaterFormatParser(strictMode),
94
+ ],
95
+ refiners: [new ENMergeRelativeDateRefiner(), new ENMergeDateTimeRefiner(), new ENMergeDateRangeRefiner()],
96
+ },
97
+ strictMode
98
+ );
99
+ }
@@ -0,0 +1,53 @@
1
+ import { ParsingContext } from "../../../chrono";
2
+ import { ParsingComponents, ParsingResult } from "../../../results";
3
+ import dayjs from "dayjs";
4
+ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
5
+ import { assignSimilarDate } from "../../../utils/dayjs";
6
+ import * as references from "../../../common/casualReferences";
7
+
8
+ const PATTERN = /(ora|oggi|stasera|questa sera|domani|dmn|ieri\s*sera)(?=\W|$)/i;
9
+
10
+ export default class ENCasualDateParser extends AbstractParserWithWordBoundaryChecking {
11
+ innerPattern(context: ParsingContext): RegExp {
12
+ return PATTERN;
13
+ }
14
+
15
+ innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | ParsingResult {
16
+ let targetDate = dayjs(context.refDate);
17
+ const lowerText = match[0].toLowerCase();
18
+ const component = context.createParsingComponents();
19
+
20
+ switch (lowerText) {
21
+ case "ora":
22
+ return references.now(context.reference);
23
+
24
+ case "oggi":
25
+ return references.today(context.reference);
26
+
27
+ case "ieri":
28
+ return references.yesterday(context.reference);
29
+
30
+ case "domani":
31
+ case "dmn":
32
+ return references.tomorrow(context.reference);
33
+
34
+ case "stasera":
35
+ case "questa sera":
36
+ return references.tonight(context.reference);
37
+
38
+ default:
39
+ if (lowerText.match(/ieri\s*sera/)) {
40
+ if (targetDate.hour() > 6) {
41
+ targetDate = targetDate.add(-1, "day");
42
+ }
43
+
44
+ assignSimilarDate(component, targetDate);
45
+ component.imply("hour", 0);
46
+ }
47
+
48
+ break;
49
+ }
50
+
51
+ return component;
52
+ }
53
+ }
@@ -0,0 +1,50 @@
1
+ import { ParsingContext } from "../../../chrono";
2
+ import { Meridiem } from "../../../index";
3
+ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
4
+ import dayjs from "dayjs";
5
+ import { assignTheNextDay } from "../../../utils/dayjs";
6
+
7
+ const PATTERN = /(?:questo|questa)?\s{0,3}(mattina|pomeriggio|sera|notte|mezzanotte|mezzogiorno)(?=\W|$)/i;
8
+
9
+ export default class ENCasualTimeParser extends AbstractParserWithWordBoundaryChecking {
10
+ innerPattern() {
11
+ return PATTERN;
12
+ }
13
+
14
+ innerExtract(context: ParsingContext, match: RegExpMatchArray) {
15
+ const targetDate = dayjs(context.refDate);
16
+ const component = context.createParsingComponents();
17
+
18
+ switch (match[1].toLowerCase()) {
19
+ case "pomeriggio":
20
+ component.imply("meridiem", Meridiem.PM);
21
+ component.imply("hour", 15);
22
+ break;
23
+
24
+ case "sera":
25
+ case "notte":
26
+ component.imply("meridiem", Meridiem.PM);
27
+ component.imply("hour", 20);
28
+ break;
29
+
30
+ case "mezzanotte":
31
+ assignTheNextDay(component, targetDate);
32
+ component.imply("hour", 0);
33
+ component.imply("minute", 0);
34
+ component.imply("second", 0);
35
+ break;
36
+
37
+ case "mattina":
38
+ component.imply("meridiem", Meridiem.AM);
39
+ component.imply("hour", 6);
40
+ break;
41
+
42
+ case "mezzogiorno":
43
+ component.imply("meridiem", Meridiem.AM);
44
+ component.imply("hour", 12);
45
+ break;
46
+ }
47
+
48
+ return component;
49
+ }
50
+ }
@@ -0,0 +1,49 @@
1
+ import { ParsingContext } from "../../../chrono";
2
+ import { MONTH_DICTIONARY } from "../constants";
3
+ import { matchAnyPattern } from "../../../utils/pattern";
4
+ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
5
+
6
+ /*
7
+ Date format with slash "/" between numbers like ENSlashDateFormatParser,
8
+ but this parser expect year before month and date.
9
+ - YYYY/MM/DD
10
+ - YYYY-MM-DD
11
+ - YYYY.MM.DD
12
+ */
13
+ const PATTERN = new RegExp(
14
+ `([0-9]{4})[\\.\\/\\s]` +
15
+ `(?:(${matchAnyPattern(MONTH_DICTIONARY)})|([0-9]{1,2}))[\\.\\/\\s]` +
16
+ `([0-9]{1,2})` +
17
+ "(?=\\W|$)",
18
+ "i"
19
+ );
20
+
21
+ const YEAR_NUMBER_GROUP = 1;
22
+ const MONTH_NAME_GROUP = 2;
23
+ const MONTH_NUMBER_GROUP = 3;
24
+ const DATE_NUMBER_GROUP = 4;
25
+
26
+ export default class ENCasualYearMonthDayParser extends AbstractParserWithWordBoundaryChecking {
27
+ innerPattern(): RegExp {
28
+ return PATTERN;
29
+ }
30
+
31
+ innerExtract(context: ParsingContext, match: RegExpMatchArray) {
32
+ const month = match[MONTH_NUMBER_GROUP]
33
+ ? parseInt(match[MONTH_NUMBER_GROUP])
34
+ : MONTH_DICTIONARY[match[MONTH_NAME_GROUP].toLowerCase()];
35
+
36
+ if (month < 1 || month > 12) {
37
+ return null;
38
+ }
39
+
40
+ const year = parseInt(match[YEAR_NUMBER_GROUP]);
41
+ const day = parseInt(match[DATE_NUMBER_GROUP]);
42
+
43
+ return {
44
+ day: day,
45
+ month: month,
46
+ year: year,
47
+ };
48
+ }
49
+ }
@@ -0,0 +1,69 @@
1
+ import { ParsingContext } from "../../../chrono";
2
+ import { ParsingResult } from "../../../results";
3
+ import { findYearClosestToRef } from "../../../calculation/years";
4
+ import { MONTH_DICTIONARY } from "../constants";
5
+ import { YEAR_PATTERN, parseYear } from "../constants";
6
+ import { ORDINAL_NUMBER_PATTERN, parseOrdinalNumberPattern } from "../constants";
7
+ import { matchAnyPattern } from "../../../utils/pattern";
8
+ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
9
+
10
+ // prettier-ignore
11
+ const PATTERN = new RegExp(
12
+ `(?:on\\s{0,3})?` +
13
+ `(${ORDINAL_NUMBER_PATTERN})` +
14
+ `(?:` +
15
+ `\\s{0,3}(?:al|\\-|\\–|fino|alle|allo)?\\s{0,3}` +
16
+ `(${ORDINAL_NUMBER_PATTERN})` +
17
+ ")?" +
18
+ `(?:-|/|\\s{0,3}(?:dal)?\\s{0,3})` +
19
+ `(${matchAnyPattern(MONTH_DICTIONARY)})` +
20
+ "(?:" +
21
+ `(?:-|/|,?\\s{0,3})` +
22
+ `(${YEAR_PATTERN}(?![^\\s]\\d))` +
23
+ ")?" +
24
+ "(?=\\W|$)",
25
+ "i"
26
+ );
27
+
28
+ const DATE_GROUP = 1;
29
+ const DATE_TO_GROUP = 2;
30
+ const MONTH_NAME_GROUP = 3;
31
+ const YEAR_GROUP = 4;
32
+
33
+ export default class ENMonthNameLittleEndianParser extends AbstractParserWithWordBoundaryChecking {
34
+ innerPattern(): RegExp {
35
+ return PATTERN;
36
+ }
37
+
38
+ innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingResult {
39
+ const result = context.createParsingResult(match.index, match[0]);
40
+
41
+ const month = MONTH_DICTIONARY[match[MONTH_NAME_GROUP].toLowerCase()];
42
+ const day = parseOrdinalNumberPattern(match[DATE_GROUP]);
43
+ if (day > 31) {
44
+ // e.g. "[96 Aug]" => "9[6 Aug]", we need to shift away from the next number
45
+ match.index = match.index + match[DATE_GROUP].length;
46
+ return null;
47
+ }
48
+
49
+ result.start.assign("month", month);
50
+ result.start.assign("day", day);
51
+
52
+ if (match[YEAR_GROUP]) {
53
+ const yearNumber = parseYear(match[YEAR_GROUP]);
54
+ result.start.assign("year", yearNumber);
55
+ } else {
56
+ const year = findYearClosestToRef(context.refDate, day, month);
57
+ result.start.imply("year", year);
58
+ }
59
+
60
+ if (match[DATE_TO_GROUP]) {
61
+ const endDate = parseOrdinalNumberPattern(match[DATE_TO_GROUP]);
62
+
63
+ result.end = result.start.clone();
64
+ result.end.assign("day", endDate);
65
+ }
66
+
67
+ return result;
68
+ }
69
+ }
@@ -0,0 +1,78 @@
1
+ import { ParsingContext } from "../../../chrono";
2
+ import { findYearClosestToRef } from "../../../calculation/years";
3
+ import { MONTH_DICTIONARY } from "../constants";
4
+ import { ORDINAL_NUMBER_PATTERN, parseOrdinalNumberPattern } from "../constants";
5
+ import { YEAR_PATTERN, parseYear } from "../constants";
6
+ import { matchAnyPattern } from "../../../utils/pattern";
7
+ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
8
+
9
+ const PATTERN = new RegExp(
10
+ `(${matchAnyPattern(MONTH_DICTIONARY)})` +
11
+ "(?:-|/|\\s*,?\\s*)" +
12
+ `(${ORDINAL_NUMBER_PATTERN})(?!\\s*(?:am|pm))\\s*` +
13
+ "(?:" +
14
+ "(?:al|\\-|\\alle|\\del|\\s)\\s*" +
15
+ `(${ORDINAL_NUMBER_PATTERN})\\s*` +
16
+ ")?" +
17
+ "(?:" +
18
+ "(?:-|/|\\s*,?\\s*)" +
19
+ `(${YEAR_PATTERN})` +
20
+ ")?" +
21
+ "(?=\\W|$)(?!\\:\\d)",
22
+ "i"
23
+ );
24
+
25
+ const MONTH_NAME_GROUP = 1;
26
+ const DATE_GROUP = 2;
27
+ const DATE_TO_GROUP = 3;
28
+ const YEAR_GROUP = 4;
29
+
30
+ /**
31
+ * The parser for parsing US's date format that begin with month's name.
32
+ * - January 13
33
+ * - January 13, 2012
34
+ * - January 13 - 15, 2012
35
+ * Note: Watch out for:
36
+ * - January 12:00
37
+ * - January 12.44
38
+ * - January 1222344
39
+ */
40
+ export default class ENMonthNameMiddleEndianParser extends AbstractParserWithWordBoundaryChecking {
41
+ innerPattern(): RegExp {
42
+ return PATTERN;
43
+ }
44
+
45
+ innerExtract(context: ParsingContext, match: RegExpMatchArray) {
46
+ const month = MONTH_DICTIONARY[match[MONTH_NAME_GROUP].toLowerCase()];
47
+ const day = parseOrdinalNumberPattern(match[DATE_GROUP]);
48
+ if (day > 31) {
49
+ return null;
50
+ }
51
+
52
+ const components = context.createParsingComponents({
53
+ day: day,
54
+ month: month,
55
+ });
56
+
57
+ if (match[YEAR_GROUP]) {
58
+ const year = parseYear(match[YEAR_GROUP]);
59
+ components.assign("year", year);
60
+ } else {
61
+ const year = findYearClosestToRef(context.refDate, day, month);
62
+ components.imply("year", year);
63
+ }
64
+
65
+ if (!match[DATE_TO_GROUP]) {
66
+ return components;
67
+ }
68
+
69
+ // Text can be 'range' value. Such as 'January 12 - 13, 2012'
70
+ const endDate = parseOrdinalNumberPattern(match[DATE_TO_GROUP]);
71
+ const result = context.createParsingResult(match.index, match[0]);
72
+ result.start = components;
73
+ result.end = components.clone();
74
+ result.end.assign("day", endDate);
75
+
76
+ return result;
77
+ }
78
+ }