date-and-time 2.1.1 → 2.2.1
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 +25 -9
- package/README.md +12 -25
- package/date-and-time.js +13 -3
- package/date-and-time.min.js +11 -10
- package/esm/date-and-time.es.js +13 -3
- package/esm/date-and-time.es.min.js +10 -10
- package/esm/date-and-time.mjs +13 -3
- package/esm/plugin/timezone.es.js +7 -5
- package/esm/plugin/timezone.mjs +7 -5
- package/package.json +3 -3
- package/plugin/timezone.js +7 -5
package/PLUGINS.md
CHANGED
|
@@ -76,7 +76,7 @@ date.plugin('foobar');
|
|
|
76
76
|
- It adds `timeSpan()` function that calculates the difference of two dates to the library.
|
|
77
77
|
|
|
78
78
|
- [timezone](#timezone)
|
|
79
|
-
- It adds `formatTZ()` and `
|
|
79
|
+
- It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` to the library.
|
|
80
80
|
|
|
81
81
|
- [two-digit-year](#two-digit-year)
|
|
82
82
|
- It adds two-digit year notation to the parser.
|
|
@@ -290,7 +290,7 @@ In these functions can be available some tokens to format the calculation result
|
|
|
290
290
|
|
|
291
291
|
### timezone
|
|
292
292
|
|
|
293
|
-
It adds `formatTZ()` and `
|
|
293
|
+
It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
|
|
294
294
|
|
|
295
295
|
#### formatTZ(dateObj, arg[, timeZone])
|
|
296
296
|
|
|
@@ -299,7 +299,7 @@ It adds `formatTZ()` and `parseTZ()` functions that support `IANA time zone name
|
|
|
299
299
|
- @param {**string**} [timeZone] - output as this time zone
|
|
300
300
|
- @returns {**string**} a formatted string
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
`formatTZ()` is upward compatible with `format()`. Tokens available for `arg` are the same as those for `format()`. If `timeZone` is omitted, this function assumes `timeZone` to be a local time zone and outputs a string. This means that the result is the same as when `format()` is used.
|
|
303
303
|
|
|
304
304
|
#### parseTZ(dateString, arg[, timeZone])
|
|
305
305
|
|
|
@@ -308,7 +308,17 @@ The `formatTZ()` is upward compatible with `format()`. Tokens available here are
|
|
|
308
308
|
- @param {**string**} [timeZone] - input as this time zone
|
|
309
309
|
- @returns {**Date**} a constructed date
|
|
310
310
|
|
|
311
|
-
|
|
311
|
+
`parseTZ()` is upward compatible with `parse()`. Tokens available for `arg` are the same as those for `parse()`. `timeZone` in this function is used as supplemental information. if `dateString` contains a time zone offset value (i.e. -0800, +0900), `timeZone` is not be used. If `dateString` doesn't contain a time zone offset value and `timeZone` is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `parse()` is used.
|
|
312
|
+
|
|
313
|
+
#### transformTZ(dateString, arg1, arg2[, timeZone])
|
|
314
|
+
|
|
315
|
+
- @param {**string**} dateString - a date string
|
|
316
|
+
- @param {**string|Array.\<string\>**} arg1 - a format string or its compiled object
|
|
317
|
+
- @param {**string|Array.\<string\>**} arg2 - a transformed format string or its compiled object
|
|
318
|
+
- @param {**string**} [timeZone] - output as this time zone
|
|
319
|
+
- @returns {**string**} a formatted string
|
|
320
|
+
|
|
321
|
+
`transformTZ()` is upward compatible with `transform()`. `dateString` must itself contain a time zone offset value (i.e. -0800, +0900), otherwise this function assumes it is a local time zone. Tokens available for `arg1` are the same as those for `parse()`, also tokens available for `arg2` are the same as those for `format()`. `timeZone` is a `IANA time zone names`, which is required to output a new formatted string. If it is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `transform()` is used.
|
|
312
322
|
|
|
313
323
|
```javascript
|
|
314
324
|
const date = require('date-and-time');
|
|
@@ -329,16 +339,22 @@ date.parseTZ('Sep 25 2021 4:00:00', 'MMM D YYYY H:mm:ss', 'Pacific/Honolulu');
|
|
|
329
339
|
|
|
330
340
|
// Parses the date string assuming that the time zone is "Europe/London" (UTC+0100).
|
|
331
341
|
date.parseTZ('Sep 25 2021 4:00:00', 'MMM D YYYY H:mm:ss', 'Europe/London'); // 2021-09-25T03:00:00.000Z
|
|
342
|
+
|
|
343
|
+
// Transforms the date string from EST (Eastern Standard Time) to PDT (Pacific Daylight Time).
|
|
344
|
+
date.transformTZ('2021-11-07T03:59:59 UTC-0500', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss UTC[Z]', 'America/Los_Angeles'); // November 7 2021 1:59:59 UTC-0700
|
|
345
|
+
|
|
346
|
+
// Transforms the date string from PDT(Pacific Daylight Time) to JST (Japan Standard Time).
|
|
347
|
+
date.transformTZ('2021-03-14T03:00:00 UTC-0700', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss UTC[Z]', 'Asia/Tokyo'); // March 14 2021 19:00:00 UTC+0900
|
|
332
348
|
```
|
|
333
349
|
|
|
334
350
|
#### Caveats
|
|
335
351
|
|
|
336
352
|
- This plugin uses the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) object to parse `IANA time zone names`. Note that if you use this plugin in older browsers, this may **NOT** be supported there. At least it does not work in IE.
|
|
337
|
-
- If you don't need to use `IANA time zone names`, you should not use this plugin for performance reasons.
|
|
353
|
+
- If you don't need to use `IANA time zone names`, you should not use this plugin for performance reasons. Recommended to use `format()` and `parse()`.
|
|
338
354
|
|
|
339
355
|
#### Start of DST (Daylight Saving Time)
|
|
340
356
|
|
|
341
|
-
For example, in the US, when local standard time is about to reach Sunday, 14 March 2021, `02:00:00` clocks are turned `forward` 1 hour to Sunday, 14 March 2021, `03:00:00` local daylight time instead. Thus
|
|
357
|
+
For example, in the US, when local standard time is about to reach Sunday, 14 March 2021, `02:00:00` clocks are turned `forward` 1 hour to Sunday, 14 March 2021, `03:00:00` local daylight time instead. Thus there is no `02:00:00` to `02:59:59` on 14 March 2021. In such edge cases, `parseTZ()` will parse like this:
|
|
342
358
|
|
|
343
359
|
```javascript
|
|
344
360
|
date.parseTZ('Mar 14 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T09:59:59Z
|
|
@@ -349,16 +365,16 @@ date.parseTZ('Mar 14 2021 3:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles')
|
|
|
349
365
|
|
|
350
366
|
#### End of DST
|
|
351
367
|
|
|
352
|
-
Also, when local daylight time is about to reach Sunday, 7 November 2021, `02:00:00` clocks are turned `backward` 1 hour to Sunday, 7 November 2021, `01:00:00` local standard time instead. Thus
|
|
368
|
+
Also, when local daylight time is about to reach Sunday, 7 November 2021, `02:00:00` clocks are turned `backward` 1 hour to Sunday, 7 November 2021, `01:00:00` local standard time instead. Thus `01:00:00` to `01:59:59` on November 7 2021 is repeated twice. Since there are two possible times here, `parseTZ()` assumes that the time is the former (DST) in order to make the result unique:
|
|
353
369
|
|
|
354
370
|
```javascript
|
|
355
|
-
// The parseTZ() assumes that
|
|
371
|
+
// This time is DST or PST? The parseTZ() always assumes that it is DST.
|
|
356
372
|
date.parseTZ('Nov 7 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-11-07T08:59:59Z
|
|
357
373
|
// This time is already PST.
|
|
358
374
|
date.parseTZ('Nov 7 2021 2:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-11-07T10:00:00Z
|
|
359
375
|
```
|
|
360
376
|
|
|
361
|
-
|
|
377
|
+
In the first example above, if you want `parseTZ()` to parse the time as PST, you need to pass a date string containing the time zone offset value. In this case, it is better to use `parse()` instead:
|
|
362
378
|
|
|
363
379
|
```javascript
|
|
364
380
|
date.parse('Nov 7 2021 1:59:59 -0800', 'MMM D YYYY H:mm:ss Z'); // => 2021-11-07T09:59:59Z
|
package/README.md
CHANGED
|
@@ -24,30 +24,15 @@ npm i date-and-time
|
|
|
24
24
|
|
|
25
25
|
## Recent Changes
|
|
26
26
|
|
|
27
|
-
- 2.
|
|
28
|
-
-
|
|
27
|
+
- 2.2.1
|
|
28
|
+
- Fixed an issue where `parse()` would treat a date-time string containing a UTC time zone (i.e. +0000) as a local time zone when parsing it.
|
|
29
29
|
|
|
30
|
-
- 2.
|
|
31
|
-
-
|
|
30
|
+
- 2.2.0
|
|
31
|
+
- Added `tranformTZ()` to `timezone` plugin. See [PLUGINS.md](./PLUGINS.md) for details.
|
|
32
|
+
- Added `ZZ` token to support time zone values with colon like `-08:00` `+09:00` to `format()` and `parse()`.
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const { format, parse } = require('date-and-time');
|
|
36
|
-
|
|
37
|
-
// These used to be errors in 2.0.x.
|
|
38
|
-
format(new Date(), 'MMM DD YYYY');
|
|
39
|
-
parse('Jan 11 2022', 'MMM DD YYYY');
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
- Added Swedish support.
|
|
43
|
-
|
|
44
|
-
- 2.0.1
|
|
45
|
-
- Fixed a bug that the timezone plugin does not support changing locales.
|
|
46
|
-
|
|
47
|
-
- 2.0.0
|
|
48
|
-
- Fixed a conflict when importing multiple plugins and locales.
|
|
49
|
-
- **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.
|
|
50
|
-
- 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.
|
|
34
|
+
- 2.1.2
|
|
35
|
+
- Fixed an issue where the lib's validation logic would consider an error when a time zone offset value of a date-time string was greater than +12 hours.
|
|
51
36
|
|
|
52
37
|
## Usage
|
|
53
38
|
|
|
@@ -186,7 +171,8 @@ Available tokens and their meanings are as follows:
|
|
|
186
171
|
| SSS | millisecond (high accuracy) | 753, 022 |
|
|
187
172
|
| SS | millisecond (middle accuracy) | 75, 02 |
|
|
188
173
|
| S | millisecond (low accuracy) | 7, 0 |
|
|
189
|
-
| Z |
|
|
174
|
+
| Z | time zone offset value | +0100, -0800 |
|
|
175
|
+
| ZZ | time zone offset value with colon | +01:00, -08:00 |
|
|
190
176
|
|
|
191
177
|
You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.
|
|
192
178
|
|
|
@@ -260,7 +246,8 @@ Available tokens and their meanings are as follows:
|
|
|
260
246
|
| SSS | millisecond (high accuracy) | 753, 022 |
|
|
261
247
|
| SS | millisecond (middle accuracy) | 75, 02 |
|
|
262
248
|
| S | millisecond (low accuracy) | 7, 0 |
|
|
263
|
-
| Z |
|
|
249
|
+
| Z | time zone offset value | +0100, -0800 |
|
|
250
|
+
| ZZ | time zone offset value with colon | +01:00, -08:00 |
|
|
264
251
|
|
|
265
252
|
You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.
|
|
266
253
|
|
|
@@ -291,7 +278,7 @@ if (isNaN(today)) {
|
|
|
291
278
|
|
|
292
279
|
#### Note 2. Input as UTC
|
|
293
280
|
|
|
294
|
-
This function
|
|
281
|
+
This function assumes the `dateString` is a local date-time unless it contains a time zone offset value. Set to true the `utc` option (the 3rd parameter) if it is a UTC date-time.
|
|
295
282
|
|
|
296
283
|
```javascript
|
|
297
284
|
date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
|
package/date-and-time.js
CHANGED
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
var offset = d.getTimezoneOffset() / 0.6 | 0;
|
|
49
49
|
return (offset > 0 ? '-' : '+') + ('000' + Math.abs(offset - (offset % 100 * 0.4 | 0))).slice(-4);
|
|
50
50
|
},
|
|
51
|
+
ZZ: function (d/*, formatString*/) {
|
|
52
|
+
var offset = d.getTimezoneOffset();
|
|
53
|
+
var mod = Math.abs(offset);
|
|
54
|
+
return (offset > 0 ? '-' : '+') + ('0' + (mod / 60 | 0)).slice(-2) + ':' + ('0' + mod % 60).slice(-2);
|
|
55
|
+
},
|
|
51
56
|
post: function (str) { return str; },
|
|
52
57
|
res: _res
|
|
53
58
|
},
|
|
@@ -93,6 +98,10 @@
|
|
|
93
98
|
result.value = (result.value / 100 | 0) * -60 - result.value % 100;
|
|
94
99
|
return result;
|
|
95
100
|
},
|
|
101
|
+
ZZ: function (str/*, formatString */) {
|
|
102
|
+
var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
|
|
103
|
+
return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
|
|
104
|
+
},
|
|
96
105
|
h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
|
|
97
106
|
exec: function (re, str) {
|
|
98
107
|
var result = (re.exec(str) || [''])[0];
|
|
@@ -218,11 +227,12 @@
|
|
|
218
227
|
* @returns {Date} a constructed date
|
|
219
228
|
*/
|
|
220
229
|
proto.parse = function (dateString, arg, utc) {
|
|
221
|
-
var ctx = this || date,
|
|
230
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
231
|
+
dt = ctx.preparse(dateString, pattern);
|
|
222
232
|
|
|
223
233
|
if (ctx.isValid(dt)) {
|
|
224
234
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
225
|
-
if (utc ||
|
|
235
|
+
if (utc || ~ctx._parser.find(pattern, 'ZZ').value) {
|
|
226
236
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
227
237
|
}
|
|
228
238
|
return new Date(dt.Y, dt.M, dt.D, dt.H, dt.m, dt.s, dt.S);
|
|
@@ -244,7 +254,7 @@
|
|
|
244
254
|
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
245
255
|
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
246
256
|
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
247
|
-
dt.Z < -
|
|
257
|
+
dt.Z < -840 || dt.Z > 720
|
|
248
258
|
);
|
|
249
259
|
};
|
|
250
260
|
|
package/date-and-time.min.js
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
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
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)},
|
|
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,
|
|
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/
|
|
10
|
-
b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var
|
|
11
|
-
f.format=function(a,b,
|
|
12
|
-
1,u=b.length,k,q;l<u;l++)if(k=b[l],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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)},ZZ:function(a){a=a.getTimezoneOffset();var b=Math.abs(a);return(0<a?"-":"+")+("0"+(b/60|0)).slice(-2)+":"+("0"+b%60).slice(-2)},post:function(a){return a},
|
|
8
|
+
res:t},x={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)},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,
|
|
9
|
+
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}/,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/
|
|
10
|
+
100|0)-a.value%100;return a},ZZ:function(a){a=/^([\+-])(\d{2}):([0-5]\d)/.exec(a)||["","","",""];return{value:-(60*(a[1]+a[2]|0)+(a[1]+a[3]|0)),length:a[0].length}},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 d=-1,c=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>c&&(d=h,c=l.length);return{value:d,length:c}},pre:function(a){return a},res:t},n=function(a,b,d,c){var h={},g;for(g in a)h[g]=
|
|
11
|
+
a[g];for(g in b||{})!!d^!!h[g]||(h[g]=b[g]);c&&(h.res=c);return h},f={_formatter:w,_parser:x};f.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,d,c=[a];d=b.exec(a);)c[c.length]=d[0];return c};f.format=function(a,b,d){var c=this||e;b="string"===typeof b?c.compile(b):b;var h=a.getTimezoneOffset();a=c.addMinutes(a,d?h:0);c=c._formatter;var g="";a.getTimezoneOffset=function(){return d?0:h};for(var l=1,u=b.length,k;l<u;l++)k=b[l],g+=c[k]?c.post(c[k](a,b[0])):k.replace(/\[(.*)]/,
|
|
12
|
+
"$1");return g};f.preparse=function(a,b){var d=this||e;b="string"===typeof b?d.compile(b):b;var c={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=/\[(.*)]/;d=d._parser;var g=0;a=d.pre(a);for(var l=1,u=b.length,k,q;l<u;l++)if(k=b[l],d[k]){q=d[k](a.slice(g),b[0]);if(!q.length)break;g+=q.length;c[q.token||k.charAt(0)]=q.value;c._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}c.H=
|
|
13
|
+
c.H||d.h12(c.h,c.A);c._index=g;c._length=a.length;return c};f.parse=function(a,b,d){var c=this||e;b="string"===typeof b?c.compile(b):b;a=c.preparse(a,b);return c.isValid(a)?(a.M-=100>a.Y?22801:1,d||~c._parser.find(b,"ZZ").value?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)};f.isValid=function(a,b){var d=this||e;a="string"===typeof a?d.preparse(a,b):a;d=[31,28+d.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>
|
|
14
|
+
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>d||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,d,c){let h=this||e;return h.format(h.parse(a,b),d,c)};f.addYears=function(a,b){return(this||e).addMonths(a,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,
|
|
15
|
+
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 d=a.getTime()-b.getTime();return{toMilliseconds:function(){return d},toSeconds:function(){return d/1E3},toMinutes:function(){return d/6E4},toHours:function(){return d/36E5},toDays:function(){return d/864E5}}};f.isLeapYear=function(a){return!(a%
|
|
16
|
+
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]||{},d=n(t,b.res,!0);a=n(w,b.formatter,!0,d);b=n(x,b.parser,!0,d);e._formatter=v._formatter=a;e._parser=v._parser=b;for(var c in m)e.extend(m[c]);return r};e.extend=function(a){var b=n(e._parser.res,a.res),d=a.extender||
|
|
17
|
+
{};e._formatter=n(e._formatter,a.formatter,!1,b);e._parser=n(e._parser,a.parser,!1,b);for(var c in d)e[c]||(e[c]=d[c])};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
|
@@ -42,6 +42,11 @@ var locales = {},
|
|
|
42
42
|
var offset = d.getTimezoneOffset() / 0.6 | 0;
|
|
43
43
|
return (offset > 0 ? '-' : '+') + ('000' + Math.abs(offset - (offset % 100 * 0.4 | 0))).slice(-4);
|
|
44
44
|
},
|
|
45
|
+
ZZ: function (d/*, formatString*/) {
|
|
46
|
+
var offset = d.getTimezoneOffset();
|
|
47
|
+
var mod = Math.abs(offset);
|
|
48
|
+
return (offset > 0 ? '-' : '+') + ('0' + (mod / 60 | 0)).slice(-2) + ':' + ('0' + mod % 60).slice(-2);
|
|
49
|
+
},
|
|
45
50
|
post: function (str) { return str; },
|
|
46
51
|
res: _res
|
|
47
52
|
},
|
|
@@ -87,6 +92,10 @@ var locales = {},
|
|
|
87
92
|
result.value = (result.value / 100 | 0) * -60 - result.value % 100;
|
|
88
93
|
return result;
|
|
89
94
|
},
|
|
95
|
+
ZZ: function (str/*, formatString */) {
|
|
96
|
+
var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
|
|
97
|
+
return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
|
|
98
|
+
},
|
|
90
99
|
h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
|
|
91
100
|
exec: function (re, str) {
|
|
92
101
|
var result = (re.exec(str) || [''])[0];
|
|
@@ -212,11 +221,12 @@ proto.preparse = function (dateString, arg) {
|
|
|
212
221
|
* @returns {Date} a constructed date
|
|
213
222
|
*/
|
|
214
223
|
proto.parse = function (dateString, arg, utc) {
|
|
215
|
-
var ctx = this || date,
|
|
224
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
225
|
+
dt = ctx.preparse(dateString, pattern);
|
|
216
226
|
|
|
217
227
|
if (ctx.isValid(dt)) {
|
|
218
228
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
219
|
-
if (utc ||
|
|
229
|
+
if (utc || ~ctx._parser.find(pattern, 'ZZ').value) {
|
|
220
230
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
221
231
|
}
|
|
222
232
|
return new Date(dt.Y, dt.M, dt.D, dt.H, dt.m, dt.s, dt.S);
|
|
@@ -238,7 +248,7 @@ proto.isValid = function (arg1, arg2) {
|
|
|
238
248
|
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
239
249
|
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
240
250
|
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
241
|
-
dt.Z < -
|
|
251
|
+
dt.Z < -840 || dt.Z > 720
|
|
242
252
|
);
|
|
243
253
|
};
|
|
244
254
|
|
|
@@ -4,15 +4,15 @@
|
|
|
4
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: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,
|
|
8
|
-
|
|
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},
|
|
10
|
-
res:n};function t(a,b,c
|
|
11
|
-
u.format=function(a,b,
|
|
12
|
-
u.preparse=function(a,b){var
|
|
13
|
-
|
|
14
|
-
u.isValid=function(a,b){var
|
|
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)},ZZ:function(a){a=a.getTimezoneOffset();var b=Math.abs(a);return(0<a?"-":"+")+("0"+(b/60|0)).slice(-2)+":"+("0"+b%60).slice(-2)},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,
|
|
8
|
+
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?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,
|
|
9
|
+
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},ZZ:function(a){a=/^([\+-])(\d{2}):([0-5]\d)/.exec(a)||["","","",""];return{value:-(60*(a[1]+a[2]|0)+(a[1]+a[3]|0)),length:a[0].length}},h12:function(a,
|
|
10
|
+
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 d=-1,c=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>c&&(d=h,c=l.length);return{value:d,length:c}},pre:function(a){return a},res:n};function t(a,b,d,c){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!d^!!h[g]||(h[g]=b[g]);c&&(h.res=c);return h}var u={_formatter:q,_parser:r},w,x;
|
|
11
|
+
u.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,d,c=[a];d=b.exec(a);)c[c.length]=d[0];return c};u.format=function(a,b,d){var c=this||x;b="string"===typeof b?c.compile(b):b;var h=a.getTimezoneOffset();a=c.addMinutes(a,d?h:0);c=c._formatter;var g="";a.getTimezoneOffset=function(){return d?0:h};for(var l=1,v=b.length,k;l<v;l++)k=b[l],g+=c[k]?c.post(c[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};
|
|
12
|
+
u.preparse=function(a,b){var d=this||x;b="string"===typeof b?d.compile(b):b;var c={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=/\[(.*)]/;d=d._parser;var g=0;a=d.pre(a);for(var l=1,v=b.length,k,p;l<v;l++)if(k=b[l],d[k]){p=d[k](a.slice(g),b[0]);if(!p.length)break;g+=p.length;c[p.token||k.charAt(0)]=p.value;c._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}c.H=c.H||d.h12(c.h,
|
|
13
|
+
c.A);c._index=g;c._length=a.length;return c};u.parse=function(a,b,d){var c=this||x;b="string"===typeof b?c.compile(b):b;a=c.preparse(a,b);return c.isValid(a)?(a.M-=100>a.Y?22801:1,d||~c._parser.find(b,"ZZ").value?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 d=this||x;a="string"===typeof a?d.preparse(a,b):a;d=[31,28+d.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>d||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,d,c){let h=this||x;return h.format(h.parse(a,b),d,c)};u.addYears=function(a,b){return(this||x).addMonths(a,12*b)};
|
|
15
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
|
|
17
|
-
x.locale=function(a){a="function"===typeof a?a:x.locale[a];if(!a)return m;m=a(u);var b=e[m]||{},
|
|
16
|
+
u.subtract=function(a,b){var d=a.getTime()-b.getTime();return{toMilliseconds:function(){return d},toSeconds:function(){return d/1E3},toMinutes:function(){return d/6E4},toHours:function(){return d/36E5},toDays:function(){return d/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]||{},d=t(n,b.res,!0);a=t(q,b.formatter,!0,d);b=t(r,b.parser,!0,d);x._formatter=w._formatter=a;x._parser=w._parser=b;for(var c in f)x.extend(f[c]);return m};x.extend=function(a){var b=t(x._parser.res,a.res),d=a.extender||{};x._formatter=t(x._formatter,a.formatter,!1,b);x._parser=t(x._parser,a.parser,!1,b);for(var c in d)x[c]||(x[c]=d[c])};
|
|
18
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
|
@@ -42,6 +42,11 @@ var locales = {},
|
|
|
42
42
|
var offset = d.getTimezoneOffset() / 0.6 | 0;
|
|
43
43
|
return (offset > 0 ? '-' : '+') + ('000' + Math.abs(offset - (offset % 100 * 0.4 | 0))).slice(-4);
|
|
44
44
|
},
|
|
45
|
+
ZZ: function (d/*, formatString*/) {
|
|
46
|
+
var offset = d.getTimezoneOffset();
|
|
47
|
+
var mod = Math.abs(offset);
|
|
48
|
+
return (offset > 0 ? '-' : '+') + ('0' + (mod / 60 | 0)).slice(-2) + ':' + ('0' + mod % 60).slice(-2);
|
|
49
|
+
},
|
|
45
50
|
post: function (str) { return str; },
|
|
46
51
|
res: _res
|
|
47
52
|
},
|
|
@@ -87,6 +92,10 @@ var locales = {},
|
|
|
87
92
|
result.value = (result.value / 100 | 0) * -60 - result.value % 100;
|
|
88
93
|
return result;
|
|
89
94
|
},
|
|
95
|
+
ZZ: function (str/*, formatString */) {
|
|
96
|
+
var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
|
|
97
|
+
return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
|
|
98
|
+
},
|
|
90
99
|
h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },
|
|
91
100
|
exec: function (re, str) {
|
|
92
101
|
var result = (re.exec(str) || [''])[0];
|
|
@@ -212,11 +221,12 @@ proto.preparse = function (dateString, arg) {
|
|
|
212
221
|
* @returns {Date} a constructed date
|
|
213
222
|
*/
|
|
214
223
|
proto.parse = function (dateString, arg, utc) {
|
|
215
|
-
var ctx = this || date,
|
|
224
|
+
var ctx = this || date, pattern = typeof arg === 'string' ? ctx.compile(arg) : arg,
|
|
225
|
+
dt = ctx.preparse(dateString, pattern);
|
|
216
226
|
|
|
217
227
|
if (ctx.isValid(dt)) {
|
|
218
228
|
dt.M -= dt.Y < 100 ? 22801 : 1; // 22801 = 1900 * 12 + 1
|
|
219
|
-
if (utc ||
|
|
229
|
+
if (utc || ~ctx._parser.find(pattern, 'ZZ').value) {
|
|
220
230
|
return new Date(Date.UTC(dt.Y, dt.M, dt.D, dt.H, dt.m + dt.Z, dt.s, dt.S));
|
|
221
231
|
}
|
|
222
232
|
return new Date(dt.Y, dt.M, dt.D, dt.H, dt.m, dt.s, dt.S);
|
|
@@ -238,7 +248,7 @@ proto.isValid = function (arg1, arg2) {
|
|
|
238
248
|
dt._index < 1 || dt._length < 1 || dt._index - dt._length || dt._match < 1 ||
|
|
239
249
|
dt.Y < 1 || dt.Y > 9999 || dt.M < 1 || dt.M > 12 || dt.D < 1 || dt.D > last ||
|
|
240
250
|
dt.H < 0 || dt.H > 23 || dt.m < 0 || dt.m > 59 || dt.s < 0 || dt.s > 59 || dt.S < 0 || dt.S > 999 ||
|
|
241
|
-
dt.Z < -
|
|
251
|
+
dt.Z < -840 || dt.Z > 720
|
|
242
252
|
);
|
|
243
253
|
};
|
|
244
254
|
|
|
@@ -30,10 +30,8 @@ var plugin = function (date, localized_date) {
|
|
|
30
30
|
var pattern2 = typeof arg === 'string' ? date.compile(arg) : arg;
|
|
31
31
|
var dateObj = localized_date.parse(dateString, pattern2, true);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return dateObj;
|
|
36
|
-
}
|
|
33
|
+
if (~date._parser.find(pattern2, 'ZZ').value) {
|
|
34
|
+
return dateObj;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
options.timeZone = timeZone;
|
|
@@ -58,13 +56,17 @@ var plugin = function (date, localized_date) {
|
|
|
58
56
|
}
|
|
59
57
|
return NaN;
|
|
60
58
|
};
|
|
59
|
+
var transformTZ = function (dateString, arg1, arg2, timeZone) {
|
|
60
|
+
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone);
|
|
61
|
+
};
|
|
61
62
|
|
|
62
63
|
var name = 'timezone';
|
|
63
64
|
|
|
64
65
|
date.plugin(name, {
|
|
65
66
|
extender: {
|
|
66
67
|
formatTZ: formatTZ,
|
|
67
|
-
parseTZ: parseTZ
|
|
68
|
+
parseTZ: parseTZ,
|
|
69
|
+
transformTZ: transformTZ
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
return name;
|
package/esm/plugin/timezone.mjs
CHANGED
|
@@ -30,10 +30,8 @@ var plugin = function (date, localized_date) {
|
|
|
30
30
|
var pattern2 = typeof arg === 'string' ? date.compile(arg) : arg;
|
|
31
31
|
var dateObj = localized_date.parse(dateString, pattern2, true);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return dateObj;
|
|
36
|
-
}
|
|
33
|
+
if (~date._parser.find(pattern2, 'ZZ').value) {
|
|
34
|
+
return dateObj;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
options.timeZone = timeZone;
|
|
@@ -58,13 +56,17 @@ var plugin = function (date, localized_date) {
|
|
|
58
56
|
}
|
|
59
57
|
return NaN;
|
|
60
58
|
};
|
|
59
|
+
var transformTZ = function (dateString, arg1, arg2, timeZone) {
|
|
60
|
+
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone);
|
|
61
|
+
};
|
|
61
62
|
|
|
62
63
|
var name = 'timezone';
|
|
63
64
|
|
|
64
65
|
date.plugin(name, {
|
|
65
66
|
extender: {
|
|
66
67
|
formatTZ: formatTZ,
|
|
67
|
-
parseTZ: parseTZ
|
|
68
|
+
parseTZ: parseTZ,
|
|
69
|
+
transformTZ: transformTZ
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
return name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-and-time",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "A Minimalist DateTime utility for Node.js and the browser",
|
|
5
5
|
"main": "date-and-time.js",
|
|
6
6
|
"module": "esm/date-and-time.es.js",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@ampproject/rollup-plugin-closure-compiler": "^0.27.0",
|
|
48
48
|
"expect.js": "^0.3.1",
|
|
49
|
-
"mocha": "^9.2.
|
|
49
|
+
"mocha": "^9.2.1",
|
|
50
50
|
"mocha-headless-chrome": "^4.0.0",
|
|
51
|
-
"rollup": "^2.
|
|
51
|
+
"rollup": "^2.68.0"
|
|
52
52
|
}
|
|
53
53
|
}
|
package/plugin/timezone.js
CHANGED
|
@@ -36,10 +36,8 @@
|
|
|
36
36
|
var pattern2 = typeof arg === 'string' ? date.compile(arg) : arg;
|
|
37
37
|
var dateObj = localized_date.parse(dateString, pattern2, true);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return dateObj;
|
|
42
|
-
}
|
|
39
|
+
if (~date._parser.find(pattern2, 'ZZ').value) {
|
|
40
|
+
return dateObj;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
options.timeZone = timeZone;
|
|
@@ -64,13 +62,17 @@
|
|
|
64
62
|
}
|
|
65
63
|
return NaN;
|
|
66
64
|
};
|
|
65
|
+
var transformTZ = function (dateString, arg1, arg2, timeZone) {
|
|
66
|
+
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone);
|
|
67
|
+
};
|
|
67
68
|
|
|
68
69
|
var name = 'timezone';
|
|
69
70
|
|
|
70
71
|
date.plugin(name, {
|
|
71
72
|
extender: {
|
|
72
73
|
formatTZ: formatTZ,
|
|
73
|
-
parseTZ: parseTZ
|
|
74
|
+
parseTZ: parseTZ,
|
|
75
|
+
transformTZ: transformTZ
|
|
74
76
|
}
|
|
75
77
|
});
|
|
76
78
|
return name;
|