chrono-node 1.3.5 → 1.4.4

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 (195) hide show
  1. package/.travis.yml +2 -0
  2. package/README.md +100 -86
  3. package/dist/chrono.js +7865 -0
  4. package/dist/chrono.js.map +1 -0
  5. package/dist/chrono.min.js +3 -0
  6. package/dist/chrono.min.js.LICENSE.txt +19 -0
  7. package/dist/chrono.min.js.map +1 -0
  8. package/package.json +20 -22
  9. package/src/chrono.js +5 -3
  10. package/src/options.js +33 -3
  11. package/src/parsers/{DE → de}/DECasualDateParser.js +18 -21
  12. package/src/parsers/{DE → de}/DEDeadlineFormatParser.js +9 -9
  13. package/src/parsers/{DE → de}/DEMonthNameLittleEndianParser.js +15 -36
  14. package/src/parsers/{DE → de}/DEMonthNameParser.js +12 -27
  15. package/src/parsers/{DE → de}/DESlashDateFormatParser.js +2 -3
  16. package/src/parsers/{DE → de}/DETimeAgoFormatParser.js +9 -14
  17. package/src/parsers/{DE → de}/DETimeExpressionParser.js +2 -2
  18. package/src/parsers/{DE → de}/DEWeekdayParser.js +14 -14
  19. package/src/parsers/{EN → en}/ENCasualDateParser.js +6 -11
  20. package/src/parsers/en/ENCasualTimeParser.js +54 -0
  21. package/src/parsers/{EN → en}/ENDeadlineFormatParser.js +15 -20
  22. package/src/parsers/{EN → en}/ENISOFormatParser.js +3 -3
  23. package/src/parsers/{EN → en}/ENMonthNameLittleEndianParser.js +25 -49
  24. package/src/parsers/{EN → en}/ENMonthNameMiddleEndianParser.js +6 -23
  25. package/src/parsers/{EN → en}/ENMonthNameParser.js +5 -22
  26. package/src/parsers/{EN → en}/ENRelativeDateFormatParser.js +48 -15
  27. package/src/parsers/{EN → en}/ENSlashDateFormatParser.js +7 -3
  28. package/src/parsers/{EN → en}/ENSlashDateFormatStartWithYearParser.js +12 -5
  29. package/src/parsers/{EN → en}/ENSlashMonthFormatParser.js +2 -5
  30. package/src/parsers/en/ENTimeAgoFormatParser.js +69 -0
  31. package/src/parsers/{EN → en}/ENTimeExpressionParser.js +26 -17
  32. package/src/parsers/en/ENTimeLaterFormatParser.js +75 -0
  33. package/src/parsers/{EN → en}/ENWeekdayParser.js +8 -12
  34. package/src/parsers/{ES → es}/ESCasualDateParser.js +8 -13
  35. package/src/parsers/{ES → es}/ESDeadlineFormatParser.js +5 -11
  36. package/src/parsers/{ES → es}/ESMonthNameLittleEndianParser.js +6 -28
  37. package/src/parsers/{ES → es}/ESSlashDateFormatParser.js +2 -2
  38. package/src/parsers/{ES → es}/ESTimeAgoFormatParser.js +8 -13
  39. package/src/parsers/{ES → es}/ESTimeExpressionParser.js +2 -7
  40. package/src/parsers/{ES → es}/ESWeekdayParser.js +1 -6
  41. package/src/parsers/{FR → fr}/FRCasualDateParser.js +6 -11
  42. package/src/parsers/{FR → fr}/FRDeadlineFormatParser.js +9 -14
  43. package/src/parsers/{FR → fr}/FRMonthNameLittleEndianParser.js +4 -26
  44. package/src/parsers/{FR → fr}/FRRelativeDateFormatParser.js +29 -34
  45. package/src/parsers/{FR → fr}/FRSlashDateFormatParser.js +22 -15
  46. package/src/parsers/{FR → fr}/FRTimeAgoFormatParser.js +8 -14
  47. package/src/parsers/{FR → fr}/FRTimeExpressionParser.js +2 -7
  48. package/src/parsers/{FR → fr}/FRWeekdayParser.js +1 -6
  49. package/src/parsers/{JP → ja}/JPCasualDateParser.js +5 -10
  50. package/src/parsers/ja/JPStandardParser.js +71 -0
  51. package/src/parsers/parser.js +80 -53
  52. package/src/parsers/pt/PTCasualDateParser.js +123 -0
  53. package/src/parsers/pt/PTDeadlineFormatParser.js +61 -0
  54. package/src/parsers/pt/PTMonthNameLittleEndianParser.js +86 -0
  55. package/src/parsers/pt/PTSlashDateFormatParser.js +114 -0
  56. package/src/parsers/pt/PTTimeAgoFormatParser.js +87 -0
  57. package/src/parsers/pt/PTTimeExpressionParser.js +234 -0
  58. package/src/parsers/pt/PTWeekdayParser.js +60 -0
  59. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantCasualDateParser.js +30 -19
  60. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantDateParser.js +2 -7
  61. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantDeadlineFormatParser.js +14 -19
  62. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantTimeExpressionParser.js +38 -11
  63. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantWeekdayParser.js +1 -7
  64. package/src/refiners/ExtractTimezoneAbbrRefiner.js +19 -10
  65. package/src/refiners/ForwardDateRefiner.js +10 -15
  66. package/src/refiners/{DE → de}/DEMergeDateRangeRefiner.js +1 -1
  67. package/src/refiners/{DE → de}/DEMergeDateTimeRefiner.js +3 -3
  68. package/src/refiners/{EN → en}/ENMergeDateRangeRefiner.js +5 -9
  69. package/src/refiners/{EN → en}/ENMergeDateTimeRefiner.js +15 -2
  70. package/src/refiners/{EN → en}/ENMergeWeekdayRefiner.js +0 -0
  71. package/src/refiners/{EN → en}/ENPrioritizeSpecificDateRefiner.js +0 -0
  72. package/src/refiners/{FR → fr}/FRMergeDateRangeRefiner.js +0 -0
  73. package/src/refiners/{FR → fr}/FRMergeDateTimeRefiner.js +1 -1
  74. package/src/refiners/{JP → ja}/JPMergeDateRangeRefiner.js +1 -1
  75. package/src/refiners/refiner.js +12 -12
  76. package/src/result.js +47 -19
  77. package/src/timezone.js +2 -0
  78. package/src/utils/EN.js +68 -2
  79. package/src/utils/PT.js +62 -0
  80. package/test/de/de.test.js +51 -0
  81. package/test/de/de_casual.test.js +432 -0
  82. package/test/de/de_dash.test.js +6 -0
  83. package/test/de/de_deadline.test.js +244 -0
  84. package/test/de/de_little_endian.test.js +459 -0
  85. package/test/de/de_time_ago.test.js +313 -0
  86. package/test/de/de_time_exp.test.js +166 -0
  87. package/test/de/de_weekday.test.js +235 -0
  88. package/test/en/en.test.js +250 -0
  89. package/test/en/en_casual.test.js +461 -0
  90. package/test/en/en_dash.test.js +31 -0
  91. package/test/en/en_deadline.test.js +366 -0
  92. package/test/{test_example.js → en/en_example.test.js} +7 -18
  93. package/test/en/en_inter_std.test.js +269 -0
  94. package/test/en/en_little_endian.test.js +566 -0
  95. package/test/en/en_middle_endian.test.js +552 -0
  96. package/test/en/en_month.test.js +156 -0
  97. package/test/en/en_option_forward.test.js +156 -0
  98. package/test/en/en_relative.test.js +228 -0
  99. package/test/en/en_slash.test.js +450 -0
  100. package/test/en/en_time_ago.test.js +374 -0
  101. package/test/en/en_time_exp.test.js +722 -0
  102. package/test/en/en_time_from_now.test.js +371 -0
  103. package/test/en/en_time_later.test.js +95 -0
  104. package/test/en/en_weekday.test.js +301 -0
  105. package/test/es/es_casual.test.js +258 -0
  106. package/test/es/es_dash.test.js +13 -0
  107. package/test/es/es_deadline.test.js +85 -0
  108. package/test/es/es_little_endian.test.js +350 -0
  109. package/test/es/es_slash.test.js +24 -0
  110. package/test/es/es_time_ago.test.js +137 -0
  111. package/test/es/es_time_exp.test.js +240 -0
  112. package/test/fr/fr_casual.test.js +454 -0
  113. package/test/fr/fr_dash.test.js +26 -0
  114. package/test/fr/fr_deadline.test.js +244 -0
  115. package/test/fr/fr_little_endian.test.js +576 -0
  116. package/test/fr/fr_relative.test.js +198 -0
  117. package/test/fr/fr_slash.test.js +81 -0
  118. package/test/fr/fr_time_ago.test.js +194 -0
  119. package/test/fr/fr_time_exp.test.js +960 -0
  120. package/test/fr/fr_weekday.test.js +200 -0
  121. package/test/ja/ja_casual.test.js +51 -0
  122. package/test/ja/ja_standard.test.js +344 -0
  123. package/test/pt/pt_casual.test.js +258 -0
  124. package/test/pt/pt_dash.test.js +13 -0
  125. package/test/pt/pt_deadline.test.js +85 -0
  126. package/test/pt/pt_little_endian.test.js +350 -0
  127. package/test/pt/pt_slash.test.js +44 -0
  128. package/test/pt/pt_time_ago.test.js +137 -0
  129. package/test/pt/pt_time_exp.test.js +240 -0
  130. package/test/system.test.js +207 -0
  131. package/test/zh/zh_hant_casual.test.js +340 -0
  132. package/test/zh/zh_hant_date.test.js +118 -0
  133. package/test/zh/zh_hant_deadline.test.js +213 -0
  134. package/test/zh/zh_hant_time_exp.test.js +226 -0
  135. package/test/zh/zh_hant_weekday.test.js +160 -0
  136. package/webpack.config.js +39 -0
  137. package/.npmignore +0 -11
  138. package/bower.json +0 -24
  139. package/chrono.js +0 -11892
  140. package/chrono.map.json +0 -1
  141. package/chrono.min.js +0 -148
  142. package/chrono.min.json +0 -1
  143. package/karma.conf.js +0 -68
  144. package/src/parsers/EN/ENCasualTimeParser.js +0 -53
  145. package/src/parsers/EN/ENTimeAgoFormatParser.js +0 -130
  146. package/src/parsers/EN/ENTimeFromNowFormatParser.js +0 -119
  147. package/src/parsers/JP/JPStandardParser.js +0 -88
  148. package/test/test_de.js +0 -62
  149. package/test/test_de_casual.js +0 -443
  150. package/test/test_de_dash.js +0 -17
  151. package/test/test_de_deadline.js +0 -255
  152. package/test/test_de_little_endian.js +0 -470
  153. package/test/test_de_time_ago.js +0 -324
  154. package/test/test_de_time_exp.js +0 -177
  155. package/test/test_de_weekday.js +0 -246
  156. package/test/test_en.js +0 -249
  157. package/test/test_en_casual.js +0 -448
  158. package/test/test_en_dash.js +0 -42
  159. package/test/test_en_deadline.js +0 -311
  160. package/test/test_en_inter_std.js +0 -272
  161. package/test/test_en_little_endian.js +0 -529
  162. package/test/test_en_middle_endian.js +0 -563
  163. package/test/test_en_month.js +0 -124
  164. package/test/test_en_option_forward.js +0 -167
  165. package/test/test_en_relative.js +0 -206
  166. package/test/test_en_slash.js +0 -370
  167. package/test/test_en_time_ago.js +0 -385
  168. package/test/test_en_time_exp.js +0 -663
  169. package/test/test_en_time_from_now.js +0 -345
  170. package/test/test_en_weekday.js +0 -312
  171. package/test/test_es_casual.js +0 -269
  172. package/test/test_es_dash.js +0 -24
  173. package/test/test_es_deadline.js +0 -96
  174. package/test/test_es_little_endian.js +0 -361
  175. package/test/test_es_slash.js +0 -35
  176. package/test/test_es_time_ago.js +0 -148
  177. package/test/test_es_time_exp.js +0 -251
  178. package/test/test_fr_casual.js +0 -465
  179. package/test/test_fr_dash.js +0 -37
  180. package/test/test_fr_deadline.js +0 -255
  181. package/test/test_fr_little_endian.js +0 -568
  182. package/test/test_fr_relative.js +0 -209
  183. package/test/test_fr_slash.js +0 -54
  184. package/test/test_fr_time_ago.js +0 -205
  185. package/test/test_fr_time_exp.js +0 -971
  186. package/test/test_fr_weekday.js +0 -211
  187. package/test/test_jp_casual.js +0 -62
  188. package/test/test_jp_standard.js +0 -181
  189. package/test/test_system.js +0 -178
  190. package/test/test_zh_hant_casual.js +0 -329
  191. package/test/test_zh_hant_date.js +0 -129
  192. package/test/test_zh_hant_deadline.js +0 -224
  193. package/test/test_zh_hant_time_exp.js +0 -210
  194. package/test/test_zh_hant_weekday.js +0 -171
  195. package/timezone.js +0 -9
@@ -1,8 +1,4 @@
1
- /*
2
-
3
- */
4
-
5
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
6
2
  var Parser = require('../parser').Parser;
7
3
  var ParsedResult = require('../../result').ParsedResult;
8
4
  var ParsedComponents = require('../../result').ParsedComponents;
@@ -13,10 +9,10 @@ var FIRST_REG_PATTERN = new RegExp("(^|\\s|T)" +
13
9
  "(?:" +
14
10
  "(?:\\.|\\:|\\:)(\\d{1,2})" +
15
11
  "(?:" +
16
- "(?:\\:|\\:)(\\d{2})" +
12
+ "(?:\\:|\\:)(\\d{2})(?:\\.(\\d{1,6}))?" +
17
13
  ")?" +
18
14
  ")?" +
19
- "(?:\\s*(A\\.M\\.|P\\.M\\.|AM?|PM?))?" +
15
+ "(?:\\s*(A\\.M\\.|P\\.M\\.|AM?|PM?|O\\W*CLOCK))?" +
20
16
  "(?=\\W|$)", 'i');
21
17
 
22
18
 
@@ -26,16 +22,17 @@ var SECOND_REG_PATTERN = new RegExp("^\\s*" +
26
22
  "(?:" +
27
23
  "(?:\\.|\\:|\\:)(\\d{1,2})" +
28
24
  "(?:" +
29
- "(?:\\.|\\:|\\:)(\\d{1,2})" +
25
+ "(?:\\.|\\:|\\:)(\\d{1,2})(?:\\.(\\d{1,6}))?" +
30
26
  ")?" +
31
27
  ")?" +
32
- "(?:\\s*(A\\.M\\.|P\\.M\\.|AM?|PM?))?" +
28
+ "(?:\\s*(A\\.M\\.|P\\.M\\.|AM?|PM?|O\\W*CLOCK))?" +
33
29
  "(?=\\W|$)", 'i');
34
30
 
35
31
  var HOUR_GROUP = 2;
36
32
  var MINUTE_GROUP = 3;
37
33
  var SECOND_GROUP = 4;
38
- var AM_PM_HOUR_GROUP = 5;
34
+ var MILLI_SECOND_GROUP = 5;
35
+ var AM_PM_HOUR_GROUP = 6;
39
36
 
40
37
 
41
38
  exports.Parser = function ENTimeExpressionParser(){
@@ -45,9 +42,9 @@ exports.Parser = function ENTimeExpressionParser(){
45
42
 
46
43
  this.extract = function(text, ref, match, opt){
47
44
 
48
- // This pattern can be overlaped Ex. [12] AM, 1[2] AM
45
+ // This pattern can be overlapped Ex. [12] AM, 1[2] AM
49
46
  if (match.index > 0 && text[match.index-1].match(/\w/)) return null;
50
- var refMoment = moment(ref);
47
+ var refMoment = dayjs(ref);
51
48
  var result = new ParsedResult();
52
49
  result.ref = ref;
53
50
  result.index = match.index + match[1].length;
@@ -62,6 +59,14 @@ exports.Parser = function ENTimeExpressionParser(){
62
59
  var minute = 0;
63
60
  var meridiem = -1;
64
61
 
62
+ // ----- Millisecond
63
+ if(match[MILLI_SECOND_GROUP] != null){
64
+ var millisecond = parseInt(match[MILLI_SECOND_GROUP].substring(0, 3));
65
+ if(millisecond >= 1000) return null;
66
+
67
+ result.start.assign('millisecond', millisecond);
68
+ }
69
+
65
70
  // ----- Second
66
71
  if(match[SECOND_GROUP] != null){
67
72
  var second = parseInt(match[SECOND_GROUP]);
@@ -127,16 +132,12 @@ exports.Parser = function ENTimeExpressionParser(){
127
132
  result.start.imply('meridiem', 1);
128
133
  }
129
134
  }
130
-
135
+
131
136
  // ==============================================================
132
137
  // Extracting the 'to' chunk
133
138
  // ==============================================================
134
139
  match = SECOND_REG_PATTERN.exec(text.substring(result.index + result.text.length));
135
140
  if (!match) {
136
- // Not accept number only result
137
- if (result.text.match(/^\d+$/)) {
138
- return null;
139
- }
140
141
  return result;
141
142
  }
142
143
 
@@ -155,6 +156,14 @@ exports.Parser = function ENTimeExpressionParser(){
155
156
  var minute = 0;
156
157
  var meridiem = -1;
157
158
 
159
+ // ----- Millisecond
160
+ if(match[MILLI_SECOND_GROUP] != null){
161
+ var millisecond = parseInt(match[MILLI_SECOND_GROUP].substring(0, 3));
162
+ if(millisecond >= 1000) return null;
163
+
164
+ result.end.assign('millisecond', millisecond);
165
+ }
166
+
158
167
  // ----- Second
159
168
  if(match[SECOND_GROUP] != null){
160
169
  var second = parseInt(match[SECOND_GROUP]);
@@ -0,0 +1,75 @@
1
+ const dayjs = require('dayjs');
2
+ var Parser = require('../parser').Parser;
3
+ var ParsedResult = require('../../result').ParsedResult;
4
+ var util = require('../../utils/EN');
5
+
6
+ var PATTERN = new RegExp('' +
7
+ /*match[1]*/ '(\\W|^)' +
8
+ /*match[2]*/ '(in )?' +
9
+ /*match[3]*/ '(' + util.TIME_UNIT_PATTERN + ')' +
10
+ /*match[4]*/ '(later|after|from now|henceforth|forward|out)?' +
11
+ /*match[5]*/ '(?=(?:\\W|$))',
12
+ 'i');
13
+
14
+ var STRICT_PATTERN = new RegExp('' +
15
+ /*match[1]*/ '(\\W|^)' +
16
+ /*match[2]*/ '(in )?' +
17
+ /*match[3]*/ '(' + util.TIME_UNIT_STRICT_PATTERN + ')' +
18
+ /*match[4]*/ '(later|from now)?' +
19
+ /*match[5]*/ '(?=(?:\\W|$))',
20
+ 'i');
21
+
22
+ exports.Parser = function ENTimeLaterFormatParser(){
23
+ Parser.apply(this, arguments);
24
+
25
+ this.pattern = function() {
26
+ return this.isStrictMode()? STRICT_PATTERN : PATTERN;
27
+ };
28
+
29
+ this.extract = function(text, ref, match, opt){
30
+ if (match.index > 0 && text[match.index-1].match(/\w/)) return null;
31
+
32
+ var prefix = match[2];
33
+ var suffix = match[4];
34
+ if (!prefix && !suffix) return null;
35
+
36
+ var preamble = match[1];
37
+ var text = match[0].substr(preamble.length, match[0].length - preamble.length);
38
+ var index = match.index + preamble.length;
39
+
40
+ var result = new ParsedResult({
41
+ index: index,
42
+ text: text,
43
+ ref: ref
44
+ });
45
+
46
+ var fragments = util.extractDateTimeUnitFragments(match[3]);
47
+ var date = dayjs(ref);
48
+ for (var key in fragments) {
49
+ date = date.add(fragments[key], key);
50
+ }
51
+
52
+ if (fragments['hour'] > 0 || fragments['minute'] > 0 || fragments['second'] > 0) {
53
+ result.start.assign('hour', date.hour());
54
+ result.start.assign('minute', date.minute());
55
+ result.start.assign('second', date.second());
56
+ result.tags['ENTimeAgoFormatParser'] = true;
57
+ }
58
+
59
+ if (fragments['d'] > 0 || fragments['month'] > 0 || fragments['year'] > 0) {
60
+ result.start.assign('day', date.date());
61
+ result.start.assign('month', date.month() + 1);
62
+ result.start.assign('year', date.year());
63
+ } else {
64
+ if (fragments['week'] > 0) {
65
+ result.start.imply('weekday', date.day());
66
+ }
67
+
68
+ result.start.imply('day', date.date());
69
+ result.start.imply('month', date.month() + 1);
70
+ result.start.imply('year', date.year());
71
+ }
72
+
73
+ return result;
74
+ };
75
+ }
@@ -1,8 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
6
2
  var Parser = require('../parser').Parser;
7
3
  var ParsedResult = require('../../result').ParsedResult;
8
4
 
@@ -25,25 +21,25 @@ var POSTFIX_GROUP = 4;
25
21
 
26
22
  exports.updateParsedComponent = function updateParsedComponent(result, ref, offset, modifier) {
27
23
 
28
- var startMoment = moment(ref);
24
+ var startMoment = dayjs(ref);
29
25
  var startMomentFixed = false;
30
26
  var refOffset = startMoment.day();
31
27
 
32
28
  if(modifier == 'last' || modifier == 'past') {
33
- startMoment.day(offset - 7);
29
+ startMoment =startMoment.day(offset - 7);
34
30
  startMomentFixed = true;
35
31
  } else if(modifier == 'next') {
36
- startMoment.day(offset + 7);
32
+ startMoment = startMoment.day(offset + 7);
37
33
  startMomentFixed = true;
38
34
  } else if(modifier == 'this') {
39
- startMoment.day(offset);
35
+ startMoment = startMoment.day(offset);
40
36
  } else {
41
37
  if (Math.abs(offset - 7 - refOffset) < Math.abs(offset - refOffset)) {
42
- startMoment.day(offset - 7);
38
+ startMoment = startMoment.day(offset - 7);
43
39
  } else if (Math.abs(offset + 7 - refOffset) < Math.abs(offset - refOffset)) {
44
- startMoment.day(offset + 7);
40
+ startMoment = startMoment.day(offset + 7);
45
41
  } else {
46
- startMoment.day(offset);
42
+ startMoment = startMoment.day(offset);
47
43
  }
48
44
  }
49
45
 
@@ -1,9 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
7
2
  var Parser = require('../parser').Parser;
8
3
  var ParsedResult = require('../../result').ParsedResult;
9
4
 
@@ -41,26 +36,26 @@ exports.Parser = function ESCasualDateParser(){
41
36
  ref: ref,
42
37
  });
43
38
 
44
- var refMoment = moment(ref);
45
- var startMoment = refMoment.clone();
39
+ var refMoment = dayjs(ref);
40
+ var startMoment = refMoment;
46
41
  var lowerText = text.toLowerCase().replace(/\s+/g, ' ');
47
42
 
48
43
  if(lowerText == 'mañana'){
49
44
 
50
45
  // Check not "Tomorrow" on late night
51
46
  if(refMoment.hour() > 1) {
52
- startMoment.add(1, 'day');
47
+ startMoment = startMoment.add(1, 'day');
53
48
  }
54
49
 
55
50
  } else if(lowerText == 'ayer') {
56
51
 
57
- startMoment.add(-1, 'day');
52
+ startMoment = startMoment.add(-1, 'day');
58
53
  }
59
54
  else if(lowerText == 'anoche') {
60
55
 
61
56
  result.start.imply('hour', 0);
62
57
  if (refMoment.hour() > 6) {
63
- startMoment.add(-1, 'day');
58
+ startMoment = startMoment.add(-1, 'day');
64
59
  }
65
60
 
66
61
  } else if (lowerText.match("esta")) {
@@ -86,11 +81,11 @@ exports.Parser = function ESCasualDateParser(){
86
81
  var firstMatch = match[4].toLowerCase();
87
82
  if (firstMatch === 'ayer') {
88
83
 
89
- startMoment.add(-1, 'day');
84
+ startMoment = startMoment.add(-1, 'day');
90
85
 
91
86
  } else if (firstMatch === 'mañana') {
92
87
 
93
- startMoment.add(1, 'day');
88
+ startMoment = startMoment.add(1, 'day');
94
89
 
95
90
  }
96
91
 
@@ -1,9 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
7
2
  var Parser = require('../parser').Parser;
8
3
  var ParsedResult = require('../../result').ParsedResult;
9
4
 
@@ -35,10 +30,9 @@ exports.Parser = function ESDeadlineFormatParser(){
35
30
  }
36
31
  }
37
32
 
38
- var date = moment(ref);
33
+ var date = dayjs(ref);
39
34
  if (match[4].match(/d[ií]a/)) {
40
- date.add(num, 'd');
41
-
35
+ date = date.add(num, 'd');
42
36
  result.start.assign('year', date.year());
43
37
  result.start.assign('month', date.month() + 1);
44
38
  result.start.assign('day', date.date());
@@ -48,11 +42,11 @@ exports.Parser = function ESDeadlineFormatParser(){
48
42
 
49
43
  if (match[4].match(/hora/)) {
50
44
 
51
- date.add(num, 'hour');
45
+ date = date.add(num, 'hour');
52
46
 
53
47
  } else if (match[4].match(/minuto/)) {
54
48
 
55
- date.add(num, 'minute');
49
+ date = date.add(num, 'minute');
56
50
  }
57
51
 
58
52
  result.start.imply('year', date.year());
@@ -1,11 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
7
-
8
- var Parser = require('../parser').Parser;
1
+ var parser = require('../parser');
9
2
  var ParsedResult = require('../../result').ParsedResult;
10
3
 
11
4
  var util = require('../../utils/ES');
@@ -16,7 +9,7 @@ var PATTERN = new RegExp('(\\W|^)' +
16
9
  '(?:(Domingo|Lunes|Martes|Miércoles|Miercoles|Jueves|Viernes|Sábado|Sabado|Dom|Lun|Mar|Mie|Jue|Vie|Sab)\\s*,?\\s*)?' +
17
10
  '([0-9]{1,2})(?:º|ª|°)?' +
18
11
  '(?:\\s*(?:desde|de|\\-|\\–|al?|hasta|\\s)\\s*([0-9]{1,2})(?:º|ª|°)?)?\\s*(?:de)?\\s*' +
19
- '(Ene(?:ro|\\.)?|Feb(?:rero|\\.)?|Mar(?:zo|\\.)?|Abr(?:il|\\.)?|May(?:o|\\.)?|Jun(?:io|\\.)?|Jul(?:io|\\.)?|Ago(?:sto|\\.)?|Sep(?:tiembre|\\.)?|Oct(?:ubre|\\.)?|Nov(?:iembre|\\.)?|Dic(?:iembre|\\.)?)' +
12
+ '(Ene(?:ro|\\.)?|Feb(?:rero|\\.)?|Mar(?:zo|\\.)?|Abr(?:il|\\.)?|May(?:o|\\.)?|Jun(?:io|\\.)?|Jul(?:io|\\.)?|Ago(?:sto|\\.)?|Sep(?:tiembre|\\.)?|Set(?:iembre|\\.)?|Oct(?:ubre|\\.)?|Nov(?:iembre|\\.)?|Dic(?:iembre|\\.)?)' +
20
13
  '(?:\\s*(?:del?)?(\\s*[0-9]{1,4}(?![^\\s]\\d))(\\s*[ad]\\.?\\s*c\\.?|a\\.?\\s*d\\.?)?)?' +
21
14
  '(?=\\W|$)', 'i'
22
15
  );
@@ -29,7 +22,7 @@ var YEAR_GROUP = 6;
29
22
  var YEAR_BE_GROUP = 7;
30
23
 
31
24
  exports.Parser = function ESMonthNameLittleEndianParser(){
32
- Parser.apply(this, arguments);
25
+ parser.Parser.apply(this, arguments);
33
26
 
34
27
  this.pattern = function() { return PATTERN; }
35
28
 
@@ -68,25 +61,10 @@ exports.Parser = function ESMonthNameLittleEndianParser(){
68
61
  result.start.assign('month', month);
69
62
  result.start.assign('year', year);
70
63
  } else {
71
-
72
- //Find the most appropriated year
73
- var refMoment = moment(ref);
74
- refMoment.month(month - 1);
75
- refMoment.date(day);
76
- refMoment.year(moment(ref).year());
77
-
78
- var nextYear = refMoment.clone().add(1, 'y');
79
- var lastYear = refMoment.clone().add(-1, 'y');
80
- if( Math.abs(nextYear.diff(moment(ref))) < Math.abs(refMoment.diff(moment(ref))) ){
81
- refMoment = nextYear;
82
- }
83
- else if( Math.abs(lastYear.diff(moment(ref))) < Math.abs(refMoment.diff(moment(ref))) ){
84
- refMoment = lastYear;
85
- }
86
-
64
+ year = parser.findYearClosestToRef(ref, day, month);
87
65
  result.start.assign('day', day);
88
66
  result.start.assign('month', month);
89
- result.start.imply('year', refMoment.year());
67
+ result.start.imply('year', year);
90
68
  }
91
69
 
92
70
  // Weekday component
@@ -105,4 +83,4 @@ exports.Parser = function ESMonthNameLittleEndianParser(){
105
83
  result.tags['ESMonthNameLittleEndianParser'] = true;
106
84
  return result;
107
85
  };
108
- }
86
+ }
@@ -4,7 +4,7 @@
4
4
  - 3/11/2015
5
5
  - 3/11
6
6
  */
7
- var moment = require('moment');
7
+ const dayjs = require('dayjs');
8
8
  var Parser = require('../parser').Parser;
9
9
  var ParsedResult = require('../../result').ParsedResult;
10
10
 
@@ -65,7 +65,7 @@ exports.Parser = function ESSlashDateFormatParser(argument) {
65
65
  if(!match[YEAR_GROUP] && match[0].indexOf('/') < 0) return;
66
66
 
67
67
  var date = null;
68
- var year = match[YEAR_GROUP] || moment(ref).year() + '';
68
+ var year = match[YEAR_GROUP] || dayjs(ref).year() + '';
69
69
  var month = match[MONTH_GROUP];
70
70
  var day = match[DAY_GROUP];
71
71
 
@@ -1,9 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
7
2
  var Parser = require('../parser').Parser;
8
3
  var ParsedResult = require('../../result').ParsedResult;
9
4
 
@@ -39,16 +34,16 @@ exports.Parser = function ESTimeAgoFormatParser(){
39
34
  }
40
35
  }
41
36
 
42
- var date = moment(ref);
37
+ var date = dayjs(ref);
43
38
 
44
39
  if (match[3].match(/hora/) || match[3].match(/minuto/)) {
45
40
  if (match[3].match(/hora/)) {
46
41
 
47
- date.add(-num, 'hour');
42
+ date = date.add(-num, 'hour');
48
43
 
49
44
  } else if (match[3].match(/minuto/)) {
50
45
 
51
- date.add(-num, 'minute');
46
+ date = date.add(-num, 'minute');
52
47
  }
53
48
 
54
49
  result.start.imply('day', date.date());
@@ -61,7 +56,7 @@ exports.Parser = function ESTimeAgoFormatParser(){
61
56
  }
62
57
 
63
58
  if (match[3].match(/semana/)) {
64
- date.add(-num, 'week');
59
+ date = date.add(-num, 'week');
65
60
 
66
61
  result.start.imply('day', date.date());
67
62
  result.start.imply('month', date.month() + 1);
@@ -71,16 +66,16 @@ exports.Parser = function ESTimeAgoFormatParser(){
71
66
  }
72
67
 
73
68
  if (match[3].match(/d[ií]a/)) {
74
- date.add(-num, 'd');
69
+ date = date.add(-num, 'd');
75
70
  }
76
71
 
77
72
  if (match[3].match(/mes/)) {
78
- date.add(-num, 'month');
73
+ date = date.add(-num, 'month');
79
74
  }
80
75
 
81
76
  if (match[3].match(/año/)) {
82
77
 
83
- date.add(-num, 'year');
78
+ date = date.add(-num, 'year');
84
79
  }
85
80
 
86
81
  result.start.assign('day', date.date());
@@ -1,9 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
7
2
  var Parser = require('../parser').Parser;
8
3
  var ParsedResult = require('../../result').ParsedResult;
9
4
  var ParsedComponents = require('../../result').ParsedComponents;
@@ -47,7 +42,7 @@ exports.Parser = function ESTimeExpressionParser(){
47
42
 
48
43
  // This pattern can be overlaped Ex. [12] AM, 1[2] AM
49
44
  if (match.index > 0 && text[match.index-1].match(/\w/)) return null;
50
- var refMoment = moment(ref);
45
+ var refMoment = dayjs(ref);
51
46
  var result = new ParsedResult();
52
47
  result.ref = ref;
53
48
  result.index = match.index + match[1].length;
@@ -1,11 +1,6 @@
1
- /*
2
-
3
-
4
- */
5
- var moment = require('moment');
6
1
  var Parser = require('../parser').Parser;
7
2
  var ParsedResult = require('../../result').ParsedResult;
8
- var updateParsedComponent = require('../EN/ENWeekdayParser').updateParsedComponent;
3
+ var updateParsedComponent = require('../en/ENWeekdayParser').updateParsedComponent;
9
4
 
10
5
  var DAYS_OFFSET = { 'domingo': 0, 'dom': 0, 'lunes': 1, 'lun': 1, 'martes': 2, 'mar':2, 'miercoles': 3, 'miércoles': 3, 'mie': 3,
11
6
  'jueves': 4, 'jue': 4, 'viernes': 5, 'vier': 5, 'sabado': 6, 'sábado': 6, 'sab': 6,}
@@ -1,9 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
7
2
  var Parser = require('../parser').Parser;
8
3
  var ParsedResult = require('../../result').ParsedResult;
9
4
 
@@ -25,19 +20,19 @@ exports.Parser = function FRCasualDateParser(){
25
20
  ref: ref,
26
21
  });
27
22
 
28
- var refMoment = moment(ref);
29
- var startMoment = refMoment.clone();
23
+ var refMoment = dayjs(ref);
24
+ var startMoment = refMoment;
30
25
  var lowerText = text.toLowerCase();
31
26
 
32
27
  if(lowerText.match(/demain/)){
33
28
  // Check not "Tomorrow" on late night
34
29
  if(refMoment.hour() > 1) {
35
- startMoment.add(1, 'day');
30
+ startMoment = startMoment.add(1, 'day');
36
31
  }
37
32
  }
38
33
 
39
34
  if(lowerText.match(/hier/)) {
40
- startMoment.add(-1, 'day');
35
+ startMoment = startMoment.add(-1, 'day');
41
36
  }
42
37
 
43
38
  if(lowerText.match(/cette\s*nuit/)){
@@ -49,7 +44,7 @@ exports.Parser = function FRCasualDateParser(){
49
44
 
50
45
  result.start.imply('hour', 0);
51
46
  if (refMoment.hour() > 6) {
52
- startMoment.add(-1, 'day');
47
+ startMoment = startMoment.add(-1, 'day');
53
48
  }
54
49
 
55
50
  } else if (lowerText.match(/(après-midi|aprem)/)) {
@@ -1,9 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
1
+ const dayjs = require('dayjs');
7
2
  var Parser = require('../parser').Parser;
8
3
  var ParsedResult = require('../../result').ParsedResult;
9
4
  var util = require('../../utils/FR');
@@ -54,17 +49,17 @@ exports.Parser = function FRDeadlineFormatParser(){
54
49
  num = parseInt(num);
55
50
  }
56
51
 
57
- var date = moment(ref);
52
+ var date = dayjs(ref);
58
53
  if (match[4].match(/jour|semaine|mois|année/i)) {
59
54
 
60
55
  if (match[4].match(/jour/)) {
61
- date.add(num, 'd');
56
+ date = date.add(num, 'd');
62
57
  } else if (match[4].match(/semaine/i)) {
63
- date.add(num * 7, 'd');
58
+ date = date.add(num * 7, 'd');
64
59
  } else if (match[4].match(/mois/i)) {
65
- date.add(num, 'month');
60
+ date = date.add(num, 'month');
66
61
  } else if (match[4].match(/année/i)) {
67
- date.add(num, 'year');
62
+ date = date.add(num, 'year');
68
63
  }
69
64
 
70
65
  result.start.assign('year', date.year());
@@ -75,15 +70,15 @@ exports.Parser = function FRDeadlineFormatParser(){
75
70
 
76
71
  if (match[4].match(/heure/i)) {
77
72
 
78
- date.add(num, 'hour');
73
+ date = date.add(num, 'hour');
79
74
 
80
75
  } else if (match[4].match(/min/i)) {
81
76
 
82
- date.add(num, 'minutes');
77
+ date = date.add(num, 'minutes');
83
78
 
84
79
  } else if (match[4].match(/secondes/i)) {
85
80
 
86
- date.add(num, 'second');
81
+ date = date.add(num, 'second');
87
82
  }
88
83
 
89
84
  result.start.imply('year', date.year());
@@ -1,11 +1,4 @@
1
- /*
2
-
3
-
4
- */
5
-
6
- var moment = require('moment');
7
-
8
- var Parser = require('../parser').Parser;
1
+ const parser = require('../parser');
9
2
  var ParsedResult = require('../../result').ParsedResult;
10
3
 
11
4
  var util = require('../../utils/FR');
@@ -29,7 +22,7 @@ var YEAR_GROUP = 6;
29
22
  var YEAR_BE_GROUP = 7;
30
23
 
31
24
  exports.Parser = function FRMonthNameLittleEndianParser(){
32
- Parser.apply(this, arguments);
25
+ parser.Parser.apply(this, arguments);
33
26
 
34
27
  this.pattern = function() { return PATTERN; }
35
28
 
@@ -68,25 +61,10 @@ exports.Parser = function FRMonthNameLittleEndianParser(){
68
61
  result.start.assign('month', month);
69
62
  result.start.assign('year', year);
70
63
  } else {
71
-
72
- // Find the most appropriated year
73
- var refMoment = moment(ref);
74
- refMoment.month(month - 1);
75
- refMoment.date(day);
76
- refMoment.year(moment(ref).year());
77
-
78
- var nextYear = refMoment.clone().add(1, 'y');
79
- var lastYear = refMoment.clone().add(-1, 'y');
80
- if( Math.abs(nextYear.diff(moment(ref))) < Math.abs(refMoment.diff(moment(ref))) ){
81
- refMoment = nextYear;
82
- }
83
- else if( Math.abs(lastYear.diff(moment(ref))) < Math.abs(refMoment.diff(moment(ref))) ){
84
- refMoment = lastYear;
85
- }
86
-
64
+ year = parser.findYearClosestToRef(ref, day, month)
87
65
  result.start.assign('day', day);
88
66
  result.start.assign('month', month);
89
- result.start.imply('year', refMoment.year());
67
+ result.start.imply('year', year);
90
68
  }
91
69
 
92
70
  // Weekday component