date-and-time 2.0.0 → 2.1.2
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/EXTEND.md +4 -0
- package/LOCALE.md +1 -0
- package/README.md +16 -9
- package/date-and-time.js +33 -28
- package/date-and-time.min.js +10 -10
- package/esm/date-and-time.es.js +31 -26
- package/esm/date-and-time.es.min.js +12 -11
- package/esm/date-and-time.mjs +31 -26
- package/esm/locale/sv.es.js +22 -0
- package/esm/locale/sv.mjs +22 -0
- package/esm/plugin/timezone.es.js +4 -4
- package/esm/plugin/timezone.mjs +4 -4
- package/locale/ar.js +2 -2
- package/locale/az.js +2 -2
- package/locale/bn.js +2 -2
- package/locale/cs.js +2 -2
- package/locale/de.js +2 -2
- package/locale/dk.js +2 -2
- package/locale/el.js +2 -2
- package/locale/en.js +2 -2
- package/locale/es.js +2 -2
- package/locale/fa.js +2 -2
- package/locale/fr.js +2 -2
- package/locale/hi.js +2 -2
- package/locale/hu.js +2 -2
- package/locale/id.js +2 -2
- package/locale/it.js +2 -2
- package/locale/ja.js +2 -2
- package/locale/jv.js +2 -2
- package/locale/ko.js +2 -2
- package/locale/my.js +2 -2
- package/locale/nl.js +2 -2
- package/locale/pa-in.js +3 -3
- package/locale/pl.js +2 -2
- package/locale/pt.js +2 -2
- package/locale/ro.js +2 -2
- package/locale/ru.js +2 -2
- package/locale/rw.js +2 -2
- package/locale/sr.js +2 -2
- package/locale/sv.js +30 -0
- package/locale/th.js +2 -2
- package/locale/tr.js +2 -2
- package/locale/uk.js +2 -2
- package/locale/uz.js +2 -2
- package/locale/vi.js +2 -2
- package/locale/zh-cn.js +3 -3
- package/locale/zh-tw.js +3 -3
- package/package.json +4 -4
- package/plugin/day-of-week.js +3 -3
- package/plugin/meridiem.js +2 -2
- package/plugin/microsecond.js +2 -2
- package/plugin/ordinal.js +2 -2
- package/plugin/timespan.js +2 -2
- package/plugin/timezone.js +6 -6
- package/plugin/two-digit-year.js +3 -3
package/EXTEND.md
CHANGED
|
@@ -101,3 +101,7 @@ date.extend({
|
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
Extending the parser may be a bit difficult. Refer to the library source code to grasp the default behavior.
|
|
104
|
+
|
|
105
|
+
## Caveats
|
|
106
|
+
|
|
107
|
+
Note that switching locales or applying plugins after extending the library will be cleared all extensions. In such cases, you need to extend the library again.
|
package/LOCALE.md
CHANGED
package/README.md
CHANGED
|
@@ -24,18 +24,25 @@ npm i date-and-time
|
|
|
24
24
|
|
|
25
25
|
## Recent Changes
|
|
26
26
|
|
|
27
|
-
- 2.
|
|
28
|
-
- Fixed
|
|
29
|
-
- **Breaking Changes!** Due to the above fix, the specifications of plugin, locale, and extension have been changed. The `meridiem` plugin and the `two-digit-year` plugin are now partially incompatible with previous ones. See [here](./PLUGINS.md) for details. Also the `extend()` function has changed. If you are using it, check [here](./EXTEND.md) for any impact. The locales are still compatible.
|
|
30
|
-
- Added `timezone` plugin. You can now use the IANA timezone name to output a datetime string or input a date object. See [PLUGINS.md](./PLUGINS.md) for details.
|
|
27
|
+
- 2.1.2
|
|
28
|
+
- Fixed an issue that the lib's validation logic would condider an error when a timezone offset value of a datetime string was greater then +12 hours.
|
|
31
29
|
|
|
32
|
-
- 1.
|
|
30
|
+
- 2.1.1
|
|
33
31
|
- Updated dev dependencies to resolve vulnerability.
|
|
34
32
|
|
|
35
|
-
- 1.0
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
- 2.1.0
|
|
34
|
+
- Fixed an issue that the lib's functions assigned to variables using ES6 destructuring assignment cause an error.
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// Destructuring assignment
|
|
38
|
+
const { format, parse } = require('date-and-time');
|
|
39
|
+
|
|
40
|
+
// These used to be errors in 2.0.x.
|
|
41
|
+
format(new Date(), 'MMM DD YYYY');
|
|
42
|
+
parse('Jan 11 2022', 'MMM DD YYYY');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Added Swedish support.
|
|
39
46
|
|
|
40
47
|
## Usage
|
|
41
48
|
|
package/date-and-time.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.date = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @preserve date-and-time (c) KNOWLEDGECODE | MIT
|
|
@@ -128,12 +128,13 @@
|
|
|
128
128
|
obj.res = res;
|
|
129
129
|
}
|
|
130
130
|
return obj;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
},
|
|
132
|
+
proto = {
|
|
133
|
+
_formatter: _formatter,
|
|
134
|
+
_parser: _parser
|
|
135
|
+
},
|
|
136
|
+
localized_proto,
|
|
137
|
+
date;
|
|
137
138
|
|
|
138
139
|
/**
|
|
139
140
|
* Compiling a format string
|
|
@@ -157,10 +158,10 @@
|
|
|
157
158
|
* @returns {string} a formatted string
|
|
158
159
|
*/
|
|
159
160
|
proto.format = function (dateObj, arg, utc) {
|
|
160
|
-
var pattern = typeof arg === 'string' ?
|
|
161
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
161
162
|
offset = dateObj.getTimezoneOffset(),
|
|
162
|
-
d =
|
|
163
|
-
formatter =
|
|
163
|
+
d = ctx.addMinutes(dateObj, utc ? offset : 0),
|
|
164
|
+
formatter = ctx._formatter, str = '';
|
|
164
165
|
|
|
165
166
|
d.getTimezoneOffset = function () { return utc ? 0 : offset; };
|
|
166
167
|
for (var i = 1, len = pattern.length, token; i < len; i++) {
|
|
@@ -177,9 +178,9 @@
|
|
|
177
178
|
* @returns {Object} a date structure
|
|
178
179
|
*/
|
|
179
180
|
proto.preparse = function (dateString, arg) {
|
|
180
|
-
var pattern = typeof arg === 'string' ?
|
|
181
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
181
182
|
dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, Z: 0, _index: 0, _length: 0, _match: 0 },
|
|
182
|
-
comment = /\[(.*)]/, parser =
|
|
183
|
+
comment = /\[(.*)]/, parser = ctx._parser, offset = 0;
|
|
183
184
|
|
|
184
185
|
dateString = parser.pre(dateString);
|
|
185
186
|
for (var i = 1, len = pattern.length, token, result; i < len; i++) {
|
|
@@ -217,9 +218,9 @@
|
|
|
217
218
|
* @returns {Date} a constructed date
|
|
218
219
|
*/
|
|
219
220
|
proto.parse = function (dateString, arg, utc) {
|
|
220
|
-
var dt =
|
|
221
|
+
var ctx = this || date, dt = ctx.preparse(dateString, arg);
|
|
221
222
|
|
|
222
|
-
if (
|
|
223
|
+
if (ctx.isValid(dt)) {
|
|
223
224
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
224
225
|
if (utc || dt.Z) {
|
|
225
226
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
@@ -236,14 +237,14 @@
|
|
|
236
237
|
* @returns {boolean} whether the date string is a valid date
|
|
237
238
|
*/
|
|
238
239
|
proto.isValid = function (arg1, arg2) {
|
|
239
|
-
var dt = typeof arg1 === 'string' ?
|
|
240
|
-
last = [31, 28 +
|
|
240
|
+
var ctx = this || date, dt = typeof arg1 === 'string' ? ctx.preparse(arg1, arg2) : arg1,
|
|
241
|
+
last = [31, 28 + ctx.isLeapYear(dt.Y) | 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][dt.M - 1];
|
|
241
242
|
|
|
242
243
|
return !(
|
|
243
244
|
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
244
245
|
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
245
246
|
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
246
|
-
dt.Z < -
|
|
247
|
+
dt.Z < -840 || dt.Z > 720
|
|
247
248
|
);
|
|
248
249
|
};
|
|
249
250
|
|
|
@@ -256,7 +257,8 @@
|
|
|
256
257
|
* @returns {string} a formatted string
|
|
257
258
|
*/
|
|
258
259
|
proto.transform = function (dateString, arg1, arg2, utc) {
|
|
259
|
-
|
|
260
|
+
const ctx = this || date;
|
|
261
|
+
return ctx.format(ctx.parse(dateString, arg1), arg2, utc);
|
|
260
262
|
};
|
|
261
263
|
|
|
262
264
|
/**
|
|
@@ -266,7 +268,7 @@
|
|
|
266
268
|
* @returns {Date} a date after adding the value
|
|
267
269
|
*/
|
|
268
270
|
proto.addYears = function (dateObj, years) {
|
|
269
|
-
return this.addMonths(dateObj, years * 12);
|
|
271
|
+
return (this || date).addMonths(dateObj, years * 12);
|
|
270
272
|
};
|
|
271
273
|
|
|
272
274
|
/**
|
|
@@ -302,7 +304,7 @@
|
|
|
302
304
|
* @returns {Date} a date after adding the value
|
|
303
305
|
*/
|
|
304
306
|
proto.addHours = function (dateObj, hours) {
|
|
305
|
-
return this.addMinutes(dateObj, hours * 60);
|
|
307
|
+
return (this || date).addMinutes(dateObj, hours * 60);
|
|
306
308
|
};
|
|
307
309
|
|
|
308
310
|
/**
|
|
@@ -312,7 +314,7 @@
|
|
|
312
314
|
* @returns {Date} a date after adding the value
|
|
313
315
|
*/
|
|
314
316
|
proto.addMinutes = function (dateObj, minutes) {
|
|
315
|
-
return this.addSeconds(dateObj, minutes * 60);
|
|
317
|
+
return (this || date).addSeconds(dateObj, minutes * 60);
|
|
316
318
|
};
|
|
317
319
|
|
|
318
320
|
/**
|
|
@@ -322,7 +324,7 @@
|
|
|
322
324
|
* @returns {Date} a date after adding the value
|
|
323
325
|
*/
|
|
324
326
|
proto.addSeconds = function (dateObj, seconds) {
|
|
325
|
-
return this.addMilliseconds(dateObj, seconds * 1000);
|
|
327
|
+
return (this || date).addMilliseconds(dateObj, seconds * 1000);
|
|
326
328
|
};
|
|
327
329
|
|
|
328
330
|
/**
|
|
@@ -406,7 +408,8 @@
|
|
|
406
408
|
}
|
|
407
409
|
};
|
|
408
410
|
|
|
409
|
-
|
|
411
|
+
localized_proto = extend(proto);
|
|
412
|
+
date = extend(proto);
|
|
410
413
|
|
|
411
414
|
/**
|
|
412
415
|
* Changing locale
|
|
@@ -426,8 +429,8 @@
|
|
|
426
429
|
var formatter = extend(_formatter, extension.formatter, true, res);
|
|
427
430
|
var parser = extend(_parser, extension.parser, true, res);
|
|
428
431
|
|
|
429
|
-
date._formatter = formatter;
|
|
430
|
-
date._parser = parser;
|
|
432
|
+
date._formatter = localized_proto._formatter = formatter;
|
|
433
|
+
date._parser = localized_proto._parser = parser;
|
|
431
434
|
|
|
432
435
|
for (var plugin in plugins) {
|
|
433
436
|
date.extend(plugins[plugin]);
|
|
@@ -464,10 +467,12 @@
|
|
|
464
467
|
var install = typeof plugin === 'function' ? plugin : date.plugin[plugin];
|
|
465
468
|
|
|
466
469
|
if (install) {
|
|
467
|
-
date.extend(plugins[install(proto)] || {});
|
|
470
|
+
date.extend(plugins[install(proto, localized_proto)] || {});
|
|
468
471
|
}
|
|
469
472
|
};
|
|
470
473
|
|
|
471
|
-
|
|
474
|
+
var date$1 = date;
|
|
475
|
+
|
|
476
|
+
return date$1;
|
|
472
477
|
|
|
473
|
-
}))
|
|
478
|
+
}));
|
package/date-and-time.min.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*
|
|
2
2
|
date-and-time (c) KNOWLEDGECODE | MIT
|
|
3
3
|
*/
|
|
4
|
-
'use strict';(function(m
|
|
5
|
-
ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["AM","PM"]},
|
|
4
|
+
'use strict';(function(p,m){"object"===typeof exports&&"undefined"!==typeof module?module.exports=m():"function"===typeof define&&define.amd?define(m):(p="undefined"!==typeof globalThis?globalThis:p||self,p.date=m())})(this,function(){var p={},m={},r="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(" "),
|
|
5
|
+
ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["AM","PM"]},w={YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)},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)},
|
|
6
6
|
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()%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)},
|
|
7
|
-
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()]},dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:
|
|
7
|
+
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()]},dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:t},x={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},
|
|
8
8
|
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},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?/,
|
|
9
9
|
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/,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},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,
|
|
10
|
-
b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,
|
|
11
|
-
format
|
|
12
|
-
|
|
13
|
-
a.m,a.s,a.S)):new Date(NaN)}
|
|
14
|
-
new Date(a.getTime());a.setMonth(a.getMonth()+b);return a}
|
|
15
|
-
1E3},toMinutes:function(){return c/6E4},toHours:function(){return c/36E5},toDays:function(){return c/864E5}}}
|
|
16
|
-
for(var d in
|
|
10
|
+
b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},res:t},n=function(a,b,c,d){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h},f={_formatter:w,_parser:x};f.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};
|
|
11
|
+
f.format=function(a,b,c){var d=this||e;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,u=b.length,k;l<u;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};f.preparse=function(a,b){var c=this||e;b="string"===typeof b?c.compile(b):b;var d={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},h=/\[(.*)]/;c=c._parser;var g=0;a=c.pre(a);for(var l=
|
|
12
|
+
1,u=b.length,k,q;l<u;l++)if(k=b[l],c[k]){q=c[k](a.slice(g),b[0]);if(!q.length)break;g+=q.length;d[q.token||k.charAt(0)]=q.value;d._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}d.H=d.H||c.h12(d.h,d.A);d._index=g;d._length=a.length;return d};f.parse=function(a,b,c){var d=this||e;a=d.preparse(a,b);return d.isValid(a)?(a.M-=100>a.Y?22801:1,c||a.Z?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,
|
|
13
|
+
a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};f.isValid=function(a,b){var c=this||e;a="string"===typeof a?c.preparse(a,b):a;c=[31,28+c.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>a._length||a._index-a._length||1>a._match||1>a.Y||9999<a.Y||1>a.M||12<a.M||1>a.D||a.D>c||0>a.H||23<a.H||0>a.m||59<a.m||0>a.s||59<a.s||0>a.S||999<a.S||-840>a.Z||720<a.Z)};f.transform=function(a,b,c,d){let h=this||e;return h.format(h.parse(a,b),c,d)};f.addYears=function(a,b){return(this||e).addMonths(a,
|
|
14
|
+
12*b)};f.addMonths=function(a,b){a=new Date(a.getTime());a.setMonth(a.getMonth()+b);return a};f.addDays=function(a,b){a=new Date(a.getTime());a.setDate(a.getDate()+b);return a};f.addHours=function(a,b){return(this||e).addMinutes(a,60*b)};f.addMinutes=function(a,b){return(this||e).addSeconds(a,60*b)};f.addSeconds=function(a,b){return(this||e).addMilliseconds(a,1E3*b)};f.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};f.subtract=function(a,b){var c=a.getTime()-b.getTime();return{toMilliseconds:function(){return c},
|
|
15
|
+
toSeconds:function(){return c/1E3},toMinutes:function(){return c/6E4},toHours:function(){return c/36E5},toDays:function(){return c/864E5}}};f.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};f.isSameDay=function(a,b){return a.toDateString()===b.toDateString()};f.locale=function(a,b){p[a]||(p[a]=b)};f.plugin=function(a,b){m[a]||(m[a]=b)};var v=n(f);var e=n(f);e.locale=function(a){a="function"===typeof a?a:e.locale[a];if(!a)return r;r=a(f);var b=p[r]||{},c=n(t,b.res,!0);a=n(w,b.formatter,!0,
|
|
16
|
+
c);b=n(x,b.parser,!0,c);e._formatter=v._formatter=a;e._parser=v._parser=b;for(var d in m)e.extend(m[d]);return r};e.extend=function(a){var b=n(e._parser.res,a.res),c=a.extender||{};e._formatter=n(e._formatter,a.formatter,!1,b);e._parser=n(e._parser,a.parser,!1,b);for(var d in c)e[d]||(e[d]=c[d])};e.plugin=function(a){(a="function"===typeof a?a:e.plugin[a])&&e.extend(m[a(f,v)]||{})};return e})
|
package/esm/date-and-time.es.js
CHANGED
|
@@ -122,12 +122,13 @@ var locales = {},
|
|
|
122
122
|
obj.res = res;
|
|
123
123
|
}
|
|
124
124
|
return obj;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
},
|
|
126
|
+
proto = {
|
|
127
|
+
_formatter: _formatter,
|
|
128
|
+
_parser: _parser
|
|
129
|
+
},
|
|
130
|
+
localized_proto,
|
|
131
|
+
date;
|
|
131
132
|
|
|
132
133
|
/**
|
|
133
134
|
* Compiling a format string
|
|
@@ -151,10 +152,10 @@ proto.compile = function (formatString) {
|
|
|
151
152
|
* @returns {string} a formatted string
|
|
152
153
|
*/
|
|
153
154
|
proto.format = function (dateObj, arg, utc) {
|
|
154
|
-
var pattern = typeof arg === 'string' ?
|
|
155
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
155
156
|
offset = dateObj.getTimezoneOffset(),
|
|
156
|
-
d =
|
|
157
|
-
formatter =
|
|
157
|
+
d = ctx.addMinutes(dateObj, utc ? offset : 0),
|
|
158
|
+
formatter = ctx._formatter, str = '';
|
|
158
159
|
|
|
159
160
|
d.getTimezoneOffset = function () { return utc ? 0 : offset; };
|
|
160
161
|
for (var i = 1, len = pattern.length, token; i < len; i++) {
|
|
@@ -171,9 +172,9 @@ proto.format = function (dateObj, arg, utc) {
|
|
|
171
172
|
* @returns {Object} a date structure
|
|
172
173
|
*/
|
|
173
174
|
proto.preparse = function (dateString, arg) {
|
|
174
|
-
var pattern = typeof arg === 'string' ?
|
|
175
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
175
176
|
dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, Z: 0, _index: 0, _length: 0, _match: 0 },
|
|
176
|
-
comment = /\[(.*)]/, parser =
|
|
177
|
+
comment = /\[(.*)]/, parser = ctx._parser, offset = 0;
|
|
177
178
|
|
|
178
179
|
dateString = parser.pre(dateString);
|
|
179
180
|
for (var i = 1, len = pattern.length, token, result; i < len; i++) {
|
|
@@ -211,9 +212,9 @@ proto.preparse = function (dateString, arg) {
|
|
|
211
212
|
* @returns {Date} a constructed date
|
|
212
213
|
*/
|
|
213
214
|
proto.parse = function (dateString, arg, utc) {
|
|
214
|
-
var dt =
|
|
215
|
+
var ctx = this || date, dt = ctx.preparse(dateString, arg);
|
|
215
216
|
|
|
216
|
-
if (
|
|
217
|
+
if (ctx.isValid(dt)) {
|
|
217
218
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
218
219
|
if (utc || dt.Z) {
|
|
219
220
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
@@ -230,14 +231,14 @@ proto.parse = function (dateString, arg, utc) {
|
|
|
230
231
|
* @returns {boolean} whether the date string is a valid date
|
|
231
232
|
*/
|
|
232
233
|
proto.isValid = function (arg1, arg2) {
|
|
233
|
-
var dt = typeof arg1 === 'string' ?
|
|
234
|
-
last = [31, 28 +
|
|
234
|
+
var ctx = this || date, dt = typeof arg1 === 'string' ? ctx.preparse(arg1, arg2) : arg1,
|
|
235
|
+
last = [31, 28 + ctx.isLeapYear(dt.Y) | 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][dt.M - 1];
|
|
235
236
|
|
|
236
237
|
return !(
|
|
237
238
|
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
238
239
|
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
239
240
|
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
240
|
-
dt.Z < -
|
|
241
|
+
dt.Z < -840 || dt.Z > 720
|
|
241
242
|
);
|
|
242
243
|
};
|
|
243
244
|
|
|
@@ -250,7 +251,8 @@ proto.isValid = function (arg1, arg2) {
|
|
|
250
251
|
* @returns {string} a formatted string
|
|
251
252
|
*/
|
|
252
253
|
proto.transform = function (dateString, arg1, arg2, utc) {
|
|
253
|
-
|
|
254
|
+
const ctx = this || date;
|
|
255
|
+
return ctx.format(ctx.parse(dateString, arg1), arg2, utc);
|
|
254
256
|
};
|
|
255
257
|
|
|
256
258
|
/**
|
|
@@ -260,7 +262,7 @@ proto.transform = function (dateString, arg1, arg2, utc) {
|
|
|
260
262
|
* @returns {Date} a date after adding the value
|
|
261
263
|
*/
|
|
262
264
|
proto.addYears = function (dateObj, years) {
|
|
263
|
-
return this.addMonths(dateObj, years * 12);
|
|
265
|
+
return (this || date).addMonths(dateObj, years * 12);
|
|
264
266
|
};
|
|
265
267
|
|
|
266
268
|
/**
|
|
@@ -296,7 +298,7 @@ proto.addDays = function (dateObj, days) {
|
|
|
296
298
|
* @returns {Date} a date after adding the value
|
|
297
299
|
*/
|
|
298
300
|
proto.addHours = function (dateObj, hours) {
|
|
299
|
-
return this.addMinutes(dateObj, hours * 60);
|
|
301
|
+
return (this || date).addMinutes(dateObj, hours * 60);
|
|
300
302
|
};
|
|
301
303
|
|
|
302
304
|
/**
|
|
@@ -306,7 +308,7 @@ proto.addHours = function (dateObj, hours) {
|
|
|
306
308
|
* @returns {Date} a date after adding the value
|
|
307
309
|
*/
|
|
308
310
|
proto.addMinutes = function (dateObj, minutes) {
|
|
309
|
-
return this.addSeconds(dateObj, minutes * 60);
|
|
311
|
+
return (this || date).addSeconds(dateObj, minutes * 60);
|
|
310
312
|
};
|
|
311
313
|
|
|
312
314
|
/**
|
|
@@ -316,7 +318,7 @@ proto.addMinutes = function (dateObj, minutes) {
|
|
|
316
318
|
* @returns {Date} a date after adding the value
|
|
317
319
|
*/
|
|
318
320
|
proto.addSeconds = function (dateObj, seconds) {
|
|
319
|
-
return this.addMilliseconds(dateObj, seconds * 1000);
|
|
321
|
+
return (this || date).addMilliseconds(dateObj, seconds * 1000);
|
|
320
322
|
};
|
|
321
323
|
|
|
322
324
|
/**
|
|
@@ -400,7 +402,8 @@ proto.plugin = function (name, plugin) {
|
|
|
400
402
|
}
|
|
401
403
|
};
|
|
402
404
|
|
|
403
|
-
|
|
405
|
+
localized_proto = extend(proto);
|
|
406
|
+
date = extend(proto);
|
|
404
407
|
|
|
405
408
|
/**
|
|
406
409
|
* Changing locale
|
|
@@ -420,8 +423,8 @@ date.locale = function (locale) {
|
|
|
420
423
|
var formatter = extend(_formatter, extension.formatter, true, res);
|
|
421
424
|
var parser = extend(_parser, extension.parser, true, res);
|
|
422
425
|
|
|
423
|
-
date._formatter = formatter;
|
|
424
|
-
date._parser = parser;
|
|
426
|
+
date._formatter = localized_proto._formatter = formatter;
|
|
427
|
+
date._parser = localized_proto._parser = parser;
|
|
425
428
|
|
|
426
429
|
for (var plugin in plugins) {
|
|
427
430
|
date.extend(plugins[plugin]);
|
|
@@ -458,8 +461,10 @@ date.plugin = function (plugin) {
|
|
|
458
461
|
var install = typeof plugin === 'function' ? plugin : date.plugin[plugin];
|
|
459
462
|
|
|
460
463
|
if (install) {
|
|
461
|
-
date.extend(plugins[install(proto)] || {});
|
|
464
|
+
date.extend(plugins[install(proto, localized_proto)] || {});
|
|
462
465
|
}
|
|
463
466
|
};
|
|
464
467
|
|
|
465
|
-
|
|
468
|
+
var date$1 = date;
|
|
469
|
+
|
|
470
|
+
export { date$1 as default };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
/*
|
|
2
2
|
date-and-time (c) KNOWLEDGECODE | MIT
|
|
3
3
|
*/
|
|
4
|
-
var
|
|
4
|
+
var e={},f={},m="en",n={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:["AM","PM"]},q={YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)},Y:function(a){return""+
|
|
5
5
|
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()%12||12)).slice(-2)},
|
|
6
6
|
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.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:
|
|
7
|
+
dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:n},r={YYYY:function(a){return this.exec(/^\d{4}/,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},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},
|
|
8
8
|
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/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,
|
|
9
|
-
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},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,
|
|
10
|
-
res:
|
|
11
|
-
|
|
12
|
-
b
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
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},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},
|
|
10
|
+
res:n};function t(a,b,c,d){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h}var u={_formatter:q,_parser:r},w,x;u.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};
|
|
11
|
+
u.format=function(a,b,c){var d=this||x;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,v=b.length,k;l<v;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};
|
|
12
|
+
u.preparse=function(a,b){var c=this||x;b="string"===typeof b?c.compile(b):b;var d={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},h=/\[(.*)]/;c=c._parser;var g=0;a=c.pre(a);for(var l=1,v=b.length,k,p;l<v;l++)if(k=b[l],c[k]){p=c[k](a.slice(g),b[0]);if(!p.length)break;g+=p.length;d[p.token||k.charAt(0)]=p.value;d._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}d.H=d.H||c.h12(d.h,
|
|
13
|
+
d.A);d._index=g;d._length=a.length;return d};u.parse=function(a,b,c){var d=this||x;a=d.preparse(a,b);return d.isValid(a)?(a.M-=100>a.Y?22801:1,c||a.Z?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};
|
|
14
|
+
u.isValid=function(a,b){var c=this||x;a="string"===typeof a?c.preparse(a,b):a;c=[31,28+c.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>a._length||a._index-a._length||1>a._match||1>a.Y||9999<a.Y||1>a.M||12<a.M||1>a.D||a.D>c||0>a.H||23<a.H||0>a.m||59<a.m||0>a.s||59<a.s||0>a.S||999<a.S||-840>a.Z||720<a.Z)};u.transform=function(a,b,c,d){let h=this||x;return h.format(h.parse(a,b),c,d)};u.addYears=function(a,b){return(this||x).addMonths(a,12*b)};
|
|
15
|
+
u.addMonths=function(a,b){a=new Date(a.getTime());a.setMonth(a.getMonth()+b);return a};u.addDays=function(a,b){a=new Date(a.getTime());a.setDate(a.getDate()+b);return a};u.addHours=function(a,b){return(this||x).addMinutes(a,60*b)};u.addMinutes=function(a,b){return(this||x).addSeconds(a,60*b)};u.addSeconds=function(a,b){return(this||x).addMilliseconds(a,1E3*b)};u.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};
|
|
16
|
+
u.subtract=function(a,b){var c=a.getTime()-b.getTime();return{toMilliseconds:function(){return c},toSeconds:function(){return c/1E3},toMinutes:function(){return c/6E4},toHours:function(){return c/36E5},toDays:function(){return c/864E5}}};u.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};u.isSameDay=function(a,b){return a.toDateString()===b.toDateString()};u.locale=function(a,b){e[a]||(e[a]=b)};u.plugin=function(a,b){f[a]||(f[a]=b)};w=t(u);x=t(u);
|
|
17
|
+
x.locale=function(a){a="function"===typeof a?a:x.locale[a];if(!a)return m;m=a(u);var b=e[m]||{},c=t(n,b.res,!0);a=t(q,b.formatter,!0,c);b=t(r,b.parser,!0,c);x._formatter=w._formatter=a;x._parser=w._parser=b;for(var d in f)x.extend(f[d]);return m};x.extend=function(a){var b=t(x._parser.res,a.res),c=a.extender||{};x._formatter=t(x._formatter,a.formatter,!1,b);x._parser=t(x._parser,a.parser,!1,b);for(var d in c)x[d]||(x[d]=c[d])};
|
|
18
|
+
x.plugin=function(a){(a="function"===typeof a?a:x.plugin[a])&&x.extend(f[a(u,w)]||{})};export default x
|
package/esm/date-and-time.mjs
CHANGED
|
@@ -122,12 +122,13 @@ var locales = {},
|
|
|
122
122
|
obj.res = res;
|
|
123
123
|
}
|
|
124
124
|
return obj;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
},
|
|
126
|
+
proto = {
|
|
127
|
+
_formatter: _formatter,
|
|
128
|
+
_parser: _parser
|
|
129
|
+
},
|
|
130
|
+
localized_proto,
|
|
131
|
+
date;
|
|
131
132
|
|
|
132
133
|
/**
|
|
133
134
|
* Compiling a format string
|
|
@@ -151,10 +152,10 @@ proto.compile = function (formatString) {
|
|
|
151
152
|
* @returns {string} a formatted string
|
|
152
153
|
*/
|
|
153
154
|
proto.format = function (dateObj, arg, utc) {
|
|
154
|
-
var pattern = typeof arg === 'string' ?
|
|
155
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
155
156
|
offset = dateObj.getTimezoneOffset(),
|
|
156
|
-
d =
|
|
157
|
-
formatter =
|
|
157
|
+
d = ctx.addMinutes(dateObj, utc ? offset : 0),
|
|
158
|
+
formatter = ctx._formatter, str = '';
|
|
158
159
|
|
|
159
160
|
d.getTimezoneOffset = function () { return utc ? 0 : offset; };
|
|
160
161
|
for (var i = 1, len = pattern.length, token; i < len; i++) {
|
|
@@ -171,9 +172,9 @@ proto.format = function (dateObj, arg, utc) {
|
|
|
171
172
|
* @returns {Object} a date structure
|
|
172
173
|
*/
|
|
173
174
|
proto.preparse = function (dateString, arg) {
|
|
174
|
-
var pattern = typeof arg === 'string' ?
|
|
175
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
175
176
|
dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, Z: 0, _index: 0, _length: 0, _match: 0 },
|
|
176
|
-
comment = /\[(.*)]/, parser =
|
|
177
|
+
comment = /\[(.*)]/, parser = ctx._parser, offset = 0;
|
|
177
178
|
|
|
178
179
|
dateString = parser.pre(dateString);
|
|
179
180
|
for (var i = 1, len = pattern.length, token, result; i < len; i++) {
|
|
@@ -211,9 +212,9 @@ proto.preparse = function (dateString, arg) {
|
|
|
211
212
|
* @returns {Date} a constructed date
|
|
212
213
|
*/
|
|
213
214
|
proto.parse = function (dateString, arg, utc) {
|
|
214
|
-
var dt =
|
|
215
|
+
var ctx = this || date, dt = ctx.preparse(dateString, arg);
|
|
215
216
|
|
|
216
|
-
if (
|
|
217
|
+
if (ctx.isValid(dt)) {
|
|
217
218
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
218
219
|
if (utc || dt.Z) {
|
|
219
220
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
@@ -230,14 +231,14 @@ proto.parse = function (dateString, arg, utc) {
|
|
|
230
231
|
* @returns {boolean} whether the date string is a valid date
|
|
231
232
|
*/
|
|
232
233
|
proto.isValid = function (arg1, arg2) {
|
|
233
|
-
var dt = typeof arg1 === 'string' ?
|
|
234
|
-
last = [31, 28 +
|
|
234
|
+
var ctx = this || date, dt = typeof arg1 === 'string' ? ctx.preparse(arg1, arg2) : arg1,
|
|
235
|
+
last = [31, 28 + ctx.isLeapYear(dt.Y) | 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][dt.M - 1];
|
|
235
236
|
|
|
236
237
|
return !(
|
|
237
238
|
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
238
239
|
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
239
240
|
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
240
|
-
dt.Z < -
|
|
241
|
+
dt.Z < -840 || dt.Z > 720
|
|
241
242
|
);
|
|
242
243
|
};
|
|
243
244
|
|
|
@@ -250,7 +251,8 @@ proto.isValid = function (arg1, arg2) {
|
|
|
250
251
|
* @returns {string} a formatted string
|
|
251
252
|
*/
|
|
252
253
|
proto.transform = function (dateString, arg1, arg2, utc) {
|
|
253
|
-
|
|
254
|
+
const ctx = this || date;
|
|
255
|
+
return ctx.format(ctx.parse(dateString, arg1), arg2, utc);
|
|
254
256
|
};
|
|
255
257
|
|
|
256
258
|
/**
|
|
@@ -260,7 +262,7 @@ proto.transform = function (dateString, arg1, arg2, utc) {
|
|
|
260
262
|
* @returns {Date} a date after adding the value
|
|
261
263
|
*/
|
|
262
264
|
proto.addYears = function (dateObj, years) {
|
|
263
|
-
return this.addMonths(dateObj, years * 12);
|
|
265
|
+
return (this || date).addMonths(dateObj, years * 12);
|
|
264
266
|
};
|
|
265
267
|
|
|
266
268
|
/**
|
|
@@ -296,7 +298,7 @@ proto.addDays = function (dateObj, days) {
|
|
|
296
298
|
* @returns {Date} a date after adding the value
|
|
297
299
|
*/
|
|
298
300
|
proto.addHours = function (dateObj, hours) {
|
|
299
|
-
return this.addMinutes(dateObj, hours * 60);
|
|
301
|
+
return (this || date).addMinutes(dateObj, hours * 60);
|
|
300
302
|
};
|
|
301
303
|
|
|
302
304
|
/**
|
|
@@ -306,7 +308,7 @@ proto.addHours = function (dateObj, hours) {
|
|
|
306
308
|
* @returns {Date} a date after adding the value
|
|
307
309
|
*/
|
|
308
310
|
proto.addMinutes = function (dateObj, minutes) {
|
|
309
|
-
return this.addSeconds(dateObj, minutes * 60);
|
|
311
|
+
return (this || date).addSeconds(dateObj, minutes * 60);
|
|
310
312
|
};
|
|
311
313
|
|
|
312
314
|
/**
|
|
@@ -316,7 +318,7 @@ proto.addMinutes = function (dateObj, minutes) {
|
|
|
316
318
|
* @returns {Date} a date after adding the value
|
|
317
319
|
*/
|
|
318
320
|
proto.addSeconds = function (dateObj, seconds) {
|
|
319
|
-
return this.addMilliseconds(dateObj, seconds * 1000);
|
|
321
|
+
return (this || date).addMilliseconds(dateObj, seconds * 1000);
|
|
320
322
|
};
|
|
321
323
|
|
|
322
324
|
/**
|
|
@@ -400,7 +402,8 @@ proto.plugin = function (name, plugin) {
|
|
|
400
402
|
}
|
|
401
403
|
};
|
|
402
404
|
|
|
403
|
-
|
|
405
|
+
localized_proto = extend(proto);
|
|
406
|
+
date = extend(proto);
|
|
404
407
|
|
|
405
408
|
/**
|
|
406
409
|
* Changing locale
|
|
@@ -420,8 +423,8 @@ date.locale = function (locale) {
|
|
|
420
423
|
var formatter = extend(_formatter, extension.formatter, true, res);
|
|
421
424
|
var parser = extend(_parser, extension.parser, true, res);
|
|
422
425
|
|
|
423
|
-
date._formatter = formatter;
|
|
424
|
-
date._parser = parser;
|
|
426
|
+
date._formatter = localized_proto._formatter = formatter;
|
|
427
|
+
date._parser = localized_proto._parser = parser;
|
|
425
428
|
|
|
426
429
|
for (var plugin in plugins) {
|
|
427
430
|
date.extend(plugins[plugin]);
|
|
@@ -458,8 +461,10 @@ date.plugin = function (plugin) {
|
|
|
458
461
|
var install = typeof plugin === 'function' ? plugin : date.plugin[plugin];
|
|
459
462
|
|
|
460
463
|
if (install) {
|
|
461
|
-
date.extend(plugins[install(proto)] || {});
|
|
464
|
+
date.extend(plugins[install(proto, localized_proto)] || {});
|
|
462
465
|
}
|
|
463
466
|
};
|
|
464
467
|
|
|
465
|
-
|
|
468
|
+
var date$1 = date;
|
|
469
|
+
|
|
470
|
+
export { date$1 as default };
|