bizdays-toolkit 0.32.3 → 0.32.5

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,24 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.32.5] - 2026-11-18
10
+
11
+ ### Changed
12
+
13
+ - Calculations that step through days are faster: turning a day number back into a date no longer parses the date string it has just built (the year is still checked against 1000–9999), and the option diagnostics work out the days a recurring rule matches only when two rules are compared. Searching, adding and counting business days, ranges of days and the option diagnostics are faster. Results, exceptions and diagnostics are unchanged
14
+
15
+ ## [0.32.4] - 2026-11-18
16
+
17
+ ### Fixed
18
+
19
+ - `combineCalendars` now copies the array of calendars it is given. Changing that array after combining (adding, removing or reordering calendars) changed the results of the combined calendar, and could make `dayInfoOn` throw a `TypeError` without a `code` (design decisions 4: options are taken in when created)
20
+ - The documentation now says how the option diagnostics treat days outside the holiday provider's supported years: with `outOfRangePolicy: "throw"`, a day whose evaluation throws `out-of-range` is a day the diagnostics cannot judge, as it has been since 0.32.2 (the guide said that the diagnostics treat days outside as having no holidays, which holds only with `"ignore"` and for a few checks)
21
+ - The documentation now says that diagnostics check at most 200 supported years of a holiday provider (for a provider with more, the supported years within 1900–2099, or the first 200 if none fall there), not every supported year (guide and providers.md)
22
+ - The type descriptions now say that two time zones with different names are compared with Temporal on runtimes that have it (`HolidayLookup.timeZone` and the `time-zone-conflict` code), as they have been since 0.32.0
23
+ - The type descriptions, the README and the guide now say that a schedule's `holidayPolicy` defaults to `"ignore"`: with a holiday provider but no `holidayPolicy`, holidays do not change a schedule's values, unlike a business-day calendar
24
+ - The type description of `timeZone` in the options now says that it takes precedence over the holiday provider's time zone
25
+ - providers.md now says that a calendar holds the holiday provider by reference, so a provider must not be changed (including its `supportedYears`) after a calendar is created with it
26
+
9
27
  ## [0.32.3] - 2026-11-17
10
28
 
11
29
  ### Fixed
@@ -1020,7 +1038,9 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
1020
1038
 
1021
1039
  - 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
1022
1040
 
1023
- [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.3...HEAD
1041
+ [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.5...HEAD
1042
+ [0.32.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.4...v0.32.5
1043
+ [0.32.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.3...v0.32.4
1024
1044
  [0.32.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.2...v0.32.3
1025
1045
  [0.32.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.1...v0.32.2
1026
1046
  [0.32.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.0...v0.32.1
package/README.md CHANGED
@@ -93,7 +93,7 @@ A calendar is built from the holiday provider and your closures: `closedWeekdays
93
93
  ### Due dates, schedules and combined calendars
94
94
 
95
95
  - `dueDate("2026-11", { dayOfMonth: 23, convention: "following" })`, `adjust`, `closingMonth` and `closingPeriod` compute month-based due dates and closing periods with the `following`, `preceding`, `modified-following` and `modified-preceding` conventions ([Month-based due dates](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#month-based-due-dates-and-date-adjustment))
96
- - `createSchedule` gives a value per day (store hours, a shipping cutoff, a price band) from the same kinds of rules, and `createCalendarFromSchedule` turns such a schedule into a calendar so the hours are the only configuration ([Day-by-day values](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#day-by-day-values-eg-store-hours), [A calendar from a schedule](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#a-business-day-calendar-from-a-schedule))
96
+ - `createSchedule` gives a value per day (store hours, a shipping cutoff, a price band) from the same kinds of rules (unlike a calendar, holidays do not affect the values unless you set `holidayPolicy`), and `createCalendarFromSchedule` turns such a schedule into a calendar so the hours are the only configuration ([Day-by-day values](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#day-by-day-values-eg-store-hours), [A calendar from a schedule](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#a-business-day-calendar-from-a-schedule))
97
97
  - `combineCalendars` builds the days on which all (or any) of several calendars are open, such as your company and the bank for a remittance date ([Combining calendars](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#combining-calendars))
98
98
  - Dates can be given as `"YYYY-MM-DD"`, `"YYYY-MM-DDTHH:mm"`, `Date` or Temporal objects; instants are converted in the calendar's time zone ([Date and date-time inputs](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#date-and-date-time-inputs))
99
99
 
@@ -345,11 +345,12 @@ export function combineCalendars(calendars, options) {
345
345
  if (!Array.isArray(calendars) || calendars.length < 2) {
346
346
  throw rangeError("invalid-argument", "calendars must be an array of two or more calendars");
347
347
  }
348
- Array.from(calendars).forEach((c, i) => {
348
+ const list = Object.freeze(Array.from(calendars));
349
+ list.forEach((c, i) => {
349
350
  if (!isCalendarLike(c))
350
351
  throw rangeError("invalid-argument", `calendars[${i}] is not a calendar`);
351
- if (calendars.indexOf(c) !== i) {
352
- throw rangeError("invalid-argument", `calendars[${i}] is the same calendar as calendars[${calendars.indexOf(c)}]`);
352
+ if (list.indexOf(c) !== i) {
353
+ throw rangeError("invalid-argument", `calendars[${i}] is the same calendar as calendars[${list.indexOf(c)}]`);
353
354
  }
354
355
  });
355
356
  const o = optionsObject(options, "combineCalendars options", (v) => renameKeys("throw", ["combine"], "", v), true, "invalid-option");
@@ -361,20 +362,20 @@ export function combineCalendars(calendars, options) {
361
362
  if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
362
363
  throw rangeError("invalid-option", "searchDayLimit must be a positive integer");
363
364
  }
364
- const zones = distinctTimeZones(calendars.map((c) => c.timeZone));
365
+ const zones = distinctTimeZones(list.map((c) => c.timeZone));
365
366
  if (zones.length > 1) {
366
367
  throw rangeError("time-zone-conflict", `Calendars use different time zones (${zones.join(", ")}); combine calendars with the same time zone`);
367
368
  }
368
369
  const providers = [];
369
- for (const c of calendars)
370
+ for (const c of list)
370
371
  for (const p of c.providers)
371
372
  if (!providers.includes(p))
372
373
  providers.push(p);
373
374
  const base = createHolidayLookup({
374
375
  providers: Object.freeze(providers),
375
376
  timeZone: zones[0],
376
- outOfRangePolicy: calendars.every((c) => c.outOfRangePolicy === "ignore") ? "ignore" : "throw",
377
- unconfirmedHolidayPolicy: calendars.some((c) => c.unconfirmedHolidayPolicy === "throw")
377
+ outOfRangePolicy: list.every((c) => c.outOfRangePolicy === "ignore") ? "ignore" : "throw",
378
+ unconfirmedHolidayPolicy: list.some((c) => c.unconfirmedHolidayPolicy === "throw")
378
379
  ? "throw"
379
380
  : "accept",
380
381
  });
@@ -386,21 +387,21 @@ export function combineCalendars(calendars, options) {
386
387
  byDate.set(h.date, h);
387
388
  return Object.freeze([...byDate.values()].sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0)));
388
389
  };
389
- const holidayOn = (input) => calendars.map((c) => c.holidayOn(input)).find((h) => h !== undefined);
390
+ const holidayOn = (input) => list.map((c) => c.holidayOn(input)).find((h) => h !== undefined);
390
391
  const lookup = {
391
392
  ...base,
392
393
  isHoliday: (input) => holidayOn(input) !== undefined,
393
394
  holidayOn,
394
395
  getHoliday: holidayOn,
395
- holidaysInYear: (year) => merge(calendars.map((c) => c.holidaysInYear(year))),
396
- holidaysBetween: (from, to) => merge(calendars.map((c) => c.holidaysBetween(from, to))),
396
+ holidaysInYear: (year) => merge(list.map((c) => c.holidaysInYear(year))),
397
+ holidaysBetween: (from, to) => merge(list.map((c) => c.holidaysBetween(from, to))),
397
398
  };
398
399
  const isOpen = (date) => {
399
- const results = calendars.map((c) => c.isBusinessDay(date));
400
+ const results = list.map((c) => c.isBusinessDay(date));
400
401
  return mode === "all" ? results.every(Boolean) : results.some(Boolean);
401
402
  };
402
403
  function info(date) {
403
- const results = calendars.map((c) => c.dayInfoOn(date));
404
+ const results = list.map((c) => c.dayInfoOn(date));
404
405
  const open = mode === "all" ? results.every((r) => r.open) : results.some((r) => r.open);
405
406
  const decidedBy = results.findIndex((r) => r.open === open);
406
407
  const decided = results[decidedBy];
@@ -25,15 +25,21 @@ export declare function parseDate(value: string): {
25
25
  * @public
26
26
  */
27
27
  export declare function isValidDate(input: unknown): input is DateString;
28
- /** 年月日から "YYYY-MM-DD" を作る(範囲外なら RangeError) */
29
- export declare function formatDate(year: number, month: number, day: number): DateString;
28
+ /**
29
+ * 年月日から "YYYY-MM-DD" を作る(範囲外なら RangeError)。exists なら、実在する年月日として解析し直さず、parseDate の
30
+ * 直前 1 件の記憶に入れる(続けて同じ文字列を解析するため。decisions.md の 16 番)
31
+ */
32
+ export declare function formatDate(year: number, month: number, day: number, exists?: boolean): DateString;
30
33
  /** うるう年か */
31
34
  export declare function isLeapYear(year: number): boolean;
32
35
  /** その月の日数 */
33
36
  export declare function lengthOfMonth(year: number, month: number): number;
34
37
  /** 1970-01-01 からの日数 */
35
38
  export declare function toDayNumber(date: DateString): number;
36
- /** 1970-01-01 からの日数を "YYYY-MM-DD" に戻す */
39
+ /**
40
+ * 1970-01-01 からの日数を "YYYY-MM-DD" に戻す。日数から作る年月日は必ず実在するので、文字列を解析し直して検証しない
41
+ * (年の範囲だけを確かめる。探索・期間の数え上げ・診断の走査が 1 日ごとに呼ぶ)
42
+ */
37
43
  export declare function fromDayNumber(dayNumber: number): DateString;
38
44
  /**
39
45
  * n 日後(負なら前)の日付。
package/dist/core/date.js CHANGED
@@ -31,12 +31,15 @@ export function isValidDate(input) {
31
31
  return false;
32
32
  }
33
33
  }
34
- export function formatDate(year, month, day) {
34
+ export function formatDate(year, month, day, exists) {
35
35
  if (!Number.isInteger(year) || year < 1000 || year > 9999) {
36
36
  throw rangeError("out-of-range", `Year out of range (1000-9999): ${year}`);
37
37
  }
38
38
  const s = `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
39
- parseDate(s);
39
+ if (!exists)
40
+ parseDate(s);
41
+ else
42
+ [lastValue, lastParts] = [s, Object.freeze({ year, month, day })];
40
43
  return s;
41
44
  }
42
45
  export function isLeapYear(year) {
@@ -56,7 +59,7 @@ export function toDayNumber(date) {
56
59
  }
57
60
  export function fromDayNumber(dayNumber) {
58
61
  const d = new Date(dayNumber * MS_PER_DAY);
59
- return formatDate(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate());
62
+ return formatDate(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate(), true);
60
63
  }
61
64
  export function addDays(date, n) {
62
65
  if (!Number.isInteger(n)) {
@@ -545,7 +545,9 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
545
545
  c.warning("shadowed", rule.path, `This rule is never used: the earlier rule ${annual[k].path} covers all of its days`, annual[k].path);
546
546
  });
547
547
  const noBits = new Uint8Array(PATTERN_DAYS);
548
- const recurringBits = recurring.map((r) => (r.businessDays !== null ? noBits : patternBits(r)));
548
+ const recurringBits = [];
549
+ const bitsOf = (j) => (recurringBits[j] ??=
550
+ recurring[j].businessDays !== null ? noBits : patternBits(recurring[j]));
549
551
  const holidayOfSafe = (date) => {
550
552
  try {
551
553
  return lookup.holidayOfDate(date);
@@ -615,7 +617,6 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
615
617
  a.skipWeekdays.size === b.skipWeekdays.size &&
616
618
  [...a.skipWeekdays].every((w) => b.skipWeekdays.has(w));
617
619
  recurring.forEach((rule, j) => {
618
- const bits = recurringBits[j];
619
620
  const holidayBased = isHolidayBasedRule(rule);
620
621
  const businessDayBased = rule.businessDays !== null;
621
622
  const matches = holidayBased
@@ -688,7 +689,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
688
689
  r.businessDays === null &&
689
690
  r.cycle === null &&
690
691
  intervalCovers(r, rule) &&
691
- isSubset(bits, recurringBits[i])));
692
+ isSubset(bitsOf(j), bitsOf(i))));
692
693
  if (k < 0)
693
694
  return;
694
695
  unused.add(rule);
@@ -33,7 +33,8 @@ export type KnownErrorCode =
33
33
  /**
34
34
  * 同じタイムゾーンでなければならないものが食い違う(1 つの設定の祝日の提供元どうしで、timeZone の指定がない。
35
35
  * 合成するカレンダーどうし。スケジュールと、第 n 営業日の規則の数える基準のカレンダー)。実行環境の Intl が返す名前が
36
- * 同じかで比べるので、別名どうし("UTC" と "Etc/UTC" など)は、別名を同じ名前に直さない実行環境では食い違いになる
36
+ * 同じなら同じとし、違えば、実行環境に Temporal があれば Temporal の比較で決める(decisions.md の 18 番)。Temporal がなく、
37
+ * 別名を同じ名前に直さない実行環境では、別名どうし("UTC" と "Etc/UTC" など)は食い違いになる
37
38
  */
38
39
  | "time-zone-conflict"
39
40
  /**
@@ -457,7 +457,8 @@ export interface HolidaySourceOptions<Kind extends string = string> {
457
457
  readonly unconfirmedHolidays?: "accept" | "throw";
458
458
  /**
459
459
  * 日時の入力(Date・オフセット付き文字列など)を暦日に変換するタイムゾーン。
460
- * 省略時は祝日の提供元のタイムゾーン、提供元もなければ "UTC"
460
+ * 省略時は祝日の提供元のタイムゾーン、提供元もなければ "UTC"。書けば、提供元のタイムゾーンより優先する
461
+ * (提供元の祝日は暦日で引くので、変換のタイムゾーンを変えても祝日の日付は変わらない)
461
462
  */
462
463
  readonly timeZone?: string;
463
464
  /** 祝日の提供元の対応年を外れた日付の扱い(既定: "throw") */
@@ -479,7 +480,10 @@ export interface HolidaySourceOptions<Kind extends string = string> {
479
480
  export interface ScheduleOptions<Value, Kind extends string = string> extends HolidaySourceOptions<Kind> {
480
481
  /** 曜日ごとの値([日, 月, 火, 水, 木, 金, 土]) */
481
482
  readonly weekdayValues: readonly [Value, Value, Value, Value, Value, Value, Value];
482
- /** 祝日の値の決め方(既定: "ignore") */
483
+ /**
484
+ * 祝日の値の決め方(既定: "ignore")。省くと、祝日の提供元を渡しても祝日は値に影響しない(祝日も曜日の値になる)。
485
+ * 営業日カレンダーの既定(祝日は休業)と違うので、祝日に別の値を当てるときは書く
486
+ */
483
487
  readonly holidayPolicy?: ScheduleHolidayPolicy<Value>;
484
488
  /** 繰り返しの規則の値(書ける規則の形はガイドの「Recurring rules」の表) */
485
489
  readonly recurringRules?: readonly ScheduleRecurringRule<Value, Kind>[];
@@ -538,7 +542,8 @@ export interface HolidayLookup<Kind extends string = string> {
538
542
  /**
539
543
  * 日時の入力を暦日に変換するタイムゾーン。実行環境の Intl が返す名前で、設定に書いた綴りと違うことがあり、実行環境によっても
540
544
  * 違う("Asia/Kolkata" と書くと、Node.js では "Asia/Calcutta"、Bun では "Asia/Kolkata")。同じタイムゾーンかは、この名前が
541
- * 同じかで比べる(違えば time-zone-conflict)
545
+ * 同じなら同じとし、違えば、実行環境に Temporal があれば Temporal の比較で決め、なければ別とする(別なら time-zone-conflict。
546
+ * decisions.md の 18 番)
542
547
  */
543
548
  readonly timeZone: string;
544
549
  /** 祝日の提供元 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bizdays-toolkit",
3
- "version": "0.32.3",
3
+ "version": "0.32.5",
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",