date-and-time 3.5.0 → 3.6.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
@@ -381,18 +381,20 @@ date.transformTZ('2021-03-14T03:00:00 UTC-0700', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z',
381
381
 
382
382
  #### Start of DST (Daylight Saving Time)
383
383
 
384
- 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:
384
+ For example, in the US, when local standard time is about to reach `02:00:00` on Sunday, 14 March 2021, the clocks are set `forward` by 1 hour to `03:00:00` local daylight time instead. As a result, the time from `02:00:00` to `02:59:59` on 14 March 2021 does not exist. In such edge cases, `parseTZ()` will handle the case in the following way:
385
385
 
386
386
  ```javascript
387
387
  date.parseTZ('Mar 14 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T09:59:59Z
388
- date.parseTZ('Mar 14 2021 2:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => NaN
389
- date.parseTZ('Mar 14 2021 2:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => NaN
390
388
  date.parseTZ('Mar 14 2021 3:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T10:00:00Z
389
+
390
+ // These times don't actually exist, but parseTZ() will handle as follows:
391
+ date.parseTZ('Mar 14 2021 2:00:00', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T10:00:00Z
392
+ date.parseTZ('Mar 14 2021 2:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-03-14T10:59:59Z
391
393
  ```
392
394
 
393
395
  #### End of DST
394
396
 
395
- 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:
397
+ Also, when local daylight time is about to reach `02:00:00` on Sunday, 7 November 2021, the clocks are set `back` by 1 hour to `01:00:00` local standard time instead. As a result, the time from `01:00:00` to `01:59:59` on 7 November 2021 occurs twice. Because this time period happens twice, `parseTZ()` assumes that the time is the earlier one (during DST) in order to make the result unique:
396
398
 
397
399
  ```javascript
398
400
  // This time is DST or PST? The parseTZ() always assumes that it is DST.
package/README.md CHANGED
@@ -25,6 +25,10 @@ npm i date-and-time
25
25
 
26
26
  ## Recent Changes
27
27
 
28
+ - 3.6.0
29
+ - In `parseTZ()`, enabled parsing of the missing hour during the transition from standard time to daylight saving time into a Date type.
30
+ - In `format()` with the `z` token, fixed an issue where some short time zone names were incorrect.
31
+
28
32
  - 3.5.0
29
33
  - Added `addYearsTZ()`, `addMonthsTZ()`, and `addDaysTZ()` to the `timezone` plugin.
30
34
  - Revised the approach to adding time and removed the third parameter from `addHours()`, `addMinutes()`, `addSeconds()`, and `addMilliseconds()`.
@@ -32,10 +36,6 @@ npm i date-and-time
32
36
  - 3.4.1
33
37
  - Fixed an issue where `formatTZ()` would output 0:00 as 24:00 in 24-hour format in Node.js.
34
38
 
35
- - 3.4.0
36
- - Added `zz` (time zone name) and `z` (time zone name abbreviation) tokens to the `timezone` plugin.
37
- - Fixed an issue where token extensions by other plugins were not reflected in functions provided by the `timezone` plugin.
38
-
39
39
  ## Usage
40
40
 
41
41
  - ES Modules:
@@ -69,6 +69,16 @@ import date from '/path/to/date-and-time.es.min.js';
69
69
  ### Note
70
70
 
71
71
  - If you want to use ES Modules in Node.js without the transpiler, you need to add `"type": "module"` in your `package.json` or change your file extension from `.js` to `.mjs`.
72
+ - If you are using TypeScript and having trouble building, please ensure that the following settings in the `compilerOptions` of your `tsconfig.json` are set to `true`.
73
+
74
+ ```json
75
+ {
76
+ "compilerOptions": {
77
+ "allowSyntheticDefaultImports": true,
78
+ "esModuleInterop": true
79
+ }
80
+ }
81
+ ```
72
82
 
73
83
  ## API
74
84
 
@@ -455,7 +455,7 @@ var plugin = function (proto, date) {
455
455
  'Alaska Daylight Time': 'AKDT', 'Alaska Standard Time': 'AKST', 'Almaty Standard Time': 'ALMT',
456
456
  'Almaty Summer Time': 'ALMST', 'Amazon Standard Time': 'AMT', 'Amazon Summer Time': 'AMST',
457
457
  'Anadyr Standard Time': 'ANAT', 'Anadyr Summer Time': 'ANAST', 'Apia Daylight Time': 'WSDT',
458
- 'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTT',
458
+ 'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTST',
459
459
  'Aqtobe Standard Time': 'AQTT', 'Aqtobe Summer Time': 'AQST', 'Arabian Daylight Time': 'ADT',
460
460
  'Arabian Standard Time': 'AST', 'Argentina Standard Time': 'ART', 'Argentina Summer Time': 'ARST',
461
461
  'Armenia Standard Time': 'AMT', 'Armenia Summer Time': 'AMST', 'Atlantic Daylight Time': 'ADT',
@@ -471,19 +471,18 @@ var plugin = function (proto, date) {
471
471
  'Central Indonesia Time': 'WITA', 'Central Standard Time': 'CST', 'Chamorro Standard Time': 'ChST',
472
472
  'Chatham Daylight Time': 'CHADT', 'Chatham Standard Time': 'CHAST', 'Chile Standard Time': 'CLT',
473
473
  'Chile Summer Time': 'CLST', 'China Daylight Time': 'CDT', 'China Standard Time': 'CST',
474
- 'Choibalsan Standard Time': 'CHOT', 'Choibalsan Summer Time': 'CHOST', 'Christmas Island Time': 'CXT',
475
- 'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT', 'Colombia Standard Time': 'COT',
476
- 'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST', 'Cook Islands Standard Time': 'CKT',
477
- 'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT', 'Cuba Standard Time': 'CST',
478
- 'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT', 'East Africa Time': 'EAT',
479
- 'East Greenland Standard Time': 'EGST', 'East Greenland Summer Time': 'EGST', 'East Kazakhstan Time': 'ALMT',
480
- 'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST', 'Easter Island Summer Time': 'EASST',
481
- 'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET', 'Eastern European Summer Time': 'EEST',
482
- 'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST', 'Ecuador Time': 'ECT',
483
- 'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT', 'Fernando de Noronha Standard Time': 'FNT',
484
- 'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT', 'Fiji Summer Time': 'FJST',
485
- 'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT', 'Further-eastern European Time': 'FET',
486
- 'GMT': 'GMT', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT',
474
+ 'Christmas Island Time': 'CXT', 'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT',
475
+ 'Colombia Standard Time': 'COT', 'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST',
476
+ 'Cook Islands Standard Time': 'CKT', 'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT',
477
+ 'Cuba Standard Time': 'CST', 'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT',
478
+ 'East Africa Time': 'EAT', 'East Greenland Standard Time': 'EGT', 'East Greenland Summer Time': 'EGST',
479
+ 'East Kazakhstan Time': 'ALMT', 'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST',
480
+ 'Easter Island Summer Time': 'EASST', 'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET',
481
+ 'Eastern European Summer Time': 'EEST', 'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST',
482
+ 'Ecuador Time': 'ECT', 'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT',
483
+ 'Fernando de Noronha Standard Time': 'FNT', 'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT',
484
+ 'Fiji Summer Time': 'FJST', 'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT',
485
+ 'Further-eastern European Time': 'FET', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT',
487
486
  'Georgia Standard Time': 'GET', 'Georgia Summer Time': 'GEST', 'Gilbert Islands Time': 'GILT',
488
487
  'Greenwich Mean Time': 'GMT', 'Guam Standard Time': 'ChST', 'Gulf Standard Time': 'GST',
489
488
  'Guyana Time': 'GYT', 'Hawaii-Aleutian Daylight Time': 'HADT', 'Hawaii-Aleutian Standard Time': 'HAST',
@@ -495,7 +494,7 @@ var plugin = function (proto, date) {
495
494
  'Korean Daylight Time': 'KDT', 'Korean Standard Time': 'KST', 'Kosrae Time': 'KOST',
496
495
  'Krasnoyarsk Standard Time': 'KRAT', 'Krasnoyarsk Summer Time': 'KRAST', 'Kyrgyzstan Time': 'KGT',
497
496
  'Lanka Time': 'LKT', 'Line Islands Time': 'LINT', 'Lord Howe Daylight Time': 'LHDT',
498
- 'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDST',
497
+ 'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDT',
499
498
  'Magadan Standard Time': 'MAGT', 'Magadan Summer Time': 'MAGST', 'Malaysia Time': 'MYT',
500
499
  'Maldives Time': 'MVT', 'Marquesas Time': 'MART', 'Marshall Islands Time': 'MHT',
501
500
  'Mauritius Standard Time': 'MUT', 'Mauritius Summer Time': 'MUST', 'Mawson Time': 'MAWT',
@@ -508,7 +507,7 @@ var plugin = function (proto, date) {
508
507
  'North Mariana Islands Time': 'ChST', 'Novosibirsk Standard Time': 'NOVT', 'Novosibirsk Summer Time': 'NOVST',
509
508
  'Omsk Standard Time': 'OMST', 'Omsk Summer Time': 'OMSST', 'Pacific Daylight Time': 'PDT',
510
509
  'Pacific Standard Time': 'PST', 'Pakistan Standard Time': 'PKT', 'Pakistan Summer Time': 'PKST',
511
- 'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYST',
510
+ 'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYT',
512
511
  'Paraguay Summer Time': 'PYST', 'Peru Standard Time': 'PET', 'Peru Summer Time': 'PEST',
513
512
  'Petropavlovsk-Kamchatski Standard Time': 'PETT', 'Petropavlovsk-Kamchatski Summer Time': 'PETST', 'Philippine Standard Time': 'PST',
514
513
  'Philippine Summer Time': 'PHST', 'Phoenix Islands Time': 'PHOT', 'Pitcairn Time': 'PIT',
@@ -519,7 +518,7 @@ var plugin = function (proto, date) {
519
518
  'Singapore Standard Time': 'SGT', 'Solomon Islands Time': 'SBT', 'South Africa Standard Time': 'SAST',
520
519
  'South Georgia Time': 'GST', 'St. Pierre & Miquelon Daylight Time': 'PMDT', 'St. Pierre & Miquelon Standard Time': 'PMST',
521
520
  'Suriname Time': 'SRT', 'Syowa Time': 'SYOT', 'Tahiti Time': 'TAHT',
522
- 'Taipei Daylight Time': 'TDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT',
521
+ 'Taipei Daylight Time': 'CDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT',
523
522
  'Tokelau Time': 'TKT', 'Tonga Standard Time': 'TOT', 'Tonga Summer Time': 'TOST',
524
523
  'Turkmenistan Standard Time': 'TMT', 'Tuvalu Time': 'TVT', 'Ulaanbaatar Standard Time': 'ULAT',
525
524
  'Ulaanbaatar Summer Time': 'ULAST', 'Uruguay Standard Time': 'UYT', 'Uruguay Summer Time': 'UYST',
@@ -607,7 +606,7 @@ var plugin = function (proto, date) {
607
606
  };
608
607
  var parseTZ = function (arg1, arg2, timeZone) {
609
608
  var pattern = typeof arg2 === 'string' ? date.compile(arg2) : arg2;
610
- var dateObj = typeof arg1 === 'string' ? date.parse(arg1, pattern, !!timeZone) : arg1;
609
+ var time = typeof arg1 === 'string' ? date.parse(arg1, pattern, !!timeZone).getTime() : arg1;
611
610
  var hasZ = function (array) {
612
611
  for (var i = 1, len = array.length; i < len; i++) {
613
612
  if (!array[i].indexOf('Z')) {
@@ -617,8 +616,8 @@ var plugin = function (proto, date) {
617
616
  return false;
618
617
  };
619
618
 
620
- if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC') {
621
- return dateObj;
619
+ if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC' || isNaN(time)) {
620
+ return new Date(time);
622
621
  }
623
622
 
624
623
  var getOffset = function (timeZoneName) {
@@ -631,17 +630,17 @@ var plugin = function (proto, date) {
631
630
  return Array.isArray(value) ? value : [];
632
631
  };
633
632
 
634
- var dateString2 = getDateTimeFormat('UTC').format(dateObj);
635
- var dateTimeFormat = getDateTimeFormat(timeZone);
633
+ var utc = getDateTimeFormat('UTC');
634
+ var tz = getDateTimeFormat(timeZone);
636
635
  var offset = getOffset(timeZone);
637
- var comparer = function (d) {
638
- return dateString2 === dateTimeFormat.format(d);
639
- };
640
636
 
641
- for (var j = 0, len2 = offset.length; j < len2; j++) {
642
- var d = dateObj.getTime() - offset[j] * 1000;
643
- if (comparer(d)) {
644
- return new Date(d);
637
+ for (var i = 0; i < 2; i++) {
638
+ var targetString = utc.format(time - i * 24 * 60 * 60 * 1000);
639
+
640
+ for (var j = 0, len = offset.length; j < len; j++) {
641
+ if (tz.format(time - (offset[j] + i * 24 * 60 * 60) * 1000) === targetString) {
642
+ return new Date(time - offset[j] * 1000);
643
+ }
645
644
  }
646
645
  }
647
646
  return new Date(NaN);
@@ -670,7 +669,7 @@ var plugin = function (proto, date) {
670
669
  var parts = formatToParts(getDateTimeFormat(timeZone), dateObj);
671
670
 
672
671
  parts.month += months;
673
- var dateObj2 = parseTZ(new Date(getTimeFromParts(normalizeDateParts(parts, true))), [], timeZone);
672
+ var dateObj2 = parseTZ(getTimeFromParts(normalizeDateParts(parts, true)), [], timeZone);
674
673
 
675
674
  return isNaN(dateObj2.getTime()) ? date.addMonths(dateObj, months, true) : dateObj2;
676
675
  };
@@ -678,7 +677,7 @@ var plugin = function (proto, date) {
678
677
  var parts = formatToParts(getDateTimeFormat(timeZone), dateObj);
679
678
 
680
679
  parts.day += days;
681
- var dateObj2 = parseTZ(new Date(getTimeFromParts(normalizeDateParts(parts, false))), [], timeZone);
680
+ var dateObj2 = parseTZ(getTimeFromParts(normalizeDateParts(parts, false)), [], timeZone);
682
681
 
683
682
  return isNaN(dateObj2.getTime()) ? date.addDays(dateObj, days, true) : dateObj2;
684
683
  };
@@ -455,7 +455,7 @@ var plugin = function (proto, date) {
455
455
  'Alaska Daylight Time': 'AKDT', 'Alaska Standard Time': 'AKST', 'Almaty Standard Time': 'ALMT',
456
456
  'Almaty Summer Time': 'ALMST', 'Amazon Standard Time': 'AMT', 'Amazon Summer Time': 'AMST',
457
457
  'Anadyr Standard Time': 'ANAT', 'Anadyr Summer Time': 'ANAST', 'Apia Daylight Time': 'WSDT',
458
- 'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTT',
458
+ 'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTST',
459
459
  'Aqtobe Standard Time': 'AQTT', 'Aqtobe Summer Time': 'AQST', 'Arabian Daylight Time': 'ADT',
460
460
  'Arabian Standard Time': 'AST', 'Argentina Standard Time': 'ART', 'Argentina Summer Time': 'ARST',
461
461
  'Armenia Standard Time': 'AMT', 'Armenia Summer Time': 'AMST', 'Atlantic Daylight Time': 'ADT',
@@ -471,19 +471,18 @@ var plugin = function (proto, date) {
471
471
  'Central Indonesia Time': 'WITA', 'Central Standard Time': 'CST', 'Chamorro Standard Time': 'ChST',
472
472
  'Chatham Daylight Time': 'CHADT', 'Chatham Standard Time': 'CHAST', 'Chile Standard Time': 'CLT',
473
473
  'Chile Summer Time': 'CLST', 'China Daylight Time': 'CDT', 'China Standard Time': 'CST',
474
- 'Choibalsan Standard Time': 'CHOT', 'Choibalsan Summer Time': 'CHOST', 'Christmas Island Time': 'CXT',
475
- 'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT', 'Colombia Standard Time': 'COT',
476
- 'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST', 'Cook Islands Standard Time': 'CKT',
477
- 'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT', 'Cuba Standard Time': 'CST',
478
- 'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT', 'East Africa Time': 'EAT',
479
- 'East Greenland Standard Time': 'EGST', 'East Greenland Summer Time': 'EGST', 'East Kazakhstan Time': 'ALMT',
480
- 'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST', 'Easter Island Summer Time': 'EASST',
481
- 'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET', 'Eastern European Summer Time': 'EEST',
482
- 'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST', 'Ecuador Time': 'ECT',
483
- 'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT', 'Fernando de Noronha Standard Time': 'FNT',
484
- 'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT', 'Fiji Summer Time': 'FJST',
485
- 'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT', 'Further-eastern European Time': 'FET',
486
- 'GMT': 'GMT', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT',
474
+ 'Christmas Island Time': 'CXT', 'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT',
475
+ 'Colombia Standard Time': 'COT', 'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST',
476
+ 'Cook Islands Standard Time': 'CKT', 'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT',
477
+ 'Cuba Standard Time': 'CST', 'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT',
478
+ 'East Africa Time': 'EAT', 'East Greenland Standard Time': 'EGT', 'East Greenland Summer Time': 'EGST',
479
+ 'East Kazakhstan Time': 'ALMT', 'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST',
480
+ 'Easter Island Summer Time': 'EASST', 'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET',
481
+ 'Eastern European Summer Time': 'EEST', 'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST',
482
+ 'Ecuador Time': 'ECT', 'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT',
483
+ 'Fernando de Noronha Standard Time': 'FNT', 'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT',
484
+ 'Fiji Summer Time': 'FJST', 'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT',
485
+ 'Further-eastern European Time': 'FET', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT',
487
486
  'Georgia Standard Time': 'GET', 'Georgia Summer Time': 'GEST', 'Gilbert Islands Time': 'GILT',
488
487
  'Greenwich Mean Time': 'GMT', 'Guam Standard Time': 'ChST', 'Gulf Standard Time': 'GST',
489
488
  'Guyana Time': 'GYT', 'Hawaii-Aleutian Daylight Time': 'HADT', 'Hawaii-Aleutian Standard Time': 'HAST',
@@ -495,7 +494,7 @@ var plugin = function (proto, date) {
495
494
  'Korean Daylight Time': 'KDT', 'Korean Standard Time': 'KST', 'Kosrae Time': 'KOST',
496
495
  'Krasnoyarsk Standard Time': 'KRAT', 'Krasnoyarsk Summer Time': 'KRAST', 'Kyrgyzstan Time': 'KGT',
497
496
  'Lanka Time': 'LKT', 'Line Islands Time': 'LINT', 'Lord Howe Daylight Time': 'LHDT',
498
- 'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDST',
497
+ 'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDT',
499
498
  'Magadan Standard Time': 'MAGT', 'Magadan Summer Time': 'MAGST', 'Malaysia Time': 'MYT',
500
499
  'Maldives Time': 'MVT', 'Marquesas Time': 'MART', 'Marshall Islands Time': 'MHT',
501
500
  'Mauritius Standard Time': 'MUT', 'Mauritius Summer Time': 'MUST', 'Mawson Time': 'MAWT',
@@ -508,7 +507,7 @@ var plugin = function (proto, date) {
508
507
  'North Mariana Islands Time': 'ChST', 'Novosibirsk Standard Time': 'NOVT', 'Novosibirsk Summer Time': 'NOVST',
509
508
  'Omsk Standard Time': 'OMST', 'Omsk Summer Time': 'OMSST', 'Pacific Daylight Time': 'PDT',
510
509
  'Pacific Standard Time': 'PST', 'Pakistan Standard Time': 'PKT', 'Pakistan Summer Time': 'PKST',
511
- 'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYST',
510
+ 'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYT',
512
511
  'Paraguay Summer Time': 'PYST', 'Peru Standard Time': 'PET', 'Peru Summer Time': 'PEST',
513
512
  'Petropavlovsk-Kamchatski Standard Time': 'PETT', 'Petropavlovsk-Kamchatski Summer Time': 'PETST', 'Philippine Standard Time': 'PST',
514
513
  'Philippine Summer Time': 'PHST', 'Phoenix Islands Time': 'PHOT', 'Pitcairn Time': 'PIT',
@@ -519,7 +518,7 @@ var plugin = function (proto, date) {
519
518
  'Singapore Standard Time': 'SGT', 'Solomon Islands Time': 'SBT', 'South Africa Standard Time': 'SAST',
520
519
  'South Georgia Time': 'GST', 'St. Pierre & Miquelon Daylight Time': 'PMDT', 'St. Pierre & Miquelon Standard Time': 'PMST',
521
520
  'Suriname Time': 'SRT', 'Syowa Time': 'SYOT', 'Tahiti Time': 'TAHT',
522
- 'Taipei Daylight Time': 'TDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT',
521
+ 'Taipei Daylight Time': 'CDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT',
523
522
  'Tokelau Time': 'TKT', 'Tonga Standard Time': 'TOT', 'Tonga Summer Time': 'TOST',
524
523
  'Turkmenistan Standard Time': 'TMT', 'Tuvalu Time': 'TVT', 'Ulaanbaatar Standard Time': 'ULAT',
525
524
  'Ulaanbaatar Summer Time': 'ULAST', 'Uruguay Standard Time': 'UYT', 'Uruguay Summer Time': 'UYST',
@@ -607,7 +606,7 @@ var plugin = function (proto, date) {
607
606
  };
608
607
  var parseTZ = function (arg1, arg2, timeZone) {
609
608
  var pattern = typeof arg2 === 'string' ? date.compile(arg2) : arg2;
610
- var dateObj = typeof arg1 === 'string' ? date.parse(arg1, pattern, !!timeZone) : arg1;
609
+ var time = typeof arg1 === 'string' ? date.parse(arg1, pattern, !!timeZone).getTime() : arg1;
611
610
  var hasZ = function (array) {
612
611
  for (var i = 1, len = array.length; i < len; i++) {
613
612
  if (!array[i].indexOf('Z')) {
@@ -617,8 +616,8 @@ var plugin = function (proto, date) {
617
616
  return false;
618
617
  };
619
618
 
620
- if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC') {
621
- return dateObj;
619
+ if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC' || isNaN(time)) {
620
+ return new Date(time);
622
621
  }
623
622
 
624
623
  var getOffset = function (timeZoneName) {
@@ -631,17 +630,17 @@ var plugin = function (proto, date) {
631
630
  return Array.isArray(value) ? value : [];
632
631
  };
633
632
 
634
- var dateString2 = getDateTimeFormat('UTC').format(dateObj);
635
- var dateTimeFormat = getDateTimeFormat(timeZone);
633
+ var utc = getDateTimeFormat('UTC');
634
+ var tz = getDateTimeFormat(timeZone);
636
635
  var offset = getOffset(timeZone);
637
- var comparer = function (d) {
638
- return dateString2 === dateTimeFormat.format(d);
639
- };
640
636
 
641
- for (var j = 0, len2 = offset.length; j < len2; j++) {
642
- var d = dateObj.getTime() - offset[j] * 1000;
643
- if (comparer(d)) {
644
- return new Date(d);
637
+ for (var i = 0; i < 2; i++) {
638
+ var targetString = utc.format(time - i * 24 * 60 * 60 * 1000);
639
+
640
+ for (var j = 0, len = offset.length; j < len; j++) {
641
+ if (tz.format(time - (offset[j] + i * 24 * 60 * 60) * 1000) === targetString) {
642
+ return new Date(time - offset[j] * 1000);
643
+ }
645
644
  }
646
645
  }
647
646
  return new Date(NaN);
@@ -670,7 +669,7 @@ var plugin = function (proto, date) {
670
669
  var parts = formatToParts(getDateTimeFormat(timeZone), dateObj);
671
670
 
672
671
  parts.month += months;
673
- var dateObj2 = parseTZ(new Date(getTimeFromParts(normalizeDateParts(parts, true))), [], timeZone);
672
+ var dateObj2 = parseTZ(getTimeFromParts(normalizeDateParts(parts, true)), [], timeZone);
674
673
 
675
674
  return isNaN(dateObj2.getTime()) ? date.addMonths(dateObj, months, true) : dateObj2;
676
675
  };
@@ -678,7 +677,7 @@ var plugin = function (proto, date) {
678
677
  var parts = formatToParts(getDateTimeFormat(timeZone), dateObj);
679
678
 
680
679
  parts.day += days;
681
- var dateObj2 = parseTZ(new Date(getTimeFromParts(normalizeDateParts(parts, false))), [], timeZone);
680
+ var dateObj2 = parseTZ(getTimeFromParts(normalizeDateParts(parts, false)), [], timeZone);
682
681
 
683
682
  return isNaN(dateObj2.getTime()) ? date.addDays(dateObj, days, true) : dateObj2;
684
683
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-and-time",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
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",
@@ -52,7 +52,7 @@
52
52
  "@rollup/plugin-terser": "^0.4.4",
53
53
  "expect.js": "^0.3.1",
54
54
  "mocha": "^10.7.3",
55
- "rollup": "^4.20.0",
56
- "tsd": "^0.31.1"
55
+ "rollup": "^4.22.5",
56
+ "tsd": "^0.31.2"
57
57
  }
58
58
  }
@@ -461,7 +461,7 @@
461
461
  'Alaska Daylight Time': 'AKDT', 'Alaska Standard Time': 'AKST', 'Almaty Standard Time': 'ALMT',
462
462
  'Almaty Summer Time': 'ALMST', 'Amazon Standard Time': 'AMT', 'Amazon Summer Time': 'AMST',
463
463
  'Anadyr Standard Time': 'ANAT', 'Anadyr Summer Time': 'ANAST', 'Apia Daylight Time': 'WSDT',
464
- 'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTT',
464
+ 'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTST',
465
465
  'Aqtobe Standard Time': 'AQTT', 'Aqtobe Summer Time': 'AQST', 'Arabian Daylight Time': 'ADT',
466
466
  'Arabian Standard Time': 'AST', 'Argentina Standard Time': 'ART', 'Argentina Summer Time': 'ARST',
467
467
  'Armenia Standard Time': 'AMT', 'Armenia Summer Time': 'AMST', 'Atlantic Daylight Time': 'ADT',
@@ -477,19 +477,18 @@
477
477
  'Central Indonesia Time': 'WITA', 'Central Standard Time': 'CST', 'Chamorro Standard Time': 'ChST',
478
478
  'Chatham Daylight Time': 'CHADT', 'Chatham Standard Time': 'CHAST', 'Chile Standard Time': 'CLT',
479
479
  'Chile Summer Time': 'CLST', 'China Daylight Time': 'CDT', 'China Standard Time': 'CST',
480
- 'Choibalsan Standard Time': 'CHOT', 'Choibalsan Summer Time': 'CHOST', 'Christmas Island Time': 'CXT',
481
- 'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT', 'Colombia Standard Time': 'COT',
482
- 'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST', 'Cook Islands Standard Time': 'CKT',
483
- 'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT', 'Cuba Standard Time': 'CST',
484
- 'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT', 'East Africa Time': 'EAT',
485
- 'East Greenland Standard Time': 'EGST', 'East Greenland Summer Time': 'EGST', 'East Kazakhstan Time': 'ALMT',
486
- 'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST', 'Easter Island Summer Time': 'EASST',
487
- 'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET', 'Eastern European Summer Time': 'EEST',
488
- 'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST', 'Ecuador Time': 'ECT',
489
- 'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT', 'Fernando de Noronha Standard Time': 'FNT',
490
- 'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT', 'Fiji Summer Time': 'FJST',
491
- 'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT', 'Further-eastern European Time': 'FET',
492
- 'GMT': 'GMT', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT',
480
+ 'Christmas Island Time': 'CXT', 'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT',
481
+ 'Colombia Standard Time': 'COT', 'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST',
482
+ 'Cook Islands Standard Time': 'CKT', 'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT',
483
+ 'Cuba Standard Time': 'CST', 'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT',
484
+ 'East Africa Time': 'EAT', 'East Greenland Standard Time': 'EGT', 'East Greenland Summer Time': 'EGST',
485
+ 'East Kazakhstan Time': 'ALMT', 'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST',
486
+ 'Easter Island Summer Time': 'EASST', 'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET',
487
+ 'Eastern European Summer Time': 'EEST', 'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST',
488
+ 'Ecuador Time': 'ECT', 'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT',
489
+ 'Fernando de Noronha Standard Time': 'FNT', 'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT',
490
+ 'Fiji Summer Time': 'FJST', 'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT',
491
+ 'Further-eastern European Time': 'FET', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT',
493
492
  'Georgia Standard Time': 'GET', 'Georgia Summer Time': 'GEST', 'Gilbert Islands Time': 'GILT',
494
493
  'Greenwich Mean Time': 'GMT', 'Guam Standard Time': 'ChST', 'Gulf Standard Time': 'GST',
495
494
  'Guyana Time': 'GYT', 'Hawaii-Aleutian Daylight Time': 'HADT', 'Hawaii-Aleutian Standard Time': 'HAST',
@@ -501,7 +500,7 @@
501
500
  'Korean Daylight Time': 'KDT', 'Korean Standard Time': 'KST', 'Kosrae Time': 'KOST',
502
501
  'Krasnoyarsk Standard Time': 'KRAT', 'Krasnoyarsk Summer Time': 'KRAST', 'Kyrgyzstan Time': 'KGT',
503
502
  'Lanka Time': 'LKT', 'Line Islands Time': 'LINT', 'Lord Howe Daylight Time': 'LHDT',
504
- 'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDST',
503
+ 'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDT',
505
504
  'Magadan Standard Time': 'MAGT', 'Magadan Summer Time': 'MAGST', 'Malaysia Time': 'MYT',
506
505
  'Maldives Time': 'MVT', 'Marquesas Time': 'MART', 'Marshall Islands Time': 'MHT',
507
506
  'Mauritius Standard Time': 'MUT', 'Mauritius Summer Time': 'MUST', 'Mawson Time': 'MAWT',
@@ -514,7 +513,7 @@
514
513
  'North Mariana Islands Time': 'ChST', 'Novosibirsk Standard Time': 'NOVT', 'Novosibirsk Summer Time': 'NOVST',
515
514
  'Omsk Standard Time': 'OMST', 'Omsk Summer Time': 'OMSST', 'Pacific Daylight Time': 'PDT',
516
515
  'Pacific Standard Time': 'PST', 'Pakistan Standard Time': 'PKT', 'Pakistan Summer Time': 'PKST',
517
- 'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYST',
516
+ 'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYT',
518
517
  'Paraguay Summer Time': 'PYST', 'Peru Standard Time': 'PET', 'Peru Summer Time': 'PEST',
519
518
  'Petropavlovsk-Kamchatski Standard Time': 'PETT', 'Petropavlovsk-Kamchatski Summer Time': 'PETST', 'Philippine Standard Time': 'PST',
520
519
  'Philippine Summer Time': 'PHST', 'Phoenix Islands Time': 'PHOT', 'Pitcairn Time': 'PIT',
@@ -525,7 +524,7 @@
525
524
  'Singapore Standard Time': 'SGT', 'Solomon Islands Time': 'SBT', 'South Africa Standard Time': 'SAST',
526
525
  'South Georgia Time': 'GST', 'St. Pierre & Miquelon Daylight Time': 'PMDT', 'St. Pierre & Miquelon Standard Time': 'PMST',
527
526
  'Suriname Time': 'SRT', 'Syowa Time': 'SYOT', 'Tahiti Time': 'TAHT',
528
- 'Taipei Daylight Time': 'TDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT',
527
+ 'Taipei Daylight Time': 'CDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT',
529
528
  'Tokelau Time': 'TKT', 'Tonga Standard Time': 'TOT', 'Tonga Summer Time': 'TOST',
530
529
  'Turkmenistan Standard Time': 'TMT', 'Tuvalu Time': 'TVT', 'Ulaanbaatar Standard Time': 'ULAT',
531
530
  'Ulaanbaatar Summer Time': 'ULAST', 'Uruguay Standard Time': 'UYT', 'Uruguay Summer Time': 'UYST',
@@ -613,7 +612,7 @@
613
612
  };
614
613
  var parseTZ = function (arg1, arg2, timeZone) {
615
614
  var pattern = typeof arg2 === 'string' ? date.compile(arg2) : arg2;
616
- var dateObj = typeof arg1 === 'string' ? date.parse(arg1, pattern, !!timeZone) : arg1;
615
+ var time = typeof arg1 === 'string' ? date.parse(arg1, pattern, !!timeZone).getTime() : arg1;
617
616
  var hasZ = function (array) {
618
617
  for (var i = 1, len = array.length; i < len; i++) {
619
618
  if (!array[i].indexOf('Z')) {
@@ -623,8 +622,8 @@
623
622
  return false;
624
623
  };
625
624
 
626
- if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC') {
627
- return dateObj;
625
+ if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC' || isNaN(time)) {
626
+ return new Date(time);
628
627
  }
629
628
 
630
629
  var getOffset = function (timeZoneName) {
@@ -637,17 +636,17 @@
637
636
  return Array.isArray(value) ? value : [];
638
637
  };
639
638
 
640
- var dateString2 = getDateTimeFormat('UTC').format(dateObj);
641
- var dateTimeFormat = getDateTimeFormat(timeZone);
639
+ var utc = getDateTimeFormat('UTC');
640
+ var tz = getDateTimeFormat(timeZone);
642
641
  var offset = getOffset(timeZone);
643
- var comparer = function (d) {
644
- return dateString2 === dateTimeFormat.format(d);
645
- };
646
642
 
647
- for (var j = 0, len2 = offset.length; j < len2; j++) {
648
- var d = dateObj.getTime() - offset[j] * 1000;
649
- if (comparer(d)) {
650
- return new Date(d);
643
+ for (var i = 0; i < 2; i++) {
644
+ var targetString = utc.format(time - i * 24 * 60 * 60 * 1000);
645
+
646
+ for (var j = 0, len = offset.length; j < len; j++) {
647
+ if (tz.format(time - (offset[j] + i * 24 * 60 * 60) * 1000) === targetString) {
648
+ return new Date(time - offset[j] * 1000);
649
+ }
651
650
  }
652
651
  }
653
652
  return new Date(NaN);
@@ -676,7 +675,7 @@
676
675
  var parts = formatToParts(getDateTimeFormat(timeZone), dateObj);
677
676
 
678
677
  parts.month += months;
679
- var dateObj2 = parseTZ(new Date(getTimeFromParts(normalizeDateParts(parts, true))), [], timeZone);
678
+ var dateObj2 = parseTZ(getTimeFromParts(normalizeDateParts(parts, true)), [], timeZone);
680
679
 
681
680
  return isNaN(dateObj2.getTime()) ? date.addMonths(dateObj, months, true) : dateObj2;
682
681
  };
@@ -684,7 +683,7 @@
684
683
  var parts = formatToParts(getDateTimeFormat(timeZone), dateObj);
685
684
 
686
685
  parts.day += days;
687
- var dateObj2 = parseTZ(new Date(getTimeFromParts(normalizeDateParts(parts, false))), [], timeZone);
686
+ var dateObj2 = parseTZ(getTimeFromParts(normalizeDateParts(parts, false)), [], timeZone);
688
687
 
689
688
  return isNaN(dateObj2.getTime()) ? date.addDays(dateObj, days, true) : dateObj2;
690
689
  };