chrono-node 1.3.5 → 1.3.11
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 +107 -67
- package/bower.json +1 -1
- package/chrono.js +1249 -1076
- package/chrono.map.json +1 -1
- package/chrono.min.js +101 -101
- package/package.json +11 -15
- package/src/chrono.js +2 -3
- package/src/options.js +3 -3
- package/src/parsers/{DE → de}/DECasualDateParser.js +0 -0
- package/src/parsers/{DE → de}/DEDeadlineFormatParser.js +0 -0
- package/src/parsers/{DE → de}/DEMonthNameLittleEndianParser.js +0 -0
- package/src/parsers/{DE → de}/DEMonthNameParser.js +0 -0
- package/src/parsers/{DE → de}/DESlashDateFormatParser.js +0 -0
- package/src/parsers/{DE → de}/DETimeAgoFormatParser.js +0 -0
- package/src/parsers/{DE → de}/DETimeExpressionParser.js +0 -0
- package/src/parsers/{DE → de}/DEWeekdayParser.js +4 -4
- package/src/parsers/{EN → en}/ENCasualDateParser.js +0 -0
- package/src/parsers/en/ENCasualTimeParser.js +60 -0
- package/src/parsers/{EN → en}/ENDeadlineFormatParser.js +6 -6
- package/src/parsers/{EN → en}/ENISOFormatParser.js +0 -0
- package/src/parsers/{EN → en}/ENMonthNameLittleEndianParser.js +21 -23
- package/src/parsers/{EN → en}/ENMonthNameMiddleEndianParser.js +2 -2
- package/src/parsers/{EN → en}/ENMonthNameParser.js +1 -1
- package/src/parsers/{EN → en}/ENRelativeDateFormatParser.js +40 -2
- package/src/parsers/{EN → en}/ENSlashDateFormatParser.js +5 -1
- package/src/parsers/{EN → en}/ENSlashDateFormatStartWithYearParser.js +8 -2
- package/src/parsers/{EN → en}/ENSlashMonthFormatParser.js +0 -0
- package/src/parsers/en/ENTimeAgoFormatParser.js +69 -0
- package/src/parsers/{EN → en}/ENTimeExpressionParser.js +24 -11
- package/src/parsers/en/ENTimeLaterFormatParser.js +77 -0
- package/src/parsers/{EN → en}/ENWeekdayParser.js +0 -0
- package/src/parsers/{ES → es}/ESCasualDateParser.js +0 -0
- package/src/parsers/{ES → es}/ESDeadlineFormatParser.js +0 -0
- package/src/parsers/{ES → es}/ESMonthNameLittleEndianParser.js +2 -2
- package/src/parsers/{ES → es}/ESSlashDateFormatParser.js +0 -0
- package/src/parsers/{ES → es}/ESTimeAgoFormatParser.js +0 -0
- package/src/parsers/{ES → es}/ESTimeExpressionParser.js +0 -0
- package/src/parsers/{ES → es}/ESWeekdayParser.js +1 -1
- package/src/parsers/{FR → fr}/FRCasualDateParser.js +0 -0
- package/src/parsers/{FR → fr}/FRDeadlineFormatParser.js +0 -0
- package/src/parsers/{FR → fr}/FRMonthNameLittleEndianParser.js +0 -0
- package/src/parsers/{FR → fr}/FRRelativeDateFormatParser.js +0 -0
- package/src/parsers/{FR → fr}/FRSlashDateFormatParser.js +41 -11
- package/src/parsers/{FR → fr}/FRTimeAgoFormatParser.js +0 -0
- package/src/parsers/{FR → fr}/FRTimeExpressionParser.js +0 -0
- package/src/parsers/{FR → fr}/FRWeekdayParser.js +1 -1
- package/src/parsers/{JP → ja}/JPCasualDateParser.js +0 -0
- package/src/parsers/{JP → ja}/JPStandardParser.js +0 -0
- package/src/parsers/parser.js +50 -50
- package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantCasualDateParser.js +18 -2
- package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantDateParser.js +0 -0
- package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantDeadlineFormatParser.js +0 -0
- package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantTimeExpressionParser.js +36 -4
- package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantWeekdayParser.js +1 -1
- package/src/refiners/ExtractTimezoneAbbrRefiner.js +19 -10
- package/src/refiners/ForwardDateRefiner.js +1 -1
- package/src/refiners/{DE → de}/DEMergeDateRangeRefiner.js +1 -1
- package/src/refiners/{DE → de}/DEMergeDateTimeRefiner.js +3 -3
- package/src/refiners/{EN → en}/ENMergeDateRangeRefiner.js +0 -0
- package/src/refiners/{EN → en}/ENMergeDateTimeRefiner.js +15 -2
- package/src/refiners/{EN → en}/ENMergeWeekdayRefiner.js +0 -0
- package/src/refiners/{EN → en}/ENPrioritizeSpecificDateRefiner.js +0 -0
- package/src/refiners/{FR → fr}/FRMergeDateRangeRefiner.js +0 -0
- package/src/refiners/{FR → fr}/FRMergeDateTimeRefiner.js +1 -1
- package/src/refiners/{JP → ja}/JPMergeDateRangeRefiner.js +1 -1
- package/src/refiners/refiner.js +12 -12
- package/src/result.js +3 -1
- package/src/timezone.js +2 -0
- package/src/utils/EN.js +68 -2
- package/test/de/de.test.js +51 -0
- package/test/de/de_casual.test.js +432 -0
- package/test/de/de_dash.test.js +6 -0
- package/test/de/de_deadline.test.js +244 -0
- package/test/de/de_little_endian.test.js +459 -0
- package/test/de/de_time_ago.test.js +313 -0
- package/test/de/de_time_exp.test.js +166 -0
- package/test/de/de_weekday.test.js +235 -0
- package/test/en/en.test.js +250 -0
- package/test/en/en_casual.test.js +461 -0
- package/test/en/en_dash.test.js +31 -0
- package/test/en/en_deadline.test.js +366 -0
- package/test/{test_example.js → en/en_example.test.js} +7 -18
- package/test/en/en_inter_std.test.js +269 -0
- package/test/en/en_little_endian.test.js +566 -0
- package/test/en/en_middle_endian.test.js +552 -0
- package/test/en/en_month.test.js +113 -0
- package/test/en/en_option_forward.test.js +156 -0
- package/test/en/en_relative.test.js +228 -0
- package/test/en/en_slash.test.js +450 -0
- package/test/en/en_time_ago.test.js +374 -0
- package/test/en/en_time_exp.test.js +722 -0
- package/test/en/en_time_from_now.test.js +371 -0
- package/test/en/en_time_later.test.js +95 -0
- package/test/en/en_weekday.test.js +301 -0
- package/test/es/es_casual.test.js +258 -0
- package/test/es/es_dash.test.js +13 -0
- package/test/es/es_deadline.test.js +85 -0
- package/test/es/es_little_endian.test.js +350 -0
- package/test/es/es_slash.test.js +24 -0
- package/test/es/es_time_ago.test.js +137 -0
- package/test/es/es_time_exp.test.js +240 -0
- package/test/fr/fr_casual.test.js +454 -0
- package/test/fr/fr_dash.test.js +26 -0
- package/test/fr/fr_deadline.test.js +244 -0
- package/test/fr/fr_little_endian.test.js +576 -0
- package/test/fr/fr_relative.test.js +198 -0
- package/test/fr/fr_slash.test.js +62 -0
- package/test/fr/fr_time_ago.test.js +194 -0
- package/test/fr/fr_time_exp.test.js +960 -0
- package/test/fr/fr_weekday.test.js +200 -0
- package/test/ja/ja_casual.test.js +51 -0
- package/test/ja/ja_standard.test.js +170 -0
- package/test/system.test.js +207 -0
- package/test/zh/zh_hant_casual.test.js +340 -0
- package/test/zh/zh_hant_date.test.js +118 -0
- package/test/zh/zh_hant_deadline.test.js +213 -0
- package/test/zh/zh_hant_time_exp.test.js +226 -0
- package/test/zh/zh_hant_weekday.test.js +160 -0
- package/.npmignore +0 -11
- package/src/parsers/EN/ENCasualTimeParser.js +0 -53
- package/src/parsers/EN/ENTimeAgoFormatParser.js +0 -130
- package/src/parsers/EN/ENTimeFromNowFormatParser.js +0 -119
- package/test/test_de.js +0 -62
- package/test/test_de_casual.js +0 -443
- package/test/test_de_dash.js +0 -17
- package/test/test_de_deadline.js +0 -255
- package/test/test_de_little_endian.js +0 -470
- package/test/test_de_time_ago.js +0 -324
- package/test/test_de_time_exp.js +0 -177
- package/test/test_de_weekday.js +0 -246
- package/test/test_en.js +0 -249
- package/test/test_en_casual.js +0 -448
- package/test/test_en_dash.js +0 -42
- package/test/test_en_deadline.js +0 -311
- package/test/test_en_inter_std.js +0 -272
- package/test/test_en_little_endian.js +0 -529
- package/test/test_en_middle_endian.js +0 -563
- package/test/test_en_month.js +0 -124
- package/test/test_en_option_forward.js +0 -167
- package/test/test_en_relative.js +0 -206
- package/test/test_en_slash.js +0 -370
- package/test/test_en_time_ago.js +0 -385
- package/test/test_en_time_exp.js +0 -663
- package/test/test_en_time_from_now.js +0 -345
- package/test/test_en_weekday.js +0 -312
- package/test/test_es_casual.js +0 -269
- package/test/test_es_dash.js +0 -24
- package/test/test_es_deadline.js +0 -96
- package/test/test_es_little_endian.js +0 -361
- package/test/test_es_slash.js +0 -35
- package/test/test_es_time_ago.js +0 -148
- package/test/test_es_time_exp.js +0 -251
- package/test/test_fr_casual.js +0 -465
- package/test/test_fr_dash.js +0 -37
- package/test/test_fr_deadline.js +0 -255
- package/test/test_fr_little_endian.js +0 -568
- package/test/test_fr_relative.js +0 -209
- package/test/test_fr_slash.js +0 -54
- package/test/test_fr_time_ago.js +0 -205
- package/test/test_fr_time_exp.js +0 -971
- package/test/test_fr_weekday.js +0 -211
- package/test/test_jp_casual.js +0 -62
- package/test/test_jp_standard.js +0 -181
- package/test/test_system.js +0 -178
- package/test/test_zh_hant_casual.js +0 -329
- package/test/test_zh_hant_date.js +0 -129
- package/test/test_zh_hant_deadline.js +0 -224
- package/test/test_zh_hant_time_exp.js +0 -210
- package/test/test_zh_hant_weekday.js +0 -171
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Chrono
|
|
2
|
-
|
|
1
|
+
# Chrono
|
|
2
|
+
|
|
3
3
|
A natural language date parser in Javascript, designed for extracting date information from any given text. (Java version is also available [here](https://github.com/wanasit/chrono-java))
|
|
4
4
|
|
|
5
5
|
[](https://travis-ci.org/wanasit/chrono)
|
|
@@ -20,27 +20,29 @@ Chrono supports most date and time formats, such as :
|
|
|
20
20
|
#### npm (recommended)
|
|
21
21
|
|
|
22
22
|
Just run:
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
```bash
|
|
24
|
+
$ npm i --save chrono-node
|
|
25
|
+
```
|
|
25
26
|
|
|
26
27
|
And start using chrono:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
```js
|
|
29
|
+
var chrono = require('chrono-node');
|
|
30
|
+
chrono.parseDate('An appointment on Sep 12-13');
|
|
31
|
+
```
|
|
30
32
|
|
|
31
33
|
#### Bower
|
|
32
34
|
|
|
33
35
|
Prefer bower? You can do that, too:
|
|
34
36
|
|
|
35
37
|
Just run:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
```bash
|
|
39
|
+
$ bower install chrono
|
|
40
|
+
```
|
|
39
41
|
And use:
|
|
40
42
|
|
|
41
43
|
```html
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
<script src="bower_components/chrono/chrono.min.js"></script>
|
|
45
|
+
<script>chrono.parseDate('An appointment on Sep 12-13')</script>
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
|
|
@@ -50,7 +52,7 @@ Doing something else? No worries. Try these:
|
|
|
50
52
|
|
|
51
53
|
Platform | Installation
|
|
52
54
|
---------|----
|
|
53
|
-
CDN | Via [jsDelivr]:<br> `<script src="https://cdn.jsdelivr.net/chrono
|
|
55
|
+
CDN | Via [jsDelivr]:<br> `<script src="https://cdn.jsdelivr.net/npm/chrono-node@VERSION/chrono.min.js"></script>`
|
|
54
56
|
Rails | Install from [Rails Assets] by adding this to your Gemfile:<br> `gem 'rails-assets-chrono', source: 'https://rails-assets.org'`
|
|
55
57
|
Swift | Try using the community-made [chrono-swift] wrapper.
|
|
56
58
|
|
|
@@ -62,22 +64,22 @@ Swift | Try using the community-made [chrono-swift] wrapper.
|
|
|
62
64
|
|
|
63
65
|
Chrono's modules are linked and packaged using [Browserify](http://browserify.org) on `src/chrono.js`. By default, `chrono.js` file exports `chrono` object as a window global.
|
|
64
66
|
|
|
65
|
-
```
|
|
66
|
-
browserify src/chrono.js --s chrono -o chrono.js
|
|
67
|
+
```bash
|
|
68
|
+
$ browserify src/chrono.js --s chrono -o chrono.js
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
## Usage
|
|
70
72
|
|
|
71
73
|
Simply pass a string to function `chrono.parseDate` or `chrono.parse`.
|
|
72
74
|
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
+
```js
|
|
76
|
+
var chrono = require('chrono-node');
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
|
|
78
|
+
chrono.parseDate('An appointment on Sep 12-13');
|
|
79
|
+
// Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
[ { index: 18,
|
|
81
|
+
chrono.parse('An appointment on Sep 12-13');
|
|
82
|
+
/* [ { index: 18,
|
|
81
83
|
text: 'Sep 12-13',
|
|
82
84
|
tags: { ENMonthNameMiddleEndianParser: true },
|
|
83
85
|
start:
|
|
@@ -85,7 +87,7 @@ Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
|
|
|
85
87
|
impliedValues: [Object] },
|
|
86
88
|
end:
|
|
87
89
|
{ knownValues: [Object],
|
|
88
|
-
impliedValues: [Object] } } ]
|
|
90
|
+
impliedValues: [Object] } } ] */
|
|
89
91
|
```
|
|
90
92
|
|
|
91
93
|
### Reference Date
|
|
@@ -94,28 +96,52 @@ Today's "Friday" is different from last month's "Friday".
|
|
|
94
96
|
The meaning of the referenced dates depends on when they are mentioned.
|
|
95
97
|
Chrono lets you define a reference date using `chrono.parse(text, ref)` and `chrono.parseDate(text, ref)`.
|
|
96
98
|
|
|
97
|
-
```
|
|
99
|
+
```js
|
|
100
|
+
chrono.parseDate('Friday', new Date(2012, 7, 23));
|
|
101
|
+
// Fri Aug 24 2012 12:00:00 GMT+0700 (ICT)
|
|
102
|
+
|
|
103
|
+
chrono.parseDate('Friday', new Date(2012, 7, 1));
|
|
104
|
+
// Fri Aug 03 2012 12:00:00 GMT+0700 (ICT)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Parsing Options
|
|
108
|
+
|
|
109
|
+
* `forwardDate` (boolean) to assume the results should happen after the reference date (forward into the future)
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
var referenceDate = new Date(2012, 7, 25);
|
|
113
|
+
// Sat Aug 25 2012 00:00:00 GMT+0900 -- The reference date was Saturday
|
|
114
|
+
|
|
115
|
+
chrono.parseDate('Friday', referenceDate);
|
|
116
|
+
// Fri Aug 24 2012 12:00:00 GMT+0900 (JST) -- The day before was Friday
|
|
117
|
+
|
|
118
|
+
chrono.parseDate('Friday', referenceDate, { forwardDate: true });
|
|
119
|
+
// Fri Aug 31 2012 12:00:00 GMT+0900 (JST) -- The following Friday
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
* `timezones` (Map) to override Chrono's default timezone abbriviation mapping. The value should be the timezone offset in minutes (between -720 to 720).
|
|
98
123
|
|
|
99
|
-
|
|
100
|
-
|
|
124
|
+
```js
|
|
125
|
+
chrono.parse('Friday at 2 pm IST', refDate, { 'IST': 330 })[0].start.get('timezoneOffset');
|
|
126
|
+
// 330 (IST – India Standard Time +0530)
|
|
101
127
|
|
|
102
|
-
|
|
103
|
-
|
|
128
|
+
chrono.parse('Friday at 2 pm IST', refDate, { 'IST': 60 })[0].start.get('timezoneOffset');
|
|
129
|
+
// 60 (IST - Irish Standard Time +0100)
|
|
104
130
|
```
|
|
105
131
|
|
|
106
132
|
### Detailed Parsed Results
|
|
107
133
|
|
|
108
134
|
The function `chrono.parse` returns detailed parsing results as objects of class `chrono.ParsedResult`.
|
|
109
135
|
|
|
110
|
-
```
|
|
111
|
-
var results = chrono.parse('I have an appointment tomorrow from 10 to 11 AM')
|
|
136
|
+
```js
|
|
137
|
+
var results = chrono.parse('I have an appointment tomorrow from 10 to 11 AM');
|
|
112
138
|
|
|
113
|
-
results[0].index // 15
|
|
114
|
-
results[0].text // 'tomorrow from 10 to 11 AM'
|
|
115
|
-
results[0].ref // Sat Dec 13 2014 21:50:14 GMT-0600 (CST)
|
|
139
|
+
results[0].index; // 15
|
|
140
|
+
results[0].text; // 'tomorrow from 10 to 11 AM'
|
|
141
|
+
results[0].ref; // Sat Dec 13 2014 21:50:14 GMT-0600 (CST)
|
|
116
142
|
|
|
117
|
-
results[0].start.date() // Sun Dec 14 2014 10:00:00 GMT-0600 (CST)
|
|
118
|
-
results[0].end.date() // Sun Dec 14 2014 11:00:00 GMT-0600 (CST)
|
|
143
|
+
results[0].start.date(); // Sun Dec 14 2014 10:00:00 GMT-0600 (CST)
|
|
144
|
+
results[0].end.date(); // Sun Dec 14 2014 11:00:00 GMT-0600 (CST)
|
|
119
145
|
```
|
|
120
146
|
|
|
121
147
|
#### ParsedResult
|
|
@@ -136,20 +162,20 @@ A group of found date and time components (year, month, hour, etc). ParsedCompon
|
|
|
136
162
|
* `isCertain(component)` return true if the value of the component is known.
|
|
137
163
|
* `date()` Create a javascript Date
|
|
138
164
|
|
|
139
|
-
```
|
|
165
|
+
```js
|
|
140
166
|
// Remove the timezone offset of a parsed date and then create the Date object
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
'Tue Mar 08 2016 01:16:07 GMT+0000 (GMT)'
|
|
167
|
+
var results = new chrono.parse('2016-03-08T01:16:07+02:00'); // Create new ParsedResult Object
|
|
168
|
+
results[0].start.assign('timezoneOffset', 0); // Change value in ParsedComponents Object 'start'
|
|
169
|
+
|
|
170
|
+
var d = results[0].start.date(); // Create a Date object
|
|
171
|
+
d.toString(); // 'Tue Mar 08 2016 01:16:07 GMT+0000 (GMT)'
|
|
146
172
|
```
|
|
147
173
|
|
|
148
174
|
### Strict vs Casual
|
|
149
175
|
|
|
150
176
|
Chrono comes with `strict` mode that parse only formal date patterns.
|
|
151
177
|
|
|
152
|
-
```
|
|
178
|
+
```js
|
|
153
179
|
// 'strict' mode
|
|
154
180
|
chrono.strict.parseDate('Today'); // null
|
|
155
181
|
chrono.strict.parseDate('Friday'); // null
|
|
@@ -159,10 +185,27 @@ chrono.strict.parseDate('Jul 01 2016'); // Fri Jul 01 2016 12:00:00 ...
|
|
|
159
185
|
// 'casual' mode (default)
|
|
160
186
|
chrono.parseDate('Today'); // Thu Jun 30 2016 12:00:00 ...
|
|
161
187
|
chrono.casual.parseDate('Friday'); // Fri Jul 01 2016 12:00:00 ...
|
|
188
|
+
chrono.casual.parseDate('2016-07-01'); // Fri Jul 01 2016 12:00:00 ...
|
|
162
189
|
chrono.casual.parseDate('Jul 01 2016'); // Fri Jul 01 2016 12:00:00 ...
|
|
163
|
-
chrono.casual.parseDate('Friday'); // Fri Jul 01 2016 12:00:00 ...
|
|
164
190
|
```
|
|
165
191
|
|
|
192
|
+
### Choosing Locale
|
|
193
|
+
|
|
194
|
+
By default, Chrono is configurated to parse different date formats from muliple languages out-off-box. However, by using predefined locale options, you can increase parsing accuracy.
|
|
195
|
+
|
|
196
|
+
Handling different date format for UK / US is a good example.
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
// default English (US)
|
|
200
|
+
chrono.parseDate('6/10/2018'); // Sun Jun 10 2018 12:00:00 ...
|
|
201
|
+
chrono.en.parseDate('6/10/2018'); // Sun Jun 10 2018 12:00:00 ...
|
|
202
|
+
|
|
203
|
+
// UK English or German
|
|
204
|
+
chrono.en_GB.parseDate('6/10/2018'); // Sat Oct 06 2018 12:00:00 ...
|
|
205
|
+
chrono.de.parseDate('6/10/2018'); // Sat Oct 06 2018 12:00:00 ...
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Current supported locale options are: `en`, `en_GB`, `de`, `es`, `fr`, `ja`
|
|
166
209
|
|
|
167
210
|
## Customize Chrono
|
|
168
211
|
|
|
@@ -172,11 +215,11 @@ Chrono’s extraction pipeline are mainly separated into 'parse' and ‘refine
|
|
|
172
215
|
|
|
173
216
|
Parser is a module for low-level pattern-based parsing. Ideally, each parser should be designed to handle a single specific date format. User can add new type of parsers for supporting new date formats or languages.
|
|
174
217
|
|
|
175
|
-
```
|
|
218
|
+
```js
|
|
176
219
|
var christmasParser = new chrono.Parser();
|
|
177
220
|
|
|
178
221
|
// Provide search pattern
|
|
179
|
-
christmasParser.pattern = function () { return /Christmas/i }
|
|
222
|
+
christmasParser.pattern = function () { return /Christmas/i; };
|
|
180
223
|
|
|
181
224
|
// This function will be called when matched pattern is found
|
|
182
225
|
christmasParser.extract = function(text, ref, match, opt) {
|
|
@@ -191,7 +234,7 @@ christmasParser.extract = function(text, ref, match, opt) {
|
|
|
191
234
|
month: 12,
|
|
192
235
|
}
|
|
193
236
|
});
|
|
194
|
-
}
|
|
237
|
+
};
|
|
195
238
|
|
|
196
239
|
// Create a new custom Chrono. The initial pipeline 'option' can also be specified as
|
|
197
240
|
// - new chrono.Chrono(exports.options.strictOption())
|
|
@@ -199,7 +242,7 @@ christmasParser.extract = function(text, ref, match, opt) {
|
|
|
199
242
|
var custom = new chrono.Chrono();
|
|
200
243
|
custom.parsers.push(christmasParser);
|
|
201
244
|
|
|
202
|
-
custom.parseDate("I'll arrive at 2.30AM on Christmas night")
|
|
245
|
+
custom.parseDate("I'll arrive at 2.30AM on Christmas night");
|
|
203
246
|
// Wed Dec 25 2013 02:30:00 GMT+0900 (JST)
|
|
204
247
|
|
|
205
248
|
```
|
|
@@ -213,21 +256,21 @@ To create a custom parser, override `pattern` and `extract` methods on an object
|
|
|
213
256
|
|
|
214
257
|
Refiner is a higher level module for improving or manipulating the results. User can add a new type of refiner to customize Chrono's results or to add some custom logic to Chrono.
|
|
215
258
|
|
|
216
|
-
```
|
|
259
|
+
```js
|
|
217
260
|
var guessPMRefiner = new chrono.Refiner();
|
|
218
261
|
guessPMRefiner.refine = function(text, results, opt) {
|
|
219
262
|
// If there is no AM/PM (meridiem) specified,
|
|
220
263
|
// let all time between 1:00 - 4:00 be PM (13.00 - 16.00)
|
|
221
264
|
results.forEach(function (result) {
|
|
222
|
-
if (!result.start.isCertain('meridiem')
|
|
223
|
-
|
|
265
|
+
if (!result.start.isCertain('meridiem') &&
|
|
266
|
+
result.start.get('hour') >= 1 && result.start.get('hour') < 4) {
|
|
224
267
|
|
|
225
268
|
result.start.assign('meridiem', 1);
|
|
226
269
|
result.start.assign('hour', result.start.get('hour') + 12);
|
|
227
270
|
}
|
|
228
271
|
});
|
|
229
272
|
return results;
|
|
230
|
-
}
|
|
273
|
+
};
|
|
231
274
|
|
|
232
275
|
// Create a new custom Chrono. The initial pipeline 'option' can also be specified as
|
|
233
276
|
// - new chrono.Chrono(exports.options.strictOption())
|
|
@@ -253,30 +296,27 @@ This guide explains how to setup chrono project for prospective contributors.
|
|
|
253
296
|
|
|
254
297
|
```bash
|
|
255
298
|
# Clone and install library
|
|
256
|
-
git clone https://github.com/wanasit/chrono.git chrono
|
|
257
|
-
cd chrono
|
|
258
|
-
npm install
|
|
299
|
+
$ git clone https://github.com/wanasit/chrono.git chrono
|
|
300
|
+
$ cd chrono
|
|
301
|
+
$ npm install
|
|
259
302
|
|
|
260
|
-
# Try running the test
|
|
261
|
-
npm run test
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Chrono's source files is in `src` directory. The built bundle (`chrono.js` and `chrono.min.js`) can be built by [Browserify](http://browserify.org) on `src/chrono.js` using the following command
|
|
265
|
-
|
|
266
|
-
```
|
|
267
|
-
npm run make
|
|
268
303
|
```
|
|
269
304
|
|
|
270
305
|
Parsing date from text is complicated. Sometimes, a small change can have effects on unexpected places. So, Chrono is a heavily tested library. Commits that break a test shouldn't be allowed in any condition.
|
|
271
306
|
|
|
272
|
-
Chrono's unit testing is based-on [
|
|
307
|
+
Chrono's unit testing is based-on [Jest](https://facebook.github.io/jest/).
|
|
273
308
|
|
|
274
|
-
```
|
|
275
|
-
#
|
|
276
|
-
npm run
|
|
309
|
+
```bash
|
|
310
|
+
# Run the test
|
|
311
|
+
$ npm run test
|
|
277
312
|
|
|
278
|
-
#
|
|
279
|
-
npm run watch
|
|
313
|
+
# Run the test in watch mode
|
|
314
|
+
$ npm run watch
|
|
280
315
|
```
|
|
281
316
|
|
|
317
|
+
Chrono's source files is in `src` directory. The built bundle (`chrono.js` and `chrono.min.js`) can be built by [Browserify](http://browserify.org) on `src/chrono.js` using the following command
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
$ npm run make
|
|
321
|
+
```
|
|
282
322
|
|