@js-joda/timezone 3.1.0 → 3.2.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.
Files changed (37) hide show
  1. package/dist/js-joda-timezone-10-year-range.esm.js +18 -14
  2. package/dist/js-joda-timezone-10-year-range.esm.js.map +1 -1
  3. package/dist/js-joda-timezone-10-year-range.js +18 -14
  4. package/dist/js-joda-timezone-10-year-range.js.map +1 -1
  5. package/dist/js-joda-timezone-10-year-range.min.js +2 -2
  6. package/dist/js-joda-timezone-300-year-range.esm.js +34 -30
  7. package/dist/js-joda-timezone-300-year-range.esm.js.map +1 -1
  8. package/dist/js-joda-timezone-300-year-range.js +34 -30
  9. package/dist/js-joda-timezone-300-year-range.js.map +1 -1
  10. package/dist/js-joda-timezone-300-year-range.min.js +2 -2
  11. package/dist/js-joda-timezone-4-year-range.esm.js +18 -14
  12. package/dist/js-joda-timezone-4-year-range.esm.js.map +1 -1
  13. package/dist/js-joda-timezone-4-year-range.js +18 -14
  14. package/dist/js-joda-timezone-4-year-range.js.map +1 -1
  15. package/dist/js-joda-timezone-4-year-range.min.js +2 -2
  16. package/dist/js-joda-timezone-60-year-range.esm.js +18 -14
  17. package/dist/js-joda-timezone-60-year-range.esm.js.map +1 -1
  18. package/dist/js-joda-timezone-60-year-range.js +18 -14
  19. package/dist/js-joda-timezone-60-year-range.js.map +1 -1
  20. package/dist/js-joda-timezone-60-year-range.min.js +2 -2
  21. package/dist/js-joda-timezone-empty.esm.js +16 -12
  22. package/dist/js-joda-timezone-empty.esm.js.map +1 -1
  23. package/dist/js-joda-timezone-empty.js +16 -12
  24. package/dist/js-joda-timezone-empty.js.map +1 -1
  25. package/dist/js-joda-timezone-empty.min.js +2 -2
  26. package/dist/js-joda-timezone-lifetime-range.esm.js +34 -30
  27. package/dist/js-joda-timezone-lifetime-range.esm.js.map +1 -1
  28. package/dist/js-joda-timezone-lifetime-range.js +34 -30
  29. package/dist/js-joda-timezone-lifetime-range.js.map +1 -1
  30. package/dist/js-joda-timezone-lifetime-range.min.js +2 -2
  31. package/dist/js-joda-timezone.esm.js +34 -30
  32. package/dist/js-joda-timezone.esm.js.map +1 -1
  33. package/dist/js-joda-timezone.js +34 -30
  34. package/dist/js-joda-timezone.js.map +1 -1
  35. package/dist/js-joda-timezone.min.js +2 -2
  36. package/package.json +3 -3
  37. package/src/TzdbZoneRules.js +21 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-joda/timezone",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "iana tzdb timezone bindings for js-joda",
5
5
  "typings": "typings/js-joda-timezone.d.ts",
6
6
  "main": "dist/js-joda-timezone.js",
@@ -45,12 +45,12 @@
45
45
  "@js-joda/core": ">=5.7.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@js-joda/core": "^6.3.0"
48
+ "@js-joda/core": "^6.3.1"
49
49
  },
50
50
  "license": "BSD-3-Clause",
51
51
  "bugs": {
52
52
  "url": "https://github.com/js-joda/js-joda/issues"
53
53
  },
54
54
  "homepage": "https://js-joda.github.io/js-joda",
55
- "gitHead": "8c0a3b1b555bc09fced243dac13fdf5ef9746dc7"
55
+ "gitHead": "24c247ab29a9b4f2efa45285743c0234df7d6156"
56
56
  }
@@ -37,7 +37,7 @@ export class TzdbZoneRules extends ZoneRules{
37
37
  * @return {ZoneOffset} the offset, not null
38
38
  */
39
39
  offsetOfInstant(instant){
40
- const epochMilli = instant.toEpochMilli();
40
+ const epochMilli = epochMilliOf(instant);
41
41
  return this.offsetOfEpochMilli(epochMilli);
42
42
  }
43
43
 
@@ -229,7 +229,7 @@ export class TzdbZoneRules extends ZoneRules{
229
229
  * @throws {Error} if the tz data of the zone has no standard offsets
230
230
  */
231
231
  standardOffset(instant){
232
- return ZoneOffset.ofTotalSeconds(this._standardOffsetInSeconds(instant.toEpochMilli()));
232
+ return ZoneOffset.ofTotalSeconds(this._standardOffsetInSeconds(epochMilliOf(instant)));
233
233
  }
234
234
 
235
235
  _standardOffsetInSeconds(epochMilli){
@@ -256,7 +256,7 @@ export class TzdbZoneRules extends ZoneRules{
256
256
  * @throws {Error} if the tz data of the zone has no standard offsets
257
257
  */
258
258
  daylightSavings(instant){
259
- const epochMilli = instant.toEpochMilli();
259
+ const epochMilli = epochMilliOf(instant);
260
260
  const index = binarySearch(this._tzdbInfo.untils, epochMilli);
261
261
  return Duration.ofSeconds(this._offsetByIndexInSeconds(index) - this._standardOffsetInSeconds(epochMilli));
262
262
  }
@@ -306,7 +306,7 @@ export class TzdbZoneRules extends ZoneRules{
306
306
  const indices = this._transitionIndices();
307
307
  const untils = this._tzdbInfo.untils;
308
308
  // transitions are at whole milliseconds, so "after the instant" equals "after its truncated milli"
309
- const epochMilli = instant.toEpochMilli();
309
+ const epochMilli = epochMilliOf(instant);
310
310
  const k = firstIndexWhere(indices, (i) => untils[i] > epochMilli);
311
311
  return k < indices.length ? this._createTransition(indices[k]) : null;
312
312
  }
@@ -327,7 +327,7 @@ export class TzdbZoneRules extends ZoneRules{
327
327
  const untils = this._tzdbInfo.untils;
328
328
  // round up to the next milli if the instant has a fraction of a milli,
329
329
  // so that a transition at the truncated milli counts as before the instant
330
- const epochMilli = instant.toEpochMilli() + (instant.nano() % 1000000 > 0 ? 1 : 0);
330
+ const epochMilli = epochMilliOf(instant) + (instant.nano() % 1000000 > 0 ? 1 : 0);
331
331
  const k = firstIndexWhere(indices, (i) => untils[i] >= epochMilli);
332
332
  return k > 0 ? this._createTransition(indices[k - 1]) : null;
333
333
  }
@@ -479,16 +479,26 @@ function ldtBinarySearch(array, value) {
479
479
  return hi;
480
480
  }
481
481
 
482
+ // the offset is stored in minutes, with seconds as a base 60 fraction; multiplying it back can
483
+ // give a value just below the whole second (e.g. 65.35 * 60 = 3920.9999...), so round it
482
484
  function offsetInSeconds(tzdbOffset){
483
- return roundDown(+tzdbOffset*60);
485
+ return Math.round(+tzdbOffset*60);
484
486
  }
485
487
 
486
- function roundDown(r){
487
- if (r < 0) {
488
- return Math.ceil(r);
489
- } else {
490
- return Math.floor(r);
488
+ // beyond this epoch second, Instant.toEpochMilli() overflows; far outside the tz data
489
+ const MAX_EPOCH_SECOND_FOR_MILLIS = Math.floor(Number.MAX_SAFE_INTEGER / 1000) - 1;
490
+
491
+ // the epoch milli of the instant, or +/-Infinity for an instant too far out for an epoch milli
492
+ // (e.g. Instant.MAX); infinities compare with the untils of the tz data like any far instant
493
+ function epochMilliOf(instant) {
494
+ const epochSecond = instant.epochSecond();
495
+ if (epochSecond > MAX_EPOCH_SECOND_FOR_MILLIS) {
496
+ return Infinity;
497
+ }
498
+ if (epochSecond < -MAX_EPOCH_SECOND_FOR_MILLIS) {
499
+ return -Infinity;
491
500
  }
501
+ return instant.toEpochMilli();
492
502
  }
493
503
 
494
504
  // modified bin-search, to always find existing indices for non-empty arrays