bizdays-toolkit 0.31.8 → 0.31.9
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 +17 -1
- package/README.md +1 -1
- package/dist/core/date.d.ts +4 -4
- package/dist/core/date.js +6 -1
- package/dist/core/diagnose.js +32 -7
- package/dist/core/errors.d.ts +2 -1
- package/dist/core/schedule.d.ts +5 -1
- package/dist/core/schedule.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,21 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.31.9] - 2026-11-14
|
|
10
|
+
|
|
11
|
+
This version removes two wrong diagnostics, makes evaluation and the option diagnostics faster, and documents how time zone names are compared. Results of calendars and schedules do not change.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- The option diagnostics reported `never-matches` (a warning) for a recurring rule that does match, when its effective period is open on one side and the 28 years scanned from the other end reach a year divisible by 100 but not by 400 (such as 1900 or 2100). For example, `{ weekday: 1, nth: 5, months: [2], effectiveFrom: "2073-01-01" }` first matches on 2112-02-29, and removing the rule as the warning suggested changed that day. Such a period is now scanned for 56 years, which contain every combination of weekday and date, and `redundant` is decided over the same range. The guide and the design decisions (31) described this as a limit in 0.31.7 and now describe the new range; rules with `interval` or `cycle` remain an approximation across such a year. Only the wrong warning disappears (a wrong diagnostic may disappear in a patch version; design decisions 33)
|
|
16
|
+
- `diagnoseSchedule` returned a second `error`, a `time-zone-conflict` at the `calendar` of an nth-business-day rule, when the time zone of the schedule itself could not be determined (an invalid `timeZone`, or holiday providers with different time zones and no `timeZone`). It compared the calendar with a placeholder that the options do not mention (`"UTC"`, or the time zone of the first provider). It now returns only the error at `timeZone`, the one that `createSchedule` throws (design decisions 30). A conflict with a valid `timeZone` is reported as before
|
|
17
|
+
- Documentation: the guide, the type descriptions of `HolidayLookup.timeZone` and of `time-zone-conflict` in `KnownErrorCode`, and the design decisions (18) now say that `timeZone` returns the name the runtime's `Intl` reports, which can differ from the spelling in the options and from one runtime to another, and that time zones are compared by that name. Aliases of one time zone (such as `"UTC"` and `"Etc/UTC"`, or `"Asia/Kolkata"` and `"Asia/Calcutta"`) are therefore accepted on Node.js but are a `time-zone-conflict` on a runtime that does not turn aliases into one name (confirmed on Bun 1.4.3 and Safari 27.2). Results are unchanged. Write the same spelling wherever time zones must match; which time zones count as the same will be defined in the next minor version
|
|
18
|
+
- Documentation: the design decisions said that a mistyped option is a type error in TypeScript (8). That holds only for options written as an object literal: passing a holiday provider or a calendar itself as the options (`createCalendar(jp)`) compiles and makes a calendar without holidays, and the diagnostics report `unknown-option`. The design decisions also said that the supported years do not matter to the diagnostics (17) and that effective periods outside the scanned range are scanned (31); with `outOfRangePolicy: "throw"` only the supported years are scanned, as the guide said. The design decisions (18) now give the reasons why `combineCalendars` throws for fewer than two calendars and for the same calendar twice, and the guide says to remove duplicates before handling the case of one calendar. The bundle sizes in the README were measured again for 0.31.9
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Evaluating a day and the option diagnostics are faster. The date string of the day was parsed again by every step of the evaluation and by every rule; the last parsed date is now remembered. The parsed result depends only on the string, so results are unchanged (design decisions 16)
|
|
23
|
+
|
|
9
24
|
## [0.31.8] - 2026-11-13
|
|
10
25
|
|
|
11
26
|
This version fixes one input that was silently accepted and corrects type descriptions and documents. Results of calls that were written correctly do not change.
|
|
@@ -959,7 +974,8 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
|
|
|
959
974
|
|
|
960
975
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
961
976
|
|
|
962
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.
|
|
977
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.9...HEAD
|
|
978
|
+
[0.31.9]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.8...v0.31.9
|
|
963
979
|
[0.31.8]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.7...v0.31.8
|
|
964
980
|
[0.31.7]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.6...v0.31.7
|
|
965
981
|
[0.31.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.5...v0.31.6
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ A business-day calendar that combines public holidays with company or store clos
|
|
|
23
23
|
- **Recurring rules**: "closed on the 3rd Wednesday", "every other Wednesday", "stocktaking on the last day of the month", "closed on Mondays, moved to the next non-holiday when Monday is a holiday", "the day after (or before) a holiday", "the last weekday before a bank holiday", shift cycles such as four days on and two days off, each with its own behaviour on holidays and an optional effective period
|
|
24
24
|
- **Day-by-day values and combined calendars**: store hours that change by weekday, holiday and date; a business-day calendar made from such a schedule; and the days on which all (or any) of several calendars are open
|
|
25
25
|
- **Option diagnostics**: `bizdays-toolkit/diagnose` lists rules that never apply, rules that are shadowed or redundant, rules that have ended, typos in option names and options with no business day at all, without throwing. One line in a test keeps options honest
|
|
26
|
-
- **Lightweight, zero dependencies, time-zone safe**: about 14.
|
|
26
|
+
- **Lightweight, zero dependencies, time-zone safe**: about 14.2 KB min+gzip (about 15.9 KB with Japanese holidays, about 16.4 KB with UK bank holidays, about 15.1 KB with French holidays, about 15.1 KB with Singapore holidays; measured for 0.31.9). Standard JavaScript and `Intl` only, ESM with bundled types; tested on Node.js, Chrome, Firefox, Edge, Safari, Cloudflare Workers, Bun and Deno. Instants such as `Date` are converted to a civil date in the calendar's time zone before evaluation
|
|
27
27
|
- **Extensible to other countries and regions**: holiday providers are pluggable through the `HolidayProvider` interface, and `bizdays-toolkit/provider` exposes the calendar arithmetic (nth weekday of a month, Easter, substitute days for holidays on a weekend) that most countries' holidays are built from
|
|
28
28
|
|
|
29
29
|
## Installation
|
package/dist/core/date.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ export type DateString = string;
|
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
16
|
export type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
17
|
-
/** 年月日に分解する。形式または暦として不正なら RangeError */
|
|
17
|
+
/** 年月日に分解する。形式または暦として不正なら RangeError。返すオブジェクトは変更できない */
|
|
18
18
|
export declare function parseDate(value: string): {
|
|
19
|
-
year: number;
|
|
20
|
-
month: number;
|
|
21
|
-
day: number;
|
|
19
|
+
readonly year: number;
|
|
20
|
+
readonly month: number;
|
|
21
|
+
readonly day: number;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* "YYYY-MM-DD" として正しい暦日か。
|
package/dist/core/date.js
CHANGED
|
@@ -2,7 +2,11 @@ import { describeValue, rangeError } from "./errors.js";
|
|
|
2
2
|
const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
3
|
const MS_PER_DAY = 86_400_000;
|
|
4
4
|
const MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
5
|
+
let lastValue = "2000-01-01";
|
|
6
|
+
let lastParts = Object.freeze({ year: 2000, month: 1, day: 1 });
|
|
5
7
|
export function parseDate(value) {
|
|
8
|
+
if (value === lastValue)
|
|
9
|
+
return lastParts;
|
|
6
10
|
const m = typeof value === "string" ? DATE_RE.exec(value) : null;
|
|
7
11
|
if (!m) {
|
|
8
12
|
throw rangeError("invalid-date", `Invalid date string: ${describeValue(value)} (expected YYYY-MM-DD)`);
|
|
@@ -13,7 +17,8 @@ export function parseDate(value) {
|
|
|
13
17
|
if (year < 1000 || month < 1 || month > 12 || day < 1 || day > lengthOfMonth(year, month)) {
|
|
14
18
|
throw rangeError("invalid-date", `Invalid date: ${describeValue(value)}`);
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
lastValue = value;
|
|
21
|
+
return (lastParts = Object.freeze({ year, month, day }));
|
|
17
22
|
}
|
|
18
23
|
export function isValidDate(input) {
|
|
19
24
|
if (typeof input !== "string")
|
package/dist/core/diagnose.js
CHANGED
|
@@ -53,6 +53,28 @@ const MAX_WINDOW_YEARS = 200;
|
|
|
53
53
|
const MAX_DATE_RULE_DAYS = 366 * MAX_WINDOW_YEARS;
|
|
54
54
|
const atCalendarEdge = (n, error) => (n < MIN_DAY + MAX_HOLIDAY_RUN || n > MAX_DAY - MAX_HOLIDAY_RUN) &&
|
|
55
55
|
error?.code === "out-of-range";
|
|
56
|
+
function openEndedDays(from, days) {
|
|
57
|
+
const lo = Math.max(from, MIN_DAY);
|
|
58
|
+
const hi = Math.min(from + days - 1, MAX_DAY);
|
|
59
|
+
if (lo > hi)
|
|
60
|
+
return days;
|
|
61
|
+
const last = yearOf(hi);
|
|
62
|
+
for (let y = Math.ceil(yearOf(lo) / 100) * 100; y <= last; y += 100)
|
|
63
|
+
if (y % 400 !== 0)
|
|
64
|
+
return Math.max(days, 2 * PATTERN_DAYS);
|
|
65
|
+
return days;
|
|
66
|
+
}
|
|
67
|
+
function periodSpan(rule, cycle) {
|
|
68
|
+
const { effectiveFrom, effectiveTo } = rule;
|
|
69
|
+
if (effectiveFrom === null) {
|
|
70
|
+
const to = effectiveTo;
|
|
71
|
+
return { from: to - openEndedDays(to - cycle + 1, cycle) + 1, to };
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
from: effectiveFrom,
|
|
75
|
+
to: effectiveTo ?? effectiveFrom + openEndedDays(effectiveFrom, cycle) - 1,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
56
78
|
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
|
|
57
79
|
const lcm = (a, b) => (a / gcd(a, b)) * b;
|
|
58
80
|
function patternCycle(rules) {
|
|
@@ -102,9 +124,9 @@ function scanWindow(source, rules, cycle) {
|
|
|
102
124
|
for (const rule of rules) {
|
|
103
125
|
if (rule.effectiveFrom === null && rule.effectiveTo === null)
|
|
104
126
|
continue;
|
|
105
|
-
const
|
|
106
|
-
const to = Math.min(
|
|
107
|
-
ranges.push({ from: Math.max(from, MIN_DAY), to: Math.min(to, MAX_DAY) });
|
|
127
|
+
const span = periodSpan(rule, cycle);
|
|
128
|
+
const to = Math.min(span.to, span.from + 366 * MAX_WINDOW_YEARS - 1);
|
|
129
|
+
ranges.push({ from: Math.max(span.from, MIN_DAY), to: Math.min(to, MAX_DAY) });
|
|
108
130
|
}
|
|
109
131
|
}
|
|
110
132
|
ranges.sort((a, b) => a.from - b.from);
|
|
@@ -140,10 +162,13 @@ function patternBits(rule) {
|
|
|
140
162
|
return bits;
|
|
141
163
|
}
|
|
142
164
|
function matchesAnyDay(rule, cycle) {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
165
|
+
const span = rule.effectiveFrom === null && rule.effectiveTo === null
|
|
166
|
+
? { from: PATTERN_FROM, to: PATTERN_FROM + cycle - 1 }
|
|
167
|
+
: periodSpan(rule, cycle);
|
|
168
|
+
const to = rule.effectiveFrom !== null && rule.effectiveTo !== null
|
|
169
|
+
? Math.min(span.to, span.from + openEndedDays(span.from, cycle) - 1)
|
|
170
|
+
: span.to;
|
|
171
|
+
for (let n = Math.max(span.from, MIN_DAY); n <= Math.min(to, MAX_DAY); n++)
|
|
147
172
|
if (matchPattern(rule, fromDayNumber(n)))
|
|
148
173
|
return true;
|
|
149
174
|
return false;
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -32,7 +32,8 @@ export type KnownErrorCode =
|
|
|
32
32
|
| "invalid-option"
|
|
33
33
|
/**
|
|
34
34
|
* 同じタイムゾーンでなければならないものが食い違う(1 つの設定の祝日の提供元どうしで、timeZone の指定がない。
|
|
35
|
-
* 合成するカレンダーどうし。スケジュールと、第 n
|
|
35
|
+
* 合成するカレンダーどうし。スケジュールと、第 n 営業日の規則の数える基準のカレンダー)。実行環境の Intl が返す名前が
|
|
36
|
+
* 同じかで比べるので、別名どうし("UTC" と "Etc/UTC" など)は、別名を同じ名前に直さない実行環境では食い違いになる
|
|
36
37
|
*/
|
|
37
38
|
| "time-zone-conflict"
|
|
38
39
|
/**
|
package/dist/core/schedule.d.ts
CHANGED
|
@@ -532,7 +532,11 @@ export interface ScheduleDayInfo<Value, Kind extends string = string> {
|
|
|
532
532
|
* @public
|
|
533
533
|
*/
|
|
534
534
|
export interface HolidayLookup<Kind extends string = string> {
|
|
535
|
-
/**
|
|
535
|
+
/**
|
|
536
|
+
* 日時の入力を暦日に変換するタイムゾーン。実行環境の Intl が返す名前で、設定に書いた綴りと違うことがあり、実行環境によっても
|
|
537
|
+
* 違う("Asia/Kolkata" と書くと、Node.js では "Asia/Calcutta"、Bun では "Asia/Kolkata")。同じタイムゾーンかは、この名前が
|
|
538
|
+
* 同じかで比べる(違えば time-zone-conflict)
|
|
539
|
+
*/
|
|
536
540
|
readonly timeZone: string;
|
|
537
541
|
/** 祝日の提供元 */
|
|
538
542
|
readonly providers: readonly HolidayProvider<Kind>[];
|
package/dist/core/schedule.js
CHANGED
|
@@ -987,8 +987,9 @@ export function compileScheduleOptions(c, options) {
|
|
|
987
987
|
const annual = compileAnnualRules(c, "annualDates", o["annualDates"], requiredValue(c), false, true);
|
|
988
988
|
const dates = compileDateRules(c, "dates", o["dates"], requiredValue(c), false, true);
|
|
989
989
|
const recurring = compileRecurringRules(c, "recurringRules", o["recurringRules"], requiredValue(c), [...RECURRING_RULE_KEYS, "value"], "schedule", writtenKey(["source", "schedule"], written, "recurringRules"), jpUsage(source));
|
|
990
|
+
const zoneKnown = !c.issues.some((i) => i.severity === "error" && i.path === "timeZone");
|
|
990
991
|
for (const rule of recurring) {
|
|
991
|
-
if (rule.businessDays === null)
|
|
992
|
+
if (rule.businessDays === null || !zoneKnown)
|
|
992
993
|
continue;
|
|
993
994
|
const entry = o["recurringRules"][Number(/\[(\d+)\]$/.exec(rule.path)[1])];
|
|
994
995
|
const tz = entry["calendar"].timeZone;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.9",
|
|
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",
|