bizdays-toolkit 0.32.5 → 0.32.6
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 +8 -1
- package/dist/core/calendar.js +11 -3
- package/dist/core/diagnose.js +88 -13
- package/dist/core/schedule.js +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.32.6] - 2026-11-20
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- The option diagnostics could report as `redundant` a rule or date whose removal changed the results, breaking the promise that the reported rules can be removed all together. This happened for an item that takes effect only outside the effective period of another rule (after its `effectiveTo` or before its `effectiveFrom`), for an item that takes effect only outside the supported years of a holiday provider used with `outOfRangePolicy: "ignore"`, and, in a schedule without a holiday provider (or with `"ignore"`), for an item whose days depend on how the counting calendar (`calendar`) of an nth-business-day rule changes outside the years checked: effective periods, specific dates, `interval` or `cycle` rules and holiday providers inside that calendar, including combined calendars and calendars made from schedules (a schedule counted on a calendar with Japan's holidays is one such setup), and days on which the counting calendar throws outside its supported years. The diagnostics now also check one cycle of the rules on each side of each such boundary, so the years in the messages can be wider (for example `checked 1963-2028`). When they cannot read the counting calendar (an object shaped like a calendar but not made by `createCalendar`, `combineCalendars` or `createCalendarFromSchedule`) or the range would be too long, they no longer report the annual dates and recurring rules of those options as `redundant`, or the rules counted on that calendar as `never-matches`. For the same reason, `no-business-day` is no longer reported for options that have business days after an effective period ends. A date range in `closedDates`, `openDates` or a schedule's `dates` that is longer than 200 years is no longer reported as `redundant`, because the diagnostics do not check all of its days, and options in which such a range closes every remaining day (for example up to 9999-12-31) no longer get `no-business-day`. The results of calendars and schedules do not change. Most options get fewer items; in some, another rule is now reported as `redundant` in place of the incorrect item (it can be removed together with the other reported rules). If you removed rules because an earlier version reported them as `redundant`, check that the results you rely on have not changed
|
|
14
|
+
|
|
9
15
|
## [0.32.5] - 2026-11-18
|
|
10
16
|
|
|
11
17
|
### Changed
|
|
@@ -1038,7 +1044,8 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
|
|
|
1038
1044
|
|
|
1039
1045
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
1040
1046
|
|
|
1041
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.
|
|
1047
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.6...HEAD
|
|
1048
|
+
[0.32.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.5...v0.32.6
|
|
1042
1049
|
[0.32.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.4...v0.32.5
|
|
1043
1050
|
[0.32.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.3...v0.32.4
|
|
1044
1051
|
[0.32.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.2...v0.32.3
|
package/dist/core/calendar.js
CHANGED
|
@@ -4,7 +4,7 @@ import { isOptionsObject } from "./options.js";
|
|
|
4
4
|
import { renameKeys, writtenKey } from "./renamed.js";
|
|
5
5
|
import { distinctTimeZones, parseTimeOfDaySeconds, toCivil } from "./input.js";
|
|
6
6
|
import { checkClosingDay, closingDayIn, closingMonth as calendarClosingMonth, dayOfMonth, formatMonth, isDayOfMonthValue, parseMonth, readsAsDate, shiftMonth, } from "./month.js";
|
|
7
|
-
import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, infoOfSchedule, valuesOfSchedule, isWeekday, mapDays, RECURRING_RULE_KEYS, jpUsage, } from "./schedule.js";
|
|
7
|
+
import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, infoOfSchedule, PARTS, partsHolder, partsOf, valuesOfSchedule, isWeekday, mapDays, RECURRING_RULE_KEYS, jpUsage, } from "./schedule.js";
|
|
8
8
|
export const CALENDAR_OPTION_KEYS = [
|
|
9
9
|
"holidayProvider",
|
|
10
10
|
"timeZone",
|
|
@@ -222,7 +222,9 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
222
222
|
}
|
|
223
223
|
return found;
|
|
224
224
|
}
|
|
225
|
+
const parts = partsHolder(partsOf(lookup));
|
|
225
226
|
const calendar = {
|
|
227
|
+
[PARTS]: parts,
|
|
226
228
|
timeZone: lookup.timeZone,
|
|
227
229
|
providers: lookup.providers,
|
|
228
230
|
outOfRangePolicy: lookup.outOfRangePolicy,
|
|
@@ -324,6 +326,8 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
324
326
|
businessDaysBetween: (from, to) => calendar.diffBusinessDays(from, to),
|
|
325
327
|
listBusinessDays: (from, to) => calendar.businessDatesBetween(from, to),
|
|
326
328
|
};
|
|
329
|
+
parts.owner = calendar;
|
|
330
|
+
Object.freeze(parts);
|
|
327
331
|
return Object.freeze(calendar);
|
|
328
332
|
}
|
|
329
333
|
function optionsObject(options, what, rename = (v) => v, required = false, code = "invalid-argument") {
|
|
@@ -381,15 +385,17 @@ export function combineCalendars(calendars, options) {
|
|
|
381
385
|
});
|
|
382
386
|
const merge = (lists) => {
|
|
383
387
|
const byDate = new Map();
|
|
384
|
-
for (const
|
|
385
|
-
for (const h of
|
|
388
|
+
for (const holidays of lists)
|
|
389
|
+
for (const h of holidays)
|
|
386
390
|
if (!byDate.has(h.date))
|
|
387
391
|
byDate.set(h.date, h);
|
|
388
392
|
return Object.freeze([...byDate.values()].sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0)));
|
|
389
393
|
};
|
|
390
394
|
const holidayOn = (input) => list.map((c) => c.holidayOn(input)).find((h) => h !== undefined);
|
|
395
|
+
const parts = partsHolder(list);
|
|
391
396
|
const lookup = {
|
|
392
397
|
...base,
|
|
398
|
+
[PARTS]: parts,
|
|
393
399
|
isHoliday: (input) => holidayOn(input) !== undefined,
|
|
394
400
|
holidayOn,
|
|
395
401
|
getHoliday: holidayOn,
|
|
@@ -425,6 +431,8 @@ export function combineCalendars(calendars, options) {
|
|
|
425
431
|
result.decidedByPath = Object.freeze([decidedBy, ...(decided.decidedByPath ?? [])]);
|
|
426
432
|
return Object.freeze(result);
|
|
427
433
|
}
|
|
434
|
+
parts.owner = lookup;
|
|
435
|
+
Object.freeze(parts);
|
|
428
436
|
return buildCalendar(lookup, isOpen, info, searchDayLimit);
|
|
429
437
|
}
|
|
430
438
|
export function createCalendarFromSchedule(schedule, isOpen, options) {
|
package/dist/core/diagnose.js
CHANGED
|
@@ -3,7 +3,7 @@ import { compileCalendarOptions } from "./calendar.js";
|
|
|
3
3
|
import { internalError, InternalError, describeValue, IssueCollector, rangeError, } from "./errors.js";
|
|
4
4
|
import { isOptionsObject } from "./options.js";
|
|
5
5
|
import { RENAMED_KEYS, RENAMED_VALUES } from "./renamed.js";
|
|
6
|
-
import { compileScheduleOptions, createBasis, createHolidayLookup, createResolver, lostShiftMessage, throwLostShift, inPeriod, MAX_HOLIDAY_RUN, jpUsage, matchMonthDay, matchPattern, isHolidayBasedRule, resultIgnoresHolidays, } from "./schedule.js";
|
|
6
|
+
import { compileScheduleOptions, createBasis, createHolidayLookup, createResolver, lostShiftMessage, throwLostShift, inPeriod, MAX_HOLIDAY_RUN, jpUsage, matchMonthDay, matchPattern, partsOf, isHolidayBasedRule, resultIgnoresHolidays, } from "./schedule.js";
|
|
7
7
|
function editDistance(a, b) {
|
|
8
8
|
const d = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
|
|
9
9
|
for (let i = 1; i <= a.length; i++) {
|
|
@@ -99,6 +99,7 @@ function patternCycle(rules) {
|
|
|
99
99
|
}
|
|
100
100
|
return Math.min(lcm(PATTERN_DAYS, days), max);
|
|
101
101
|
}
|
|
102
|
+
const MAX_SCAN_DAYS = 366 * MAX_WINDOW_YEARS * 3;
|
|
102
103
|
function clipYears(from, to) {
|
|
103
104
|
if (to - from + 1 <= MAX_WINDOW_YEARS)
|
|
104
105
|
return [from, to];
|
|
@@ -107,8 +108,41 @@ function clipYears(from, to) {
|
|
|
107
108
|
return a <= b ? [a, b] : [from, from + MAX_WINDOW_YEARS - 1];
|
|
108
109
|
}
|
|
109
110
|
const dayOfYear = (year, last) => toDayNumber(`${String(year).padStart(4, "0")}-${last ? "12-31" : "01-01"}`);
|
|
110
|
-
function
|
|
111
|
+
function collectBasis(calendar, inside) {
|
|
112
|
+
const parts = partsOf(calendar);
|
|
113
|
+
if (parts === undefined)
|
|
114
|
+
return false;
|
|
115
|
+
if (Array.isArray(parts))
|
|
116
|
+
return parts.every((c) => collectBasis(c, inside));
|
|
117
|
+
const { source, annual, recurring, dates } = parts;
|
|
118
|
+
for (const { supportedYears } of source.providers) {
|
|
119
|
+
const [from, to] = clipYears(supportedYears.from, supportedYears.to);
|
|
120
|
+
inside.spans.push({ from: dayOfYear(from, false), to: dayOfYear(to, true) });
|
|
121
|
+
inside.edges.push(dayOfYear(supportedYears.from, false), dayOfYear(supportedYears.to, true) + 1);
|
|
122
|
+
}
|
|
123
|
+
for (const r of [...annual, ...recurring]) {
|
|
124
|
+
if (r.effectiveFrom !== null)
|
|
125
|
+
inside.edges.push(r.effectiveFrom);
|
|
126
|
+
if (r.effectiveTo !== null)
|
|
127
|
+
inside.edges.push(r.effectiveTo + 1);
|
|
128
|
+
}
|
|
129
|
+
for (const r of dates)
|
|
130
|
+
inside.edges.push(r.from, r.to + 1);
|
|
131
|
+
inside.rules.push(...recurring);
|
|
132
|
+
return recurring.every((r) => r.calendar === null || collectBasis(r.calendar, inside));
|
|
133
|
+
}
|
|
134
|
+
const crossesShortCentury = ({ from, to }) => {
|
|
135
|
+
const last = yearOf(Math.min(to, MAX_DAY));
|
|
136
|
+
for (let y = Math.ceil(yearOf(Math.max(from, MIN_DAY)) / 100) * 100; y <= last; y += 100)
|
|
137
|
+
if (y % 400 !== 0)
|
|
138
|
+
return true;
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
141
|
+
function scanWindow(source, rules, cycle, inside) {
|
|
111
142
|
const ranges = [];
|
|
143
|
+
const side = (day, before) => before
|
|
144
|
+
? { from: day - openEndedDays(day - cycle + 1, cycle) + 1, to: day }
|
|
145
|
+
: { from: day, to: day + openEndedDays(day, cycle) - 1 };
|
|
112
146
|
let extend = true;
|
|
113
147
|
if (source.providers.length === 0) {
|
|
114
148
|
ranges.push({ from: PATTERN_FROM, to: PATTERN_FROM + cycle - 1 });
|
|
@@ -128,6 +162,8 @@ function scanWindow(source, rules, cycle) {
|
|
|
128
162
|
}
|
|
129
163
|
if (from > to)
|
|
130
164
|
return undefined;
|
|
165
|
+
if (extend)
|
|
166
|
+
ranges.push(side(dayOfYear(from, false) - 1, true), side(dayOfYear(to, true) + 1, false));
|
|
131
167
|
[from, to] = clipYears(from, to);
|
|
132
168
|
ranges.push({ from: dayOfYear(from, false), to: dayOfYear(to, true) });
|
|
133
169
|
}
|
|
@@ -136,10 +172,26 @@ function scanWindow(source, rules, cycle) {
|
|
|
136
172
|
if (rule.effectiveFrom === null && rule.effectiveTo === null)
|
|
137
173
|
continue;
|
|
138
174
|
const span = periodSpan(rule, cycle);
|
|
139
|
-
|
|
140
|
-
|
|
175
|
+
ranges.push({
|
|
176
|
+
from: span.from,
|
|
177
|
+
to: Math.min(span.to, span.from + 366 * MAX_WINDOW_YEARS - 1),
|
|
178
|
+
});
|
|
179
|
+
if (rule.effectiveTo !== null)
|
|
180
|
+
ranges.push(side(rule.effectiveTo + 1, false));
|
|
181
|
+
if (rule.effectiveFrom !== null)
|
|
182
|
+
ranges.push(side(rule.effectiveFrom - 1, true));
|
|
183
|
+
}
|
|
184
|
+
if (inside) {
|
|
185
|
+
for (const e of inside.edges)
|
|
186
|
+
ranges.push(side(e - 1, true), side(e, false));
|
|
187
|
+
ranges.push(...inside.spans);
|
|
141
188
|
}
|
|
142
189
|
}
|
|
190
|
+
for (let i = 0; i < ranges.length; i++)
|
|
191
|
+
ranges[i] = { from: Math.max(ranges[i].from, MIN_DAY), to: Math.min(ranges[i].to, MAX_DAY) };
|
|
192
|
+
for (let i = ranges.length - 1; i >= 0; i--)
|
|
193
|
+
if (ranges[i].from > ranges[i].to)
|
|
194
|
+
ranges.splice(i, 1);
|
|
143
195
|
ranges.sort((a, b) => a.from - b.from);
|
|
144
196
|
const merged = [];
|
|
145
197
|
for (const r of ranges) {
|
|
@@ -151,10 +203,28 @@ function scanWindow(source, rules, cycle) {
|
|
|
151
203
|
}
|
|
152
204
|
const yearOf = (n) => parseDate(fromDayNumber(n)).year;
|
|
153
205
|
const label = merged.map((r) => `${yearOf(r.from)}-${yearOf(r.to)}`).join(", ");
|
|
154
|
-
return { ranges: merged, label };
|
|
206
|
+
return { ranges: merged, label, blind: false };
|
|
155
207
|
}
|
|
156
|
-
export function rulesScanWindow(compiled
|
|
157
|
-
|
|
208
|
+
export function rulesScanWindow(compiled) {
|
|
209
|
+
const source = compiled.source;
|
|
210
|
+
const rules = [...compiled.annual, ...compiled.recurring];
|
|
211
|
+
const inside = { edges: [], spans: [], rules: [] };
|
|
212
|
+
const known = compiled.recurring.every((r) => r.calendar === null || collectBasis(r.calendar, inside));
|
|
213
|
+
const own = patternCycle(compiled.recurring);
|
|
214
|
+
const cycle = patternCycle([...compiled.recurring, ...inside.rules]);
|
|
215
|
+
const window = known ? scanWindow(source, rules, cycle, inside) : scanWindow(source, rules, own);
|
|
216
|
+
if (!window)
|
|
217
|
+
return window;
|
|
218
|
+
const max = 366 * MAX_WINDOW_YEARS;
|
|
219
|
+
const days = window.ranges.reduce((sum, r) => sum + r.to - r.from + 1, 0);
|
|
220
|
+
const blind = !known ||
|
|
221
|
+
(cycle >= max && own < max) ||
|
|
222
|
+
days > MAX_SCAN_DAYS ||
|
|
223
|
+
(inside.rules.some((r) => r.interval !== null || r.cycle !== null) &&
|
|
224
|
+
window.ranges.some(crossesShortCentury));
|
|
225
|
+
if (!blind)
|
|
226
|
+
return window;
|
|
227
|
+
return { ...(known ? scanWindow(source, rules, own) : window), blind };
|
|
158
228
|
}
|
|
159
229
|
function eachDay(window, fn) {
|
|
160
230
|
for (const { from, to } of window.ranges) {
|
|
@@ -395,8 +465,8 @@ export function unjudgeableDays(compiled, window) {
|
|
|
395
465
|
}
|
|
396
466
|
return { days, months };
|
|
397
467
|
}
|
|
398
|
-
export function unsureOf(compiled, unknown) {
|
|
399
|
-
if (unknown.days.size === 0)
|
|
468
|
+
export function unsureOf(compiled, unknown, blind = false) {
|
|
469
|
+
if (unknown.days.size === 0 && !blind)
|
|
400
470
|
return () => false;
|
|
401
471
|
const sorted = [...unknown.days].sort((a, b) => a - b);
|
|
402
472
|
const overlaps = (start, end) => {
|
|
@@ -432,6 +502,8 @@ export function unsureOf(compiled, unknown) {
|
|
|
432
502
|
return false;
|
|
433
503
|
if (isDate(item))
|
|
434
504
|
return overlaps(item.from, item.to);
|
|
505
|
+
if (blind)
|
|
506
|
+
return true;
|
|
435
507
|
return overlaps(item.effectiveFrom, item.effectiveTo);
|
|
436
508
|
};
|
|
437
509
|
}
|
|
@@ -479,10 +551,11 @@ export function dropUnsure(c, from, unsure, recorded, unknown) {
|
|
|
479
551
|
throw internalError(`a diagnostic about an unjudgeable month was left: ${left.code} ${left.path}`);
|
|
480
552
|
}
|
|
481
553
|
function analyze(c, original, isCalendar) {
|
|
482
|
-
const
|
|
554
|
+
const window = rulesScanWindow(original);
|
|
555
|
+
const unknown = unjudgeableDays(original, window);
|
|
483
556
|
const recorded = new Set();
|
|
484
557
|
const compiled = guardBases(original, recorded);
|
|
485
|
-
const unsure = unsureOf(original, unknown);
|
|
558
|
+
const unsure = unsureOf(original, unknown, window?.blind);
|
|
486
559
|
const from = c.issues.length;
|
|
487
560
|
analyzeRules(c, compiled, isCalendar, unsure);
|
|
488
561
|
dropUnsure(c, from, unsure, recorded, unknown);
|
|
@@ -497,7 +570,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
497
570
|
});
|
|
498
571
|
const basis = createBasis(compiled, lookup);
|
|
499
572
|
const cycle = patternCycle(recurring);
|
|
500
|
-
const window = rulesScanWindow(compiled
|
|
573
|
+
const window = rulesScanWindow(compiled);
|
|
501
574
|
const unused = new Set();
|
|
502
575
|
checkLostShifts(c, compiled, lookup, window);
|
|
503
576
|
dates.forEach((rule, j) => {
|
|
@@ -803,7 +876,9 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
803
876
|
const decided = [];
|
|
804
877
|
const span = [];
|
|
805
878
|
let checked = 0;
|
|
806
|
-
|
|
879
|
+
if (rule.to - rule.from + 1 > MAX_DATE_RULE_DAYS)
|
|
880
|
+
return false;
|
|
881
|
+
const last = rule.to;
|
|
807
882
|
for (let n = rule.from; n <= last; n++) {
|
|
808
883
|
span.push(n);
|
|
809
884
|
let decidedBy;
|
package/dist/core/schedule.js
CHANGED
|
@@ -1122,6 +1122,15 @@ export function mapDays(from, to, fn) {
|
|
|
1122
1122
|
return Object.freeze(result);
|
|
1123
1123
|
}
|
|
1124
1124
|
const INTERNAL_INFO = Symbol("bizdays-toolkit.scheduleInfo");
|
|
1125
|
+
export const PARTS = Symbol("bizdays-toolkit.parts");
|
|
1126
|
+
export const partsHolder = (value) => ({
|
|
1127
|
+
owner: undefined,
|
|
1128
|
+
value,
|
|
1129
|
+
});
|
|
1130
|
+
export function partsOf(object) {
|
|
1131
|
+
const holder = object[PARTS];
|
|
1132
|
+
return holder?.owner === object ? holder.value : undefined;
|
|
1133
|
+
}
|
|
1125
1134
|
const INTERNAL_VALUES = Symbol("bizdays-toolkit.scheduleValues");
|
|
1126
1135
|
export function valuesOfSchedule(schedule) {
|
|
1127
1136
|
return schedule[INTERNAL_VALUES] ?? [];
|
|
@@ -1136,9 +1145,11 @@ export function buildSchedule(compiled) {
|
|
|
1136
1145
|
const values = Object.freeze(typeof compiled.holiday === "object" && "value" in compiled.holiday
|
|
1137
1146
|
? [...compiled.weekly, compiled.holiday.value]
|
|
1138
1147
|
: [...compiled.weekly]);
|
|
1148
|
+
const parts = partsHolder(compiled);
|
|
1139
1149
|
const schedule = {
|
|
1140
1150
|
[INTERNAL_INFO]: info,
|
|
1141
1151
|
[INTERNAL_VALUES]: values,
|
|
1152
|
+
[PARTS]: parts,
|
|
1142
1153
|
timeZone: lookup.timeZone,
|
|
1143
1154
|
providers: lookup.providers,
|
|
1144
1155
|
outOfRangePolicy: lookup.outOfRangePolicy,
|
|
@@ -1159,6 +1170,8 @@ export function buildSchedule(compiled) {
|
|
|
1159
1170
|
dayInfo: (input) => info(lookup.dateOf(input)),
|
|
1160
1171
|
daysBetween: (from, to) => mapDays(lookup.dateOf(from), lookup.dateOf(to), info),
|
|
1161
1172
|
};
|
|
1173
|
+
parts.owner = schedule;
|
|
1174
|
+
Object.freeze(parts);
|
|
1162
1175
|
return Object.freeze(schedule);
|
|
1163
1176
|
}
|
|
1164
1177
|
export function createSchedule(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.6",
|
|
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",
|