chrono-node 2.3.2 → 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.
Files changed (134) 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/ExtractTimezoneAbbrRefiner.js +5 -0
  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/hans/constants.d.ts +27 -0
  24. package/dist/locales/zh/hans/constants.js +51 -0
  25. package/dist/locales/zh/hans/index.d.ts +9 -0
  26. package/dist/locales/zh/hans/index.js +49 -0
  27. package/dist/locales/zh/hans/parsers/ZHHansCasualDateParser.d.ts +7 -0
  28. package/dist/locales/zh/hans/parsers/ZHHansCasualDateParser.js +138 -0
  29. package/dist/locales/zh/hans/parsers/ZHHansDateParser.d.ts +6 -0
  30. package/dist/locales/zh/hans/parsers/ZHHansDateParser.js +72 -0
  31. package/dist/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.d.ts +6 -0
  32. package/dist/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.js +78 -0
  33. package/dist/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.d.ts +7 -0
  34. package/dist/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.js +70 -0
  35. package/dist/locales/zh/hans/parsers/ZHHansTimeExpressionParser.d.ts +6 -0
  36. package/dist/locales/zh/hans/parsers/ZHHansTimeExpressionParser.js +438 -0
  37. package/dist/locales/zh/hans/parsers/ZHHansWeekdayParser.d.ts +7 -0
  38. package/dist/locales/zh/hans/parsers/ZHHansWeekdayParser.js +46 -0
  39. package/dist/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.d.ts +4 -0
  40. package/dist/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.js +12 -0
  41. package/dist/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.d.ts +4 -0
  42. package/dist/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.js +12 -0
  43. package/dist/locales/zh/hant/constants.d.ts +28 -0
  44. package/dist/locales/zh/hant/constants.js +52 -0
  45. package/dist/locales/zh/hant/index.d.ts +9 -0
  46. package/dist/locales/zh/hant/index.js +49 -0
  47. package/dist/locales/zh/hant/parsers/ZHHantCasualDateParser.d.ts +7 -0
  48. package/dist/locales/zh/hant/parsers/ZHHantCasualDateParser.js +138 -0
  49. package/dist/locales/zh/hant/parsers/ZHHantDateParser.d.ts +6 -0
  50. package/dist/locales/zh/hant/parsers/ZHHantDateParser.js +64 -0
  51. package/dist/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.d.ts +6 -0
  52. package/dist/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.js +78 -0
  53. package/dist/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.d.ts +7 -0
  54. package/dist/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.js +70 -0
  55. package/dist/locales/zh/hant/parsers/ZHHantTimeExpressionParser.d.ts +6 -0
  56. package/dist/locales/zh/hant/parsers/ZHHantTimeExpressionParser.js +438 -0
  57. package/dist/locales/zh/hant/parsers/ZHHantWeekdayParser.d.ts +7 -0
  58. package/dist/locales/zh/hant/parsers/ZHHantWeekdayParser.js +46 -0
  59. package/dist/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.d.ts +4 -0
  60. package/dist/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.js +12 -0
  61. package/dist/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.d.ts +4 -0
  62. package/dist/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.js +12 -0
  63. package/dist/locales/zh/index.d.ts +2 -0
  64. package/dist/locales/zh/index.js +16 -0
  65. package/dist/results.d.ts +2 -2
  66. package/dist/results.js +18 -12
  67. package/dist/timezone.d.ts +1 -1
  68. package/dist/timezone.js +3 -0
  69. package/dist/utils/dayjs.js +7 -0
  70. package/package.json +1 -1
  71. package/src/common/casualReferences.ts +3 -1
  72. package/src/common/parsers/AbstractParserWithWordBoundary.ts +1 -1
  73. package/src/common/refiners/ExtractTimezoneAbbrRefiner.ts +8 -0
  74. package/src/index.ts +2 -1
  75. package/src/locales/de/constants.ts +1 -1
  76. package/src/locales/en/constants.ts +1 -1
  77. package/src/locales/en/parsers/ENMonthNameLittleEndianParser.ts +0 -2
  78. package/src/locales/en/parsers/ENRelativeDateFormatParser.ts +3 -3
  79. package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +1 -1
  80. package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +1 -1
  81. package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +1 -1
  82. package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +1 -1
  83. package/src/locales/fr/constants.ts +1 -1
  84. package/src/locales/fr/parsers/FRTimeUnitAgoFormatParser.ts +1 -1
  85. package/src/locales/fr/parsers/FRTimeUnitRelativeFormatParser.ts +1 -1
  86. package/src/locales/fr/parsers/FRTimeUnitWithinFormatParser.ts +1 -1
  87. package/src/locales/nl/parsers/NLRelativeDateFormatParser.ts +3 -3
  88. package/src/locales/nl/parsers/NLTimeUnitAgoFormatParser.ts +1 -1
  89. package/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +1 -1
  90. package/src/locales/nl/parsers/NLTimeUnitLaterFormatParser.ts +1 -1
  91. package/src/locales/nl/parsers/NLTimeUnitWithinFormatParser.ts +1 -1
  92. package/src/locales/zh/hans/constants.ts +52 -0
  93. package/src/locales/zh/hans/index.ts +62 -0
  94. package/src/locales/zh/hans/parsers/ZHHansCasualDateParser.ts +128 -0
  95. package/src/locales/zh/hans/parsers/ZHHansDateParser.ts +75 -0
  96. package/src/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.ts +81 -0
  97. package/src/locales/zh/hans/parsers/ZHHansRelationWeekdayParser.ts +69 -0
  98. package/src/locales/zh/hans/parsers/ZHHansTimeExpressionParser.ts +424 -0
  99. package/src/locales/zh/hans/parsers/ZHHansWeekdayParser.ts +46 -0
  100. package/src/locales/zh/hans/refiners/ZHHansMergeDateRangeRefiner.ts +7 -0
  101. package/src/locales/zh/hans/refiners/ZHHansMergeDateTimeRefiner.ts +7 -0
  102. package/src/locales/zh/hant/constants.ts +53 -0
  103. package/src/locales/zh/hant/index.ts +63 -0
  104. package/src/locales/zh/hant/parsers/ZHHantCasualDateParser.ts +128 -0
  105. package/src/locales/zh/hant/parsers/ZHHantDateParser.ts +68 -0
  106. package/src/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.ts +81 -0
  107. package/src/locales/zh/hant/parsers/ZHHantRelationWeekdayParser.ts +69 -0
  108. package/src/locales/zh/hant/parsers/ZHHantTimeExpressionParser.ts +424 -0
  109. package/src/locales/zh/hant/parsers/ZHHantWeekdayParser.ts +46 -0
  110. package/src/locales/zh/hant/refiners/ZHHantMergeDateRangeRefiner.ts +7 -0
  111. package/src/locales/zh/hant/refiners/ZHHantMergeDateTimeRefiner.ts +7 -0
  112. package/src/locales/zh/index.ts +2 -0
  113. package/src/results.ts +22 -12
  114. package/src/timezone.ts +5 -1
  115. package/src/utils/dayjs.ts +6 -0
  116. package/test/en/en_casual.test.ts +11 -0
  117. package/test/en/en_month.test.ts +13 -0
  118. package/test/en/en_relative.test.ts +8 -0
  119. package/test/en/en_time_units_ago.test.ts +16 -0
  120. package/test/en/en_time_units_later.test.ts +6 -0
  121. package/test/en/en_timezone_exp.test.ts +85 -10
  122. package/test/en/negative_cases.test.ts +2 -0
  123. package/test/test_util.ts +5 -2
  124. package/test/zh/zh.test.ts +18 -0
  125. package/test/zh/zh_hans_casual.test.ts +228 -0
  126. package/test/zh/zh_hans_date.test.ts +102 -0
  127. package/test/zh/zh_hans_deadline.test.ts +136 -0
  128. package/test/zh/zh_hans_time_exp.test.ts +182 -0
  129. package/test/zh/zh_hans_weekday.test.ts +132 -0
  130. package/test/zh/zh_hant_casual.test.ts +246 -0
  131. package/test/zh/zh_hant_date.test.ts +102 -0
  132. package/test/zh/zh_hant_deadline.test.ts +136 -0
  133. package/test/zh/zh_hant_time_exp.test.ts +182 -0
  134. package/test/zh/zh_hant_weekday.test.ts +132 -0
@@ -0,0 +1,132 @@
1
+ import * as chrono from "../../src";
2
+ import { testSingleCase } from "../test_util";
3
+
4
+ test("Test - Single Expression", function () {
5
+ testSingleCase(chrono.zh.hant, "星期四", new Date(2016, 9 - 1, 2), (result) => {
6
+ expect(result.index).toBe(0);
7
+ expect(result.text).toBe("星期四");
8
+
9
+ expect(result.start).not.toBeNull();
10
+ expect(result.start.get("year")).toBe(2016);
11
+ expect(result.start.get("month")).toBe(9);
12
+ expect(result.start.get("day")).toBe(1);
13
+ expect(result.start.get("weekday")).toBe(4);
14
+
15
+ expect(result.start.isCertain("day")).toBe(false);
16
+ expect(result.start.isCertain("month")).toBe(false);
17
+ expect(result.start.isCertain("year")).toBe(false);
18
+ expect(result.start.isCertain("weekday")).toBe(true);
19
+
20
+ const resultDate = result.start.date();
21
+ const expectDate = new Date(2016, 9 - 1, 1, 12);
22
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
23
+ });
24
+
25
+ testSingleCase(
26
+ chrono.zh.hant,
27
+ "禮拜四 (forward dates only)",
28
+ new Date(2016, 9 - 1, 2),
29
+ { forwardDate: true },
30
+ (result) => {
31
+ expect(result.index).toBe(0);
32
+ expect(result.text).toBe("禮拜四");
33
+
34
+ expect(result.start).not.toBeNull();
35
+ expect(result.start.get("year")).toBe(2016);
36
+ expect(result.start.get("month")).toBe(9);
37
+ expect(result.start.get("day")).toBe(8);
38
+ expect(result.start.get("weekday")).toBe(4);
39
+
40
+ expect(result.start.isCertain("day")).toBe(false);
41
+ expect(result.start.isCertain("month")).toBe(false);
42
+ expect(result.start.isCertain("year")).toBe(false);
43
+ expect(result.start.isCertain("weekday")).toBe(true);
44
+
45
+ const resultDate = result.start.date();
46
+ const expectDate = new Date(2016, 9 - 1, 8, 12);
47
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
48
+ }
49
+ );
50
+
51
+ testSingleCase(chrono.zh.hant, "禮拜日", new Date(2016, 9 - 1, 2), (result) => {
52
+ expect(result.index).toBe(0);
53
+ expect(result.text).toBe("禮拜日");
54
+
55
+ expect(result.start).not.toBeNull();
56
+ expect(result.start.get("year")).toBe(2016);
57
+ expect(result.start.get("month")).toBe(9);
58
+ expect(result.start.get("day")).toBe(4);
59
+ expect(result.start.get("weekday")).toBe(0);
60
+
61
+ const resultDate = result.start.date();
62
+ const expectDate = new Date(2016, 9 - 1, 4, 12);
63
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
64
+ });
65
+
66
+ testSingleCase(chrono.zh.hant, "雞上個禮拜三全部都係雞", new Date(2016, 9 - 1, 2), (result) => {
67
+ expect(result.index).toBe(1);
68
+ expect(result.text).toBe("上個禮拜三");
69
+
70
+ expect(result.start).not.toBeNull();
71
+ expect(result.start.get("year")).toBe(2016);
72
+ expect(result.start.get("month")).toBe(8);
73
+ expect(result.start.get("day")).toBe(24);
74
+ expect(result.start.get("weekday")).toBe(3);
75
+
76
+ const resultDate = result.start.date();
77
+ const expectDate = new Date(2016, 8 - 1, 24, 12);
78
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
79
+ });
80
+
81
+ testSingleCase(chrono.zh.hant, "雞下星期天全部都係雞", new Date(2016, 9 - 1, 2), (result) => {
82
+ expect(result.index).toBe(1);
83
+ expect(result.text).toBe("下星期天");
84
+
85
+ expect(result.start).not.toBeNull();
86
+ expect(result.start.get("year")).toBe(2016);
87
+ expect(result.start.get("month")).toBe(9);
88
+ expect(result.start.get("day")).toBe(4);
89
+ expect(result.start.get("weekday")).toBe(0);
90
+
91
+ const resultDate = result.start.date();
92
+ const expectDate = new Date(2016, 9 - 1, 4, 12);
93
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
94
+ });
95
+ });
96
+
97
+ test("Test - forward dates only option", function () {
98
+ testSingleCase(chrono.zh.hant, "星期六-星期一", new Date(2016, 9 - 1, 2), { forwardDate: true }, (result) => {
99
+ expect(result.index).toBe(0);
100
+ expect(result.text).toBe("星期六-星期一");
101
+
102
+ expect(result.start).not.toBeNull();
103
+ expect(result.start.get("year")).toBe(2016);
104
+ expect(result.start.get("month")).toBe(9);
105
+ expect(result.start.get("day")).toBe(3);
106
+ expect(result.start.get("weekday")).toBe(6);
107
+
108
+ expect(result.start.isCertain("day")).toBe(false);
109
+ expect(result.start.isCertain("month")).toBe(false);
110
+ expect(result.start.isCertain("year")).toBe(false);
111
+ expect(result.start.isCertain("weekday")).toBe(true);
112
+
113
+ var resultDate = result.start.date();
114
+ var expectDate = new Date(2016, 9 - 1, 3, 12);
115
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
116
+
117
+ expect(result.end).not.toBeNull();
118
+ expect(result.end.get("year")).toBe(2016);
119
+ expect(result.end.get("month")).toBe(9);
120
+ expect(result.end.get("day")).toBe(5);
121
+ expect(result.end.get("weekday")).toBe(1);
122
+
123
+ expect(result.end.isCertain("day")).toBe(false);
124
+ expect(result.end.isCertain("month")).toBe(false);
125
+ expect(result.end.isCertain("year")).toBe(false);
126
+ expect(result.end.isCertain("weekday")).toBe(true);
127
+
128
+ var resultDate = result.end.date();
129
+ var expectDate = new Date(2016, 9 - 1, 5, 12);
130
+ expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
131
+ });
132
+ });