bizdays-toolkit 0.32.1 → 0.32.3

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/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.32.3] - 2026-11-17
10
+
11
+ ### Fixed
12
+
13
+ - The cache of time zone formatters no longer grows with every spelling of a time zone (`"Asia/Tokyo"`, `"asia/tokyo"`, `"+09:00"`, `"+0900"`, ...). A server that passed time zone strings from requests to `createCalendar`, `createSchedule` or `toDateString` could run out of memory: each new spelling kept a formatter of the runtime's `Intl`, outside the JavaScript heap. A formatter is now kept for each name that `Intl` reports, the spellings are remembered up to 1,000 and then forgotten, and offsets from UTC are read without a formatter of their own (design decisions 16). Results are unchanged. For an instant after the year 10000 in UTC, the message of the `out-of-range` exception is now `Instant out of range (1000-9999)` in every time zone, as before the year 999; the code is unchanged
14
+
15
+ ## [0.32.2] - 2026-11-15
16
+
17
+ ### Fixed
18
+
19
+ - The option diagnostics reported an item as `redundant` (removing it does not change any result) although removing it made a day at the edge of the holiday provider's supported years throw `out-of-range`. A rule that looks at a neighbouring day (an `"after-holiday"` rule looking back for the day it was moved from, a rule for the day before or after a holiday, an nth-business-day-of-the-week rule) throws `out-of-range` when that day is outside the supported years. When another item decided the edge day first (an earlier recurring rule, a date in `closedDates` or `openDates`), the day was evaluated without an exception, the diagnostics reported that item as `redundant`, and removing it as suggested made the day throw. The diagnostics evaluated days outside the supported years as days without holidays and so did not see the exception. They now evaluate such a day as the calendar does and treat it as a day that cannot be judged, so the item is no longer reported. This applies with `outOfRangePolicy: "throw"` (the default); with `"ignore"` nothing throws and nothing changes. No result of a calendar or schedule changes
20
+ - As a consequence, an item that decides a day at the edge of the supported years is no longer reported as `redundant` even when it is redundant on every other day. For example, with the `jp` provider and an `"after-holiday"` rule for Mondays, a weekly Sunday rule that duplicates `closedWeekdays` is no longer reported, because removing it would make 1955-01-02 (the first Sunday of the supported years) throw; the same rule for Saturdays is still reported. With the `sg` provider and a rule for the day before a holiday, a weekly Friday rule that duplicates `closedWeekdays` is no longer reported, because of 2027-12-31
21
+
9
22
  ## [0.32.1] - 2026-11-14
10
23
 
11
24
  ### Fixed
@@ -1007,7 +1020,9 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
1007
1020
 
1008
1021
  - 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
1009
1022
 
1010
- [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.1...HEAD
1023
+ [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.3...HEAD
1024
+ [0.32.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.2...v0.32.3
1025
+ [0.32.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.1...v0.32.2
1011
1026
  [0.32.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.0...v0.32.1
1012
1027
  [0.32.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.9...v0.32.0
1013
1028
  [0.31.9]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.8...v0.31.9
@@ -54,6 +54,16 @@ const MAX_DATE_RULE_DAYS = 366 * MAX_WINDOW_YEARS;
54
54
  const isLostShift = (error) => error?.code === "holiday-run-too-long";
55
55
  const atCalendarEdge = (n, error) => (n < MIN_DAY + MAX_HOLIDAY_RUN || n > MAX_DAY - MAX_HOLIDAY_RUN) &&
56
56
  error?.code === "out-of-range";
57
+ const PROVIDER_EDGE_DAYS = 367;
58
+ const atEdge = (n, error, window) => {
59
+ if (atCalendarEdge(n, error))
60
+ return true;
61
+ if (error?.code !== "out-of-range" || !window)
62
+ return false;
63
+ const first = window.ranges[0].from;
64
+ const last = window.ranges[window.ranges.length - 1].to;
65
+ return n < first + PROVIDER_EDGE_DAYS || n > last - PROVIDER_EDGE_DAYS;
66
+ };
57
67
  function openEndedDays(from, days) {
58
68
  const lo = Math.max(from, MIN_DAY);
59
69
  const hi = Math.min(from + days - 1, MAX_DAY);
@@ -451,7 +461,7 @@ function checkLostShifts(c, compiled, lookup, window) {
451
461
  resolve(fromDayNumber(n), false);
452
462
  }
453
463
  catch (error) {
454
- if (!atCalendarEdge(n, error))
464
+ if (!atEdge(n, error, window))
455
465
  throw error;
456
466
  }
457
467
  }
@@ -483,7 +493,6 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
483
493
  return;
484
494
  const lookup = createHolidayLookup({
485
495
  ...source,
486
- outOfRangePolicy: "ignore",
487
496
  unconfirmedHolidayPolicy: "accept",
488
497
  });
489
498
  const basis = createBasis(compiled, lookup);
@@ -709,7 +718,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
709
718
  found = resolve(fromDayNumber(n)).day.value === true;
710
719
  }
711
720
  catch (error) {
712
- if (!atCalendarEdge(n, error) && !isLostShift(error))
721
+ if (!atEdge(n, error, window) && !isLostShift(error))
713
722
  throw error;
714
723
  found = false;
715
724
  }
@@ -2,6 +2,8 @@ import { formatDate, parseDate } from "./date.js";
2
2
  import { describeValue, rangeError, typeError } from "./errors.js";
3
3
  const DATETIME_RE = /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:?\d{2})?$/i;
4
4
  const formatters = new Map();
5
+ const zoneNames = new Map();
6
+ const OFFSET_ZONE_RE = /^([+-])(\d\d):(\d\d)$/;
5
7
  function formatterFor(timeZone) {
6
8
  let f = formatters.get(timeZone);
7
9
  if (!f) {
@@ -18,12 +20,23 @@ function formatterFor(timeZone) {
18
20
  }
19
21
  return f;
20
22
  }
23
+ function zoneNameOf(timeZone) {
24
+ const key = timeZone.replace(/[A-Z]+/g, (s) => s.toLowerCase());
25
+ let name = zoneNames.get(key);
26
+ if (name === undefined) {
27
+ name = new Intl.DateTimeFormat("en-US", { timeZone }).resolvedOptions().timeZone;
28
+ if (zoneNames.size >= 1000)
29
+ zoneNames.clear();
30
+ zoneNames.set(key, name).set(name, name);
31
+ }
32
+ return name;
33
+ }
21
34
  export function validateTimeZone(timeZone) {
22
35
  if (typeof timeZone !== "string" || timeZone === "") {
23
36
  throw rangeError("invalid-time-zone", `Invalid time zone: ${describeValue(timeZone)}`);
24
37
  }
25
38
  try {
26
- return formatterFor(timeZone).resolvedOptions().timeZone;
39
+ return zoneNameOf(timeZone);
27
40
  }
28
41
  catch {
29
42
  throw rangeError("invalid-time-zone", `Invalid time zone: ${describeValue(timeZone)}`);
@@ -51,7 +64,12 @@ export function distinctTimeZones(zones) {
51
64
  return out;
52
65
  }
53
66
  function wallParts(epochMilliseconds, timeZone) {
54
- const parts = formatterFor(timeZone).formatToParts(new Date(epochMilliseconds));
67
+ const zone = zoneNames.get(timeZone) === timeZone ? timeZone : zoneNameOf(timeZone);
68
+ const offset = OFFSET_ZONE_RE.exec(zone);
69
+ const parts = formatterFor(offset ? "UTC" : zone).formatToParts(new Date(epochMilliseconds +
70
+ (offset
71
+ ? (offset[1] === "-" ? -60_000 : 60_000) * (Number(offset[2]) * 60 + Number(offset[3]))
72
+ : 0)));
55
73
  const get = (type) => {
56
74
  const p = parts.find((x) => x.type === type);
57
75
  if (!p)
@@ -72,7 +90,8 @@ export function instantToCivil(epochMilliseconds, timeZone) {
72
90
  if (Math.abs(epochMilliseconds) > 8.64e15) {
73
91
  throw rangeError("out-of-range", "Instant out of range (1000-9999)");
74
92
  }
75
- if (new Date(epochMilliseconds).getUTCFullYear() < 999) {
93
+ const utcYear = new Date(epochMilliseconds).getUTCFullYear();
94
+ if (utcYear < 999 || utcYear > 10000) {
76
95
  throw rangeError("out-of-range", "Instant out of range (1000-9999)");
77
96
  }
78
97
  const { year, month, day, hour, minute } = wallParts(epochMilliseconds, timeZone);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bizdays-toolkit",
3
- "version": "0.32.1",
3
+ "version": "0.32.3",
4
4
  "description": "Holidays, business-day calendar and day-by-day schedules (e.g. store hours) with time zone support. Japanese holidays verified against the Cabinet Office data; UK bank holidays (England, Wales, Scotland, Northern Ireland) verified against GOV.UK and The Gazette; French public holidays (metropole, Alsace-Moselle) verified against data.gouv.fr; Singapore public holidays verified against data.gov.sg. / 祝日と営業日のカレンダー(タイムゾーン対応・日本の祝日は内閣府、英国の bank holidays は GOV.UK と The Gazette、フランスの祝日は data.gouv.fr、シンガポールの祝日は data.gov.sg のデータで全日照合)",
5
5
  "keywords": [
6
6
  "bank-holidays",