bizdays-toolkit 0.32.2 → 0.32.4
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 +21 -1
- package/README.md +1 -1
- package/dist/core/calendar.js +13 -12
- package/dist/core/errors.d.ts +2 -1
- package/dist/core/input.js +22 -3
- package/dist/core/schedule.d.ts +8 -3
- package/package.json +1 -1
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.4] - 2026-11-18
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `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)
|
|
14
|
+
- 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)
|
|
15
|
+
- 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)
|
|
16
|
+
- 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
|
|
17
|
+
- 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
|
|
18
|
+
- The type description of `timeZone` in the options now says that it takes precedence over the holiday provider's time zone
|
|
19
|
+
- 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
|
|
20
|
+
|
|
21
|
+
## [0.32.3] - 2026-11-17
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- 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
|
|
26
|
+
|
|
9
27
|
## [0.32.2] - 2026-11-15
|
|
10
28
|
|
|
11
29
|
### Fixed
|
|
@@ -1014,7 +1032,9 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
|
|
|
1014
1032
|
|
|
1015
1033
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
1016
1034
|
|
|
1017
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.
|
|
1035
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.4...HEAD
|
|
1036
|
+
[0.32.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.3...v0.32.4
|
|
1037
|
+
[0.32.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.2...v0.32.3
|
|
1018
1038
|
[0.32.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.1...v0.32.2
|
|
1019
1039
|
[0.32.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.0...v0.32.1
|
|
1020
1040
|
[0.32.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.9...v0.32.0
|
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
|
|
package/dist/core/calendar.js
CHANGED
|
@@ -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)
|
|
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 (
|
|
352
|
-
throw rangeError("invalid-argument", `calendars[${i}] is the same calendar as calendars[${
|
|
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(
|
|
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
|
|
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:
|
|
377
|
-
unconfirmedHolidayPolicy:
|
|
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) =>
|
|
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(
|
|
396
|
-
holidaysBetween: (from, to) => merge(
|
|
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 =
|
|
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 =
|
|
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];
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -33,7 +33,8 @@ export type KnownErrorCode =
|
|
|
33
33
|
/**
|
|
34
34
|
* 同じタイムゾーンでなければならないものが食い違う(1 つの設定の祝日の提供元どうしで、timeZone の指定がない。
|
|
35
35
|
* 合成するカレンダーどうし。スケジュールと、第 n 営業日の規則の数える基準のカレンダー)。実行環境の Intl が返す名前が
|
|
36
|
-
*
|
|
36
|
+
* 同じなら同じとし、違えば、実行環境に Temporal があれば Temporal の比較で決める(decisions.md の 18 番)。Temporal がなく、
|
|
37
|
+
* 別名を同じ名前に直さない実行環境では、別名どうし("UTC" と "Etc/UTC" など)は食い違いになる
|
|
37
38
|
*/
|
|
38
39
|
| "time-zone-conflict"
|
|
39
40
|
/**
|
package/dist/core/input.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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/dist/core/schedule.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
*
|
|
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
|
+
"version": "0.32.4",
|
|
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",
|