chrono-node 2.2.7 → 2.3.3
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/README.md +25 -9
- package/benchmark/benchmark.js +4 -0
- package/dist/bundle.js +5047 -0
- package/dist/chrono.d.ts +7 -6
- package/dist/chrono.js +6 -5
- package/dist/common/casualReferences.d.ts +6 -6
- package/dist/common/casualReferences.js +16 -15
- package/dist/common/refiners/ForwardDateRefiner.js +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/locales/de/constants.js +1 -1
- package/dist/locales/de/parsers/DECasualDateParser.js +2 -2
- package/dist/locales/en/constants.d.ts +1 -1
- package/dist/locales/en/constants.js +5 -5
- package/dist/locales/en/parsers/ENCasualDateParser.js +5 -5
- package/dist/locales/en/parsers/ENCasualTimeParser.js +1 -1
- package/dist/locales/en/parsers/ENMonthNameLittleEndianParser.js +6 -8
- package/dist/locales/en/parsers/ENRelativeDateFormatParser.js +3 -3
- package/dist/locales/en/parsers/ENTimeUnitAgoFormatParser.js +3 -3
- package/dist/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +1 -1
- package/dist/locales/en/parsers/ENTimeUnitLaterFormatParser.js +2 -2
- package/dist/locales/en/parsers/ENTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/fr/constants.js +1 -1
- package/dist/locales/fr/parsers/FRCasualDateParser.js +4 -4
- package/dist/locales/fr/parsers/FRTimeUnitAgoFormatParser.js +1 -1
- package/dist/locales/fr/parsers/FRTimeUnitRelativeFormatParser.js +1 -1
- package/dist/locales/fr/parsers/FRTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/ja/parsers/JPCasualDateParser.js +3 -3
- package/dist/locales/nl/constants.js +8 -5
- package/dist/locales/nl/index.js +12 -3
- package/dist/locales/nl/parsers/NLCasualDateParser.js +4 -4
- package/dist/locales/nl/parsers/NLRelativeDateFormatParser.d.ts +7 -0
- package/dist/locales/nl/parsers/NLRelativeDateFormatParser.js +57 -0
- package/dist/locales/nl/parsers/NLTimeExpressionParser.d.ts +1 -0
- package/dist/locales/nl/parsers/NLTimeExpressionParser.js +3 -0
- package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.d.ts +9 -0
- package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.js +23 -0
- package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.d.ts +7 -0
- package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.js +25 -0
- package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.d.ts +9 -0
- package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.js +22 -0
- package/dist/locales/nl/parsers/NLTimeUnitWithinFormatParser.js +1 -1
- package/dist/locales/pt/parsers/PTCasualDateParser.js +4 -4
- package/dist/main.js +1078 -0
- package/dist/results.d.ts +12 -5
- package/dist/results.js +40 -17
- package/dist/timezone.d.ts +194 -0
- package/dist/timezone.js +207 -0
- package/dist/utils/dayjs.js +0 -2
- package/dist/utils/pattern.js +1 -1
- package/package.json +3 -3
- package/src/chrono.ts +21 -8
- package/src/common/casualReferences.ts +17 -18
- package/src/common/refiners/ForwardDateRefiner.ts +1 -1
- package/src/index.ts +19 -3
- package/src/locales/de/constants.ts +1 -1
- package/src/locales/de/parsers/DECasualDateParser.ts +2 -2
- package/src/locales/en/constants.ts +5 -5
- package/src/locales/en/parsers/ENCasualDateParser.ts +5 -5
- package/src/locales/en/parsers/ENCasualTimeParser.ts +1 -1
- package/src/locales/en/parsers/ENMonthNameLittleEndianParser.ts +9 -10
- package/src/locales/en/parsers/ENRelativeDateFormatParser.ts +3 -3
- package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +3 -4
- package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +1 -1
- package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +2 -2
- package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/fr/constants.ts +1 -1
- package/src/locales/fr/parsers/FRCasualDateParser.ts +4 -4
- package/src/locales/fr/parsers/FRTimeUnitAgoFormatParser.ts +1 -1
- package/src/locales/fr/parsers/FRTimeUnitRelativeFormatParser.ts +1 -1
- package/src/locales/fr/parsers/FRTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/ja/parsers/JPCasualDateParser.ts +3 -3
- package/src/locales/nl/constants.ts +11 -5
- package/src/locales/nl/index.ts +12 -3
- package/src/locales/nl/parsers/NLCasualDateParser.ts +4 -4
- package/src/locales/nl/parsers/NLRelativeDateFormatParser.ts +70 -0
- package/src/locales/nl/parsers/NLTimeExpressionParser.ts +4 -0
- package/src/locales/nl/parsers/NLTimeUnitAgoFormatParser.ts +26 -0
- package/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +27 -0
- package/src/locales/nl/parsers/NLTimeUnitLaterFormatParser.ts +27 -0
- package/src/locales/nl/parsers/NLTimeUnitWithinFormatParser.ts +1 -1
- package/src/locales/pt/parsers/PTCasualDateParser.ts +4 -4
- package/src/results.ts +52 -18
- package/src/timezone.ts +205 -0
- package/src/utils/dayjs.ts +0 -2
- package/src/utils/pattern.ts +1 -1
- package/test/en/en_month_name_little_endian.test.ts +10 -0
- package/test/en/en_relative.test.ts +30 -0
- package/test/en/en_slash.test.ts +11 -0
- package/test/en/en_timezone_exp.test.ts +7 -4
- package/test/en/en_weekday.test.ts +69 -25
- package/test/en/negative_cases.test.ts +2 -0
- package/test/nl/nl_relative.test.ts +212 -0
- package/test/nl/nl_time_units_ago.test.ts +243 -0
- package/test/nl/nl_time_units_casual_relative.test.ts +130 -0
- package/test/nl/nl_time_units_later.test.ts +250 -0
- package/test/result.test.ts +32 -13
- package/test/system_timezone.test.ts +100 -0
- package/test/test_util.ts +10 -7
package/README.md
CHANGED
|
@@ -66,23 +66,39 @@ chrono.parse('An appointment on Sep 12-13');
|
|
|
66
66
|
|
|
67
67
|
For more advanced usage, here is the typescript definition of the `parse` function:
|
|
68
68
|
```typescript
|
|
69
|
-
parse(text: string,
|
|
69
|
+
parse(text: string, ref?: ParsingReference, option?: ParsingOption): ParsedResult[] {...}
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
#### Reference Date
|
|
72
|
+
#### Parsing Reference (Date / Timezone)
|
|
73
73
|
|
|
74
74
|
Today's "Friday" is different from last month's "Friday".
|
|
75
|
-
The meaning of the referenced dates depends on when they are mentioned.
|
|
76
|
-
Chrono lets you define
|
|
75
|
+
The meaning of the referenced dates depends on when and where they are mentioned.
|
|
76
|
+
Chrono lets you define the reference as `Date` or `ParsingReference` object:
|
|
77
77
|
|
|
78
78
|
```javascript
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
// (Note: the exmaples run on JST timezone)
|
|
80
|
+
|
|
81
|
+
chrono.parseDate('Friday', new Date(2012, 8 - 1, 23));
|
|
82
|
+
// Fri Aug 24 2012 12:00:00 GMT+0900 (JST)
|
|
83
|
+
|
|
84
|
+
chrono.parseDate('Friday', new Date(2012, 8 - 1, 1));
|
|
85
|
+
// Fri Aug 03 2012 12:00:00 GMT+0900 (JST)
|
|
86
|
+
|
|
87
|
+
chrono.parseDate("Friday at 4pm", {
|
|
88
|
+
// Wed Jun 09 2021 21:00:00 GMT+0900 (JST)
|
|
89
|
+
// = Wed Jun 09 2021 07:00:00 GMT-0500 (CDT)
|
|
90
|
+
instant: new Date(1623240000000),
|
|
91
|
+
timezone: "CDT",
|
|
92
|
+
})
|
|
93
|
+
// Sat Jun 12 2021 06:00:00 GMT+0900 (JST)
|
|
94
|
+
// = Fri Jun 11 2021 16:00:00 GMT-0500 (CDT)
|
|
84
95
|
```
|
|
85
96
|
|
|
97
|
+
#### ParsingReference
|
|
98
|
+
* `instance?: Date` The instant when the input is written or mentioned
|
|
99
|
+
* `timezone?: string | number` The timezone where the input is written or mentioned.
|
|
100
|
+
Support minute-offset (number) and timezone name (e.g. "GMT", "CDT")
|
|
101
|
+
|
|
86
102
|
### Parsing Options
|
|
87
103
|
|
|
88
104
|
`forwardDate` (boolean) to assume the results should happen after the reference date (forward into the future)
|
package/benchmark/benchmark.js
CHANGED
|
@@ -12,6 +12,10 @@ b.suite(
|
|
|
12
12
|
chrono.en.parseDate("11/12/2021");
|
|
13
13
|
}),
|
|
14
14
|
|
|
15
|
+
b.add("Parsing a long repeated space", () => {
|
|
16
|
+
chrono.parse(`second ${" ".repeat(1000)} fourth ${" ".repeat(1000)} jum`);
|
|
17
|
+
}),
|
|
18
|
+
|
|
15
19
|
b.cycle(),
|
|
16
20
|
b.complete(),
|
|
17
21
|
b.save({ file: "chrono", format: "chart.html" })
|