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.
Files changed (98) hide show
  1. package/README.md +25 -9
  2. package/benchmark/benchmark.js +4 -0
  3. package/dist/bundle.js +5047 -0
  4. package/dist/chrono.d.ts +7 -6
  5. package/dist/chrono.js +6 -5
  6. package/dist/common/casualReferences.d.ts +6 -6
  7. package/dist/common/casualReferences.js +16 -15
  8. package/dist/common/refiners/ForwardDateRefiner.js +1 -1
  9. package/dist/index.d.ts +7 -3
  10. package/dist/locales/de/constants.js +1 -1
  11. package/dist/locales/de/parsers/DECasualDateParser.js +2 -2
  12. package/dist/locales/en/constants.d.ts +1 -1
  13. package/dist/locales/en/constants.js +5 -5
  14. package/dist/locales/en/parsers/ENCasualDateParser.js +5 -5
  15. package/dist/locales/en/parsers/ENCasualTimeParser.js +1 -1
  16. package/dist/locales/en/parsers/ENMonthNameLittleEndianParser.js +6 -8
  17. package/dist/locales/en/parsers/ENRelativeDateFormatParser.js +3 -3
  18. package/dist/locales/en/parsers/ENTimeUnitAgoFormatParser.js +3 -3
  19. package/dist/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +1 -1
  20. package/dist/locales/en/parsers/ENTimeUnitLaterFormatParser.js +2 -2
  21. package/dist/locales/en/parsers/ENTimeUnitWithinFormatParser.js +1 -1
  22. package/dist/locales/fr/constants.js +1 -1
  23. package/dist/locales/fr/parsers/FRCasualDateParser.js +4 -4
  24. package/dist/locales/fr/parsers/FRTimeUnitAgoFormatParser.js +1 -1
  25. package/dist/locales/fr/parsers/FRTimeUnitRelativeFormatParser.js +1 -1
  26. package/dist/locales/fr/parsers/FRTimeUnitWithinFormatParser.js +1 -1
  27. package/dist/locales/ja/parsers/JPCasualDateParser.js +3 -3
  28. package/dist/locales/nl/constants.js +8 -5
  29. package/dist/locales/nl/index.js +12 -3
  30. package/dist/locales/nl/parsers/NLCasualDateParser.js +4 -4
  31. package/dist/locales/nl/parsers/NLRelativeDateFormatParser.d.ts +7 -0
  32. package/dist/locales/nl/parsers/NLRelativeDateFormatParser.js +57 -0
  33. package/dist/locales/nl/parsers/NLTimeExpressionParser.d.ts +1 -0
  34. package/dist/locales/nl/parsers/NLTimeExpressionParser.js +3 -0
  35. package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.d.ts +9 -0
  36. package/dist/locales/nl/parsers/NLTimeUnitAgoFormatParser.js +23 -0
  37. package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.d.ts +7 -0
  38. package/dist/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.js +25 -0
  39. package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.d.ts +9 -0
  40. package/dist/locales/nl/parsers/NLTimeUnitLaterFormatParser.js +22 -0
  41. package/dist/locales/nl/parsers/NLTimeUnitWithinFormatParser.js +1 -1
  42. package/dist/locales/pt/parsers/PTCasualDateParser.js +4 -4
  43. package/dist/main.js +1078 -0
  44. package/dist/results.d.ts +12 -5
  45. package/dist/results.js +40 -17
  46. package/dist/timezone.d.ts +194 -0
  47. package/dist/timezone.js +207 -0
  48. package/dist/utils/dayjs.js +0 -2
  49. package/dist/utils/pattern.js +1 -1
  50. package/package.json +3 -3
  51. package/src/chrono.ts +21 -8
  52. package/src/common/casualReferences.ts +17 -18
  53. package/src/common/refiners/ForwardDateRefiner.ts +1 -1
  54. package/src/index.ts +19 -3
  55. package/src/locales/de/constants.ts +1 -1
  56. package/src/locales/de/parsers/DECasualDateParser.ts +2 -2
  57. package/src/locales/en/constants.ts +5 -5
  58. package/src/locales/en/parsers/ENCasualDateParser.ts +5 -5
  59. package/src/locales/en/parsers/ENCasualTimeParser.ts +1 -1
  60. package/src/locales/en/parsers/ENMonthNameLittleEndianParser.ts +9 -10
  61. package/src/locales/en/parsers/ENRelativeDateFormatParser.ts +3 -3
  62. package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +3 -4
  63. package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +1 -1
  64. package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +2 -2
  65. package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +1 -1
  66. package/src/locales/fr/constants.ts +1 -1
  67. package/src/locales/fr/parsers/FRCasualDateParser.ts +4 -4
  68. package/src/locales/fr/parsers/FRTimeUnitAgoFormatParser.ts +1 -1
  69. package/src/locales/fr/parsers/FRTimeUnitRelativeFormatParser.ts +1 -1
  70. package/src/locales/fr/parsers/FRTimeUnitWithinFormatParser.ts +1 -1
  71. package/src/locales/ja/parsers/JPCasualDateParser.ts +3 -3
  72. package/src/locales/nl/constants.ts +11 -5
  73. package/src/locales/nl/index.ts +12 -3
  74. package/src/locales/nl/parsers/NLCasualDateParser.ts +4 -4
  75. package/src/locales/nl/parsers/NLRelativeDateFormatParser.ts +70 -0
  76. package/src/locales/nl/parsers/NLTimeExpressionParser.ts +4 -0
  77. package/src/locales/nl/parsers/NLTimeUnitAgoFormatParser.ts +26 -0
  78. package/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +27 -0
  79. package/src/locales/nl/parsers/NLTimeUnitLaterFormatParser.ts +27 -0
  80. package/src/locales/nl/parsers/NLTimeUnitWithinFormatParser.ts +1 -1
  81. package/src/locales/pt/parsers/PTCasualDateParser.ts +4 -4
  82. package/src/results.ts +52 -18
  83. package/src/timezone.ts +205 -0
  84. package/src/utils/dayjs.ts +0 -2
  85. package/src/utils/pattern.ts +1 -1
  86. package/test/en/en_month_name_little_endian.test.ts +10 -0
  87. package/test/en/en_relative.test.ts +30 -0
  88. package/test/en/en_slash.test.ts +11 -0
  89. package/test/en/en_timezone_exp.test.ts +7 -4
  90. package/test/en/en_weekday.test.ts +69 -25
  91. package/test/en/negative_cases.test.ts +2 -0
  92. package/test/nl/nl_relative.test.ts +212 -0
  93. package/test/nl/nl_time_units_ago.test.ts +243 -0
  94. package/test/nl/nl_time_units_casual_relative.test.ts +130 -0
  95. package/test/nl/nl_time_units_later.test.ts +250 -0
  96. package/test/result.test.ts +32 -13
  97. package/test/system_timezone.test.ts +100 -0
  98. 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, refDate?: Date, option?: ParsingOption): ParsedResult[] {...}
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 a reference date using `chrono.parse(text, ref)` and `chrono.parseDate(text, ref)`.
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
- chrono.parseDate('Friday', new Date(2012, 7, 23));
80
- // Fri Aug 24 2012 12:00:00 GMT+0700 (ICT)
81
-
82
- chrono.parseDate('Friday', new Date(2012, 7, 1));
83
- // Fri Aug 03 2012 12:00:00 GMT+0700 (ICT)
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)
@@ -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" })