date-and-time 0.10.0 → 0.11.0

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/PLUGINS.md CHANGED
@@ -106,12 +106,12 @@ Tokens in this library have the following rules:
106
106
  'Eee' // Not good
107
107
  ```
108
108
 
109
- - It is not able to add new alphabet's token to the parser.
109
+ - To the parser, it is not able to add new alphabet's token.
110
110
 
111
111
  ```javascript
112
112
  'EEE' // This is not able to add.
113
113
  'YYY' // This is OK because a `Y` token is existing in the parser.
114
- 'SSS' // This is modifying, not adding because the same token is existing.
114
+ 'SSS' // This is modifying, not adding. Because the same token is existing.
115
115
  ```
116
116
 
117
117
  ### Example 1
@@ -187,4 +187,21 @@ This is the above `ordinal` plugin. This plugin adds `DDD` token to return ordin
187
187
  })(this);
188
188
  ```
189
189
 
190
- ### WIP
190
+ ---
191
+
192
+ ## Direct Replacement
193
+
194
+ All you are enough to change a bit the default behavior of this library? You are not going to write a plugin? Of course, you could replace the default behavior directly like this:
195
+
196
+ ```javascript
197
+ date.format(new Date(), 'hh:mm A'); // => 11:20 p.m.
198
+
199
+ // Replace the words that a.m./p.m. to AM/PM.
200
+ date.extend({ res: { A: ['AM', 'PM'] } });
201
+
202
+ date.format(new Date(), 'hh:mm A'); // => 11:20 PM
203
+ ```
204
+
205
+ ### Hint
206
+
207
+ The `extend()` can be regarded as an unnamed `plugin()`.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Circle CI](https://circleci.com/gh/knowledgecode/date-and-time.svg?style=shield)](https://circleci.com/gh/knowledgecode/date-and-time)
4
4
 
5
- This library is just a function collection for manipulating JS date and time. It's tiny, simple, easy to learn.
5
+ This library is a minimalist collection of functions for manipulating JS date and time. It's tiny, simple, easy to learn.
6
6
 
7
7
  ## Why
8
8
 
@@ -11,9 +11,9 @@ JS modules nowadays are getting more huge and complex, and there are also many d
11
11
  ## Features
12
12
 
13
13
  - Minimalist. Less than 2k. (minified and gzipped)
14
- - Universal / Isomorphic. Wherever JS runtime works.
14
+ - Extensible. Plugin system support.
15
15
  - Multi language support.
16
- - Not extending built-in Date object.
16
+ - Universal / Isomorphic. Wherever JS runtime works.
17
17
  - Older browser support. Even works on IE6. :)
18
18
 
19
19
  ## Install
@@ -32,6 +32,31 @@ npm install date-and-time --save
32
32
 
33
33
  ## Recent Changes
34
34
 
35
+ - 0.11.0
36
+ - Added a `compile()` function that precompiling a date string for the parser. In case of processing many date string with one format, by using this function, you could be able to get results faster than before.
37
+
38
+ ```javascript
39
+ // We have passed a string format at the 2nd parameter every time when calling the parse() function.
40
+ date.parse('Mar. 22 2019 2:54:21 p.m.', 'MMM. D YYYY h:m:s A');
41
+ date.parse('Jul. 27 2019 4:15:24 a.m.', 'MMM. D YYYY h:m:s A');
42
+ date.parse('Dec. 25 2019 3:51:11 a.m.', 'MMM. D YYYY h:m:s A');
43
+
44
+ // You can precompile the string format.
45
+ const pattern = date.compile('MMM. D YYYY h:m:s A');
46
+
47
+ // The parse() will be able to finish faster than passing the format string every time.
48
+ date.parse('Mar. 22 2019 2:54:21 p.m.', pattern);
49
+ date.parse('Jul. 27 2019 4:15:24 a.m.', pattern);
50
+ date.parse('Dec. 25 2019 3:51:11 a.m.', pattern);
51
+ ```
52
+
53
+ ```javascript
54
+ const pattern = date.compile('MMM. D YYYY h:m:s A');
55
+
56
+ // The isValid() will also too.
57
+ date.isValid('Mar. 22 2019 2:54:21 p.m.', pattern);
58
+ ```
59
+
35
60
  - 0.10.0
36
61
  - The `YYYY` token has come to require 4 digits in the `parse()`, the `preparse()` and the `isValid()` (**Breaking Change**).
37
62
 
@@ -50,8 +75,8 @@ npm install date-and-time --save
50
75
  - Added a `Y` token to support year, 4 or less digits in the above functions. This new token, `Y` is equivalent to the previous `YYYY` token.
51
76
 
52
77
  ```javascript
53
- date.parse('31-12-123', 'DD-MM-Y'); // good
54
- date.parse('31-12-3', 'DD-MM-Y'); // good
78
+ date.parse('31-12-123', 'DD-MM-Y'); // Good
79
+ date.parse('31-12-3', 'DD-MM-Y'); // Good
55
80
  ```
56
81
 
57
82
  - 0.9.0 (Locale Update)
@@ -163,11 +188,29 @@ You could also define your own tokens. See [PLUGINS.md](./PLUGINS.md) for detail
163
188
 
164
189
  ---
165
190
 
166
- ### parse(dateString, formatString[, utc])
191
+ ### compile(formatString)
192
+
193
+ - Compiling a format string for the parser.
194
+ - @param {**string**} formatString - a format string
195
+ - @returns {**Array.\<string\>**} a compiled object
196
+
197
+ ```javascript
198
+ const pattern = date.compile('MMM. D YYYY h:m:s A');
199
+
200
+ date.parse('Mar. 22 2019 2:54:21 p.m.', pattern);
201
+ date.parse('Jul. 27 2019 4:15:24 a.m.', pattern);
202
+ date.parse('Dec. 25 2019 3:51:11 a.m.', pattern);
203
+ ```
204
+
205
+ If you are going to call the `parse()` or the `isValid()` many times with one string format, recommended to precompile and reuse it for performance.
206
+
207
+ ---
208
+
209
+ ### parse(dateString, arg[, utc])
167
210
 
168
211
  - Parsing a date string.
169
212
  - @param {**string**} dateString - a date string
170
- - @param {**string**} formatString - a format string
213
+ - @param {**string|Array.\<string\>**} arg - a format string or a compiled object
171
214
  - @param {**boolean**} [utc] - input as UTC
172
215
  - @returns {**Date**} a constructed date
173
216
 
@@ -291,11 +334,11 @@ date.parse('12 hours 34 minutes', 'HH mm '); // => Jan. 1 1970 12
291
334
 
292
335
  ---
293
336
 
294
- ### preparse(dateString, formatString)
337
+ ### preparse(dateString, arg)
295
338
 
296
339
  - Pre-parsing a date string.
297
340
  - @param {**string**} dateString - a date string
298
- - @param {**string**} formatString - a format string
341
+ - @param {**string|Array.\<string\>**} arg - a format string or a compiled object
299
342
  - @returns {**Object**} a date structure
300
343
 
301
344
  This function takes exactly the same parameters with the `parse()`, but returns a date structure as follows unlike it:
@@ -319,15 +362,15 @@ date.preparse('2015/01/02 23:14:05', 'YYYY/MM/DD HH:mm:ss');
319
362
  }
320
363
  ```
321
364
 
322
- This object shows a parsing result. You will be able to tell from it how the date string was parsed(, or why the parsing was failed).
365
+ This object shows a parsing result. You would be able to tell from it how the date string was parsed(, or why the parsing was failed).
323
366
 
324
367
  ---
325
368
 
326
- ### isValid(arg[, formatString])
369
+ ### isValid(arg1[, arg2])
327
370
 
328
371
  - Validation.
329
- - @param {**Object**|**string**} arg - a date structure or a date string
330
- - @param {**string**} [formatString] - a format string
372
+ - @param {**Object|string**} arg1 - a date structure or a date string
373
+ - @param {**string|Array.\<string\>**} [arg2] - a format string or a compiled object
331
374
  - @returns {**boolean**} whether the date string is a valid date
332
375
 
333
376
  This function takes either exactly the same parameters with the `parse()` or a date structure which the `preparse()` returns, evaluates the validity of them.
@@ -0,0 +1,40 @@
1
+ const date = require('../date-and-time');
2
+ const rand = (min, max) => ((Math.random() * (max - min) + min) | 0);
3
+ const M = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4
+ const A = ['a.m.', 'p.m.'];
5
+ const dateString = [];
6
+ const formatString = 'MMM. D YYYY h:m:s A';
7
+ const cnt = 6553500;
8
+
9
+ console.log('Creating a list of random date string...');
10
+
11
+ for (let i = 0; i < cnt; i++) {
12
+ const month = M[rand(0, 12)];
13
+ const day = '' + rand(1, 29);
14
+ const year = '' + rand(2000, 2020);
15
+ const hour = '' + rand(0, 12);
16
+ const minute = '' + rand(0, 60);
17
+ const sec = '' + rand(0, 60);
18
+ const ampm = A[rand(0, 2)];
19
+ dateString.push(`${month}. ${day} ${year} ${hour}:${minute}:${sec} ${ampm}`);
20
+ }
21
+
22
+ console.log('Starting the benchmark.\n');
23
+ let start = Date.now();
24
+
25
+ for (let i = 0; i < cnt; i++) {
26
+ date.parse(dateString[i], formatString);
27
+ }
28
+
29
+ const bench1 = Date.now() - start;
30
+ console.log(`parse() only: ${bench1}ms`);
31
+
32
+ start = Date.now();
33
+ const pattern = date.compile(formatString);
34
+
35
+ for (let i = 0; i < cnt; i++) {
36
+ date.parse(dateString[i], pattern);
37
+ }
38
+
39
+ const bench2 = Date.now() - start;
40
+ console.log(`compile() + parse(): ${bench2}ms (${Math.round(bench2 / bench1 * 100)}%)`);
package/date-and-time.js CHANGED
@@ -153,23 +153,36 @@
153
153
  };
154
154
 
155
155
  /**
156
- * pre-parsing a date string
157
- * @param {string} dateString - a date string
156
+ * compiling a format string for the parser
158
157
  * @param {string} formatString - a format string
159
- * @returns {Object} a date structure
158
+ * @returns {Array.<string>} a compiled object
160
159
  */
161
- date.preparse = function (dateString, formatString) {
162
- var parser = locales[lang].parser,
163
- re = /([A-Za-z])\1*|./g,
164
- keys, token, result, offset = 0,
165
- dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, _index: 0, _length: 0, _match: 0 };
160
+ date.compile = function (formatString) {
161
+ var re = /([A-Za-z])\1*|./g, keys, pattern = [formatString];
166
162
 
167
- dateString = parser.pre(dateString);
168
163
  formatString = formatString.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]/g, function (str) {
169
164
  return str.replace(/./g, ' ').slice(2);
170
165
  });
171
166
  while ((keys = re.exec(formatString))) {
172
- token = keys[0];
167
+ pattern[pattern.length] = keys[0];
168
+ }
169
+ return pattern;
170
+ };
171
+
172
+ /**
173
+ * pre-parsing a date string
174
+ * @param {string} dateString - a date string
175
+ * @param {string|Array.<string>} arg - a format string or a compiled object
176
+ * @returns {Object} a date structure
177
+ */
178
+ date.preparse = function (dateString, arg) {
179
+ var parser = locales[lang].parser, token, result, offset = 0,
180
+ pattern = typeof arg === 'string' ? date.compile(arg) : arg, formatString = pattern[0],
181
+ dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, _index: 0, _length: 0, _match: 0 };
182
+
183
+ dateString = parser.pre(dateString);
184
+ for (var i = 1, len = pattern.length; i < len; i++) {
185
+ token = pattern[i];
173
186
  if (parser[token]) {
174
187
  result = parser[token](dateString.slice(offset), formatString);
175
188
  if (!result.length) {
@@ -192,12 +205,12 @@
192
205
 
193
206
  /**
194
207
  * validation
195
- * @param {Object|string} arg - a date structure or a date string
196
- * @param {string} [formatString] - a format string
208
+ * @param {Object|string} arg1 - a date structure or a date string
209
+ * @param {string|Array.<string>} [arg2] - a format string or a compiled object
197
210
  * @returns {boolean} whether the date string is a valid date
198
211
  */
199
- date.isValid = function (arg, formatString) {
200
- var dt = typeof arg === 'string' ? date.preparse(arg, formatString) : arg,
212
+ date.isValid = function (arg1, arg2) {
213
+ var dt = typeof arg1 === 'string' ? date.preparse(arg1, arg2) : arg1,
201
214
  last = [31, 28 + date.isLeapYear(dt.Y) | 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][dt.M - 1];
202
215
 
203
216
  return !(
@@ -210,12 +223,12 @@
210
223
  /**
211
224
  * parsing a date string
212
225
  * @param {string} dateString - a date string
213
- * @param {string} formatString - a format string
226
+ * @param {string|Array.<string>} arg - a format string or a compiled object
214
227
  * @param {boolean} [utc] - input as UTC
215
228
  * @returns {Date} a constructed date
216
229
  */
217
- date.parse = function (dateString, formatString, utc) {
218
- var dt = date.preparse(dateString, formatString), dateObj;
230
+ date.parse = function (dateString, arg, utc) {
231
+ var dt = date.preparse(dateString, arg), dateObj;
219
232
 
220
233
  if (date.isValid(dt)) {
221
234
  dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
@@ -1,15 +1,15 @@
1
1
  /*
2
2
  date-and-time.js (c) KNOWLEDGECODE | MIT
3
3
  */
4
- (function(p){var d={},l={},g={},h="en",q={MMMM:"January February March April May June July August September October November December".split(" "),MMM:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),dddd:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["a.m.","p.m."]},r={YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)},
4
+ (function(r){var b={},m={},k={},h="en",t={MMMM:"January February March April May June July August September October November December".split(" "),MMM:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),dddd:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["a.m.","p.m."]},u={YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)},
5
5
  Y:function(a){return""+a.getFullYear()},MMMM:function(a){return this.res.MMMM[a.getMonth()]},MMM:function(a){return this.res.MMM[a.getMonth()]},MM:function(a){return("0"+(a.getMonth()+1)).slice(-2)},M:function(a){return""+(a.getMonth()+1)},DD:function(a){return("0"+a.getDate()).slice(-2)},D:function(a){return""+a.getDate()},HH:function(a){return("0"+a.getHours()).slice(-2)},H:function(a){return""+a.getHours()},A:function(a){return this.res.A[11<a.getHours()|0]},hh:function(a){return("0"+(a.getHours()%
6
6
  12||12)).slice(-2)},h:function(a){return""+(a.getHours()%12||12)},mm:function(a){return("0"+a.getMinutes()).slice(-2)},m:function(a){return""+a.getMinutes()},ss:function(a){return("0"+a.getSeconds()).slice(-2)},s:function(a){return""+a.getSeconds()},SSS:function(a){return("00"+a.getMilliseconds()).slice(-3)},SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},
7
- dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.utc?0:a.getTimezoneOffset()/.6;return(0<a?"-":"+")+("000"+Math.abs(a-a%100*.4)).slice(-4)},post:function(a){return a}},t={YYYY:function(a){return this.exec(/^\d{4}/,a)},YY:function(a){a=this.exec(/^\d\d/,a);a.value+=70>a.value?2E3:100>a.value?1900:0;return a},Y:function(a){return this.exec(/^\d{1,4}/,a)},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},
7
+ dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.utc?0:a.getTimezoneOffset()/.6;return(0<a?"-":"+")+("000"+Math.abs(a-a%100*.4)).slice(-4)},post:function(a){return a}},w={YYYY:function(a){return this.exec(/^\d{4}/,a)},YY:function(a){a=this.exec(/^\d\d/,a);a.value+=70>a.value?2E3:100>a.value?1900:0;return a},Y:function(a){return this.exec(/^\d{1,4}/,a)},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},
8
8
  MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,
9
- a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},h12:function(a,c){return(12===a?0:a)+12*c},exec:function(a,c){var b=(a.exec(c)||[""])[0];return{value:b|0,length:b.length}},find:function(a,c){for(var b=-1,d=0,e=0,k=a.length,f;e<k;e++)f=a[e],!c.indexOf(f)&&f.length>d&&(b=e,d=f.length);return{value:b,length:d}},pre:function(a){return a}},
10
- n=function(a,c,b){var d=function(a,b,c){var d=function(a){a&&(this.res=a)};d.prototype=a;d.prototype.constructor=d;a=new d(c);for(var e in b||{})b.hasOwnProperty(e)&&(c=b[e],a[e]=c.slice?c.slice():c);return a},e={res:d(c.res,b.res)};e.formatter=d(c.formatter,b.formatter,e.res);e.parser=d(c.parser,b.parser,e.res);l[a]=e};d.format=function(a,c,b){var m=d.addMinutes(a,b?a.getTimezoneOffset():0),e=l[h].formatter;m.utc=b;return c.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]|([A-Za-z])\1*|./g,function(a){return e[a]?
11
- e.post(e[a](m,c)):a.replace(/\[(.*)]/,"$1")})};d.preparse=function(a,c){var b=l[h].parser,d=/([A-Za-z])\1*|./g,e,k=0,f={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,_index:0,_length:0,_match:0};a=b.pre(a);for(c=c.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]/g,function(a){return a.replace(/./g," ").slice(2)});e=d.exec(c);)if(e=e[0],b[e]){var g=b[e](a.slice(k),c);if(!g.length)break;k+=g.length;f[e.charAt(0)]=g.value;f._match++}else if(e===a.charAt(k)||" "===e)k++;else break;f.H=f.H||b.h12(f.h,f.A);f._index=k;f._length=
12
- a.length;return f};d.isValid=function(a,c){var b="string"===typeof a?d.preparse(a,c):a,g=[31,28+d.isLeapYear(b.Y)|0,31,30,31,30,31,31,30,31,30,31][b.M-1];return!(1>b._index||1>b._length||b._index-b._length||1>b._match||1>b.Y||9999<b.Y||1>b.M||12<b.M||1>b.D||b.D>g||23<b.H||0>b.H||59<b.m||0>b.m||59<b.s||0>b.s||999<b.S||0>b.S)};d.parse=function(a,c,b){a=d.preparse(a,c);return d.isValid(a)?(a.M-=100>a.Y?22801:1,b=b?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):
13
- new Date(NaN)};d.addYears=function(a,c){return d.addMonths(a,12*c)};d.addMonths=function(a,c){var b=new Date(a.getTime());b.setMonth(b.getMonth()+c);return b};d.addDays=function(a,c){var b=new Date(a.getTime());b.setDate(b.getDate()+c);return b};d.addHours=function(a,c){return d.addMilliseconds(a,36E5*c)};d.addMinutes=function(a,c){return d.addMilliseconds(a,6E4*c)};d.addSeconds=function(a,c){return d.addMilliseconds(a,1E3*c)};d.addMilliseconds=function(a,c){return new Date(a.getTime()+c)};d.subtract=
14
- function(a,c){var b=a.getTime()-c.getTime();return{toMilliseconds:function(){return b},toSeconds:function(){return b/1E3|0},toMinutes:function(){return b/6E4|0},toHours:function(){return b/36E5|0},toDays:function(){return b/864E5|0}}};d.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};d.isSameDay=function(a,c){return d.format(a,"YYYYMMDD")===d.format(c,"YYYYMMDD")};d.locale=function(a,c){c?n(a,{res:q,formatter:r,parser:t},c):a&&(h=a);return h};d.extend=function(a){n(h,l[h],a)};d.plugin=function(a,
15
- c){g[a]=g[a]||c;!c&&g[a]&&d.extend(g[a])};d.locale(h,{});"object"===typeof module&&"object"===typeof module.exports?module.exports=d:"function"===typeof define&&define.amd?define([],function(){return d}):p.date=d})(this);
9
+ a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},h12:function(a,d){return(12===a?0:a)+12*d},exec:function(a,d){var c=(a.exec(d)||[""])[0];return{value:c|0,length:c.length}},find:function(a,d){for(var c=-1,b=0,e=0,v=a.length,f;e<v;e++)f=a[e],!d.indexOf(f)&&f.length>b&&(c=e,b=f.length);return{value:c,length:b}},pre:function(a){return a}},
10
+ n=function(a,d,c){var b=function(a,c,d){var b=function(a){a&&(this.res=a)};b.prototype=a;b.prototype.constructor=b;a=new b(d);for(var e in c||{})c.hasOwnProperty(e)&&(d=c[e],a[e]=d.slice?d.slice():d);return a},e={res:b(d.res,c.res)};e.formatter=b(d.formatter,c.formatter,e.res);e.parser=b(d.parser,c.parser,e.res);m[a]=e};b.format=function(a,d,c){var g=b.addMinutes(a,c?a.getTimezoneOffset():0),e=m[h].formatter;g.utc=c;return d.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]|([A-Za-z])\1*|./g,function(a){return e[a]?
11
+ e.post(e[a](g,d)):a.replace(/\[(.*)]/,"$1")})};b.compile=function(a){var d=/([A-Za-z])\1*|./g,c,b=[a];for(a=a.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]/g,function(a){return a.replace(/./g," ").slice(2)});c=d.exec(a);)b[b.length]=c[0];return b};b.preparse=function(a,d){var c=m[h].parser,g=0,e="string"===typeof d?b.compile(d):d,k=e[0],f={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,_index:0,_length:0,_match:0};a=c.pre(a);for(var p=1,n=e.length;p<n;p++){var l=e[p];if(c[l]){var q=c[l](a.slice(g),k);if(!q.length)break;
12
+ g+=q.length;f[l.charAt(0)]=q.value;f._match++}else if(l===a.charAt(g)||" "===l)g++;else break}f.H=f.H||c.h12(f.h,f.A);f._index=g;f._length=a.length;return f};b.isValid=function(a,d){var c="string"===typeof a?b.preparse(a,d):a,g=[31,28+b.isLeapYear(c.Y)|0,31,30,31,30,31,31,30,31,30,31][c.M-1];return!(1>c._index||1>c._length||c._index-c._length||1>c._match||1>c.Y||9999<c.Y||1>c.M||12<c.M||1>c.D||c.D>g||23<c.H||0>c.H||59<c.m||0>c.m||59<c.s||0>c.s||999<c.S||0>c.S)};b.parse=function(a,d,c){a=b.preparse(a,
13
+ d);return b.isValid(a)?(a.M-=100>a.Y?22801:1,c=c?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};b.addYears=function(a,d){return b.addMonths(a,12*d)};b.addMonths=function(a,b){var c=new Date(a.getTime());c.setMonth(c.getMonth()+b);return c};b.addDays=function(a,b){var c=new Date(a.getTime());c.setDate(c.getDate()+b);return c};b.addHours=function(a,d){return b.addMilliseconds(a,36E5*d)};b.addMinutes=function(a,d){return b.addMilliseconds(a,6E4*
14
+ d)};b.addSeconds=function(a,d){return b.addMilliseconds(a,1E3*d)};b.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};b.subtract=function(a,b){var c=a.getTime()-b.getTime();return{toMilliseconds:function(){return c},toSeconds:function(){return c/1E3|0},toMinutes:function(){return c/6E4|0},toHours:function(){return c/36E5|0},toDays:function(){return c/864E5|0}}};b.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};b.isSameDay=function(a,d){return b.format(a,"YYYYMMDD")===b.format(d,
15
+ "YYYYMMDD")};b.locale=function(a,b){b?n(a,{res:t,formatter:u,parser:w},b):a&&(h=a);return h};b.extend=function(a){n(h,m[h],a)};b.plugin=function(a,d){k[a]=k[a]||d;!d&&k[a]&&b.extend(k[a])};b.locale(h,{});"object"===typeof module&&"object"===typeof module.exports?module.exports=b:"function"===typeof define&&define.amd?define([],function(){return b}):r.date=b})(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-and-time",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "A Minimalist DateTime utility for Node.js and the browser",
5
5
  "main": "date-and-time.js",
6
6
  "scripts": {