bizdays-toolkit 0.32.7 → 0.32.8
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 +13 -1
- package/README.md +1 -1
- package/dist/core/diagnose.js +92 -17
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,17 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.32.8] - 2026-11-23
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- The option diagnostics of a calendar could report a rule as `never-matches` or `redundant` although removing it changed the results, breaking the promise that the reported rules can be removed all together (design decisions 31). This happened in calendar options with an nth-business-day rule that counts the calendar's own business days (`businessDayOfMonth` or `businessDayOfWeek` in `closedRecurringRules` or `openRecurringRules`) and specific dates (`closedDates`, `openDates`), because a specific date changes the count in its month and week: when a date lies outside the years the diagnostics scan (2001–2028 without a holiday provider, so any date from 2029 on or before 2001), or when a long date range covers those years (for example `{ from: "1000-01-01", to: "2029-03-31" }` before opening). The diagnostics now check the scanned years without the specific dates and, in addition, the month and the six days around it at both ends of every specific date, also outside the scanned years. Most such options get fewer items; in some, the incorrect item is replaced by a correct one (a rule that matches only days decided by a specific date is reported as `redundant` instead of `never-matches`, a duplicate rule as `shadowed` instead of `never-matches`, or another rule as `redundant`). In such options, a rule that is used only on days inside a long specific date range is no longer reported as unused, as in options without such an nth-business-day rule. Options with many specific dates outside the scanned years take longer to diagnose (on the maintainer's machine, about two to four times as long as 0.32.7 with 1,000 such dates)
|
|
14
|
+
- For the same reason, `no-business-day` could be reported for such options although they have business days (a closed date moves the nth business day of its month to a day that the rules alone close)
|
|
15
|
+
- With `unconfirmedHolidayPolicy: "throw"`, the diagnostics of calendars and schedules could report a rule as `redundant` although removing it made a day throw `unconfirmed-holiday` (the remaining rules, such as the origin of an `"after-holiday"` rule, then look up an unconfirmed holiday on that day). Such a rule is no longer reported
|
|
16
|
+
- `counting-basis` was reported for a weekly weekday rule that does not change how its weekday is counted: a closed rule on a weekday in `closedWeekdays`, or an open rule on a weekday not in it. The count already treats that weekday the same way
|
|
17
|
+
- Documentation: the guide and the design decisions (31) now say that `relatedPath` of `redundant` is found with all reported rules removed, that with `outOfRangePolicy: "throw"` the rules reported as `out-of-range` with "so this rule is never used" are removed together with the others, and that the promise covers the days that can be judged before the removal (a day that already throws can be judged after it). The design decisions (30) now describe the range checked for `no-business-day`. Results are unchanged
|
|
18
|
+
- None of these fixes changes the results of calendars and schedules. If you removed rules because an earlier version reported them as `redundant` or `never-matches`, check that the results you rely on have not changed. A test that compares the whole diagnostics of the options above (such as `assert.deepEqual`) needs the new items
|
|
19
|
+
|
|
9
20
|
## [0.32.7] - 2026-11-21
|
|
10
21
|
|
|
11
22
|
### Changed
|
|
@@ -1053,7 +1064,8 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
|
|
|
1053
1064
|
|
|
1054
1065
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
1055
1066
|
|
|
1056
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.
|
|
1067
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.8...HEAD
|
|
1068
|
+
[0.32.8]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.7...v0.32.8
|
|
1057
1069
|
[0.32.7]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.6...v0.32.7
|
|
1058
1070
|
[0.32.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.5...v0.32.6
|
|
1059
1071
|
[0.32.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.32.4...v0.32.5
|
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
|
|
26
|
+
- **Lightweight, zero dependencies, time-zone safe**: about 15.2 KB min+gzip (about 16.9 KB with Japanese holidays, about 17.4 KB with UK bank holidays, about 16.1 KB with French holidays, about 16.1 KB with Singapore holidays; measured for 0.32.8). Standard JavaScript and `Intl` only, ESM with bundled types; tested on Node.js, Chrome, Firefox, Edge, Safari, Cloudflare Workers, Bun and Deno (on Safari without Temporal, aliases of one time zone such as `"UTC"` and `"Etc/UTC"` are a `time-zone-conflict`: write the same spelling). 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/diagnose.js
CHANGED
|
@@ -512,6 +512,38 @@ export function unsureOf(compiled, unknown, blind = false) {
|
|
|
512
512
|
return overlaps(item.effectiveFrom, item.effectiveTo);
|
|
513
513
|
};
|
|
514
514
|
}
|
|
515
|
+
function dateUnitsOf(window, compiled) {
|
|
516
|
+
const { dates, recurring, source } = compiled;
|
|
517
|
+
if (!window || dates.length === 0)
|
|
518
|
+
return [];
|
|
519
|
+
if (!recurring.some((r) => r.businessDays !== null && r.calendar === null))
|
|
520
|
+
return [];
|
|
521
|
+
const throws = source.providers.length > 0 && source.outOfRangePolicy !== "ignore";
|
|
522
|
+
const lo = throws ? window.ranges[0].from : MIN_DAY;
|
|
523
|
+
const hi = throws ? window.ranges[window.ranges.length - 1].to : MAX_DAY;
|
|
524
|
+
const ranges = [];
|
|
525
|
+
for (const d of dates) {
|
|
526
|
+
for (const edge of d.from === d.to ? [d.from] : [d.from, d.to]) {
|
|
527
|
+
const { year, month, day } = parseDate(dateOfDayNumber(edge));
|
|
528
|
+
const from = Math.max(edge - day + 1 - 6, lo);
|
|
529
|
+
const to = Math.min(edge - day + lengthOfMonth(year, month) + 6, hi);
|
|
530
|
+
if (from <= to)
|
|
531
|
+
ranges.push({ from, to });
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return mergeRanges(ranges);
|
|
535
|
+
}
|
|
536
|
+
function mergeRanges(ranges) {
|
|
537
|
+
const merged = [];
|
|
538
|
+
for (const r of [...ranges].sort((x, y) => x.from - y.from)) {
|
|
539
|
+
const last = merged[merged.length - 1];
|
|
540
|
+
if (last && r.from <= last.to + 1)
|
|
541
|
+
merged[merged.length - 1] = { from: last.from, to: Math.max(last.to, r.to) };
|
|
542
|
+
else
|
|
543
|
+
merged.push(r);
|
|
544
|
+
}
|
|
545
|
+
return merged;
|
|
546
|
+
}
|
|
515
547
|
function checkLostShifts(c, compiled, lookup, window) {
|
|
516
548
|
const { source, recurring } = compiled;
|
|
517
549
|
const shifting = recurring.filter((r) => r.holidayOverlapPolicy === "after-holiday");
|
|
@@ -574,10 +606,24 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
574
606
|
unconfirmedHolidayPolicy: "accept",
|
|
575
607
|
});
|
|
576
608
|
const basis = createBasis(compiled, lookup);
|
|
609
|
+
const strictLookup = source.unconfirmedHolidayPolicy === "throw" ? createHolidayLookup({ ...source }) : null;
|
|
577
610
|
const cycle = patternCycle(recurring);
|
|
578
|
-
const
|
|
611
|
+
const rulesWindow = rulesScanWindow(compiled);
|
|
612
|
+
const dateUnits = dateUnitsOf(rulesWindow, compiled);
|
|
613
|
+
const window = rulesWindow && dateUnits.length > 0
|
|
614
|
+
? { ...rulesWindow, ranges: mergeRanges([...rulesWindow.ranges, ...dateUnits]) }
|
|
615
|
+
: rulesWindow;
|
|
616
|
+
const inDateUnits = (n) => dateUnits.some((r) => r.from <= n && n <= r.to);
|
|
617
|
+
const resolverIn = (base, using = lookup) => {
|
|
618
|
+
const withDates = createResolver(base, using, throwLostShift);
|
|
619
|
+
if (dateUnits.length === 0)
|
|
620
|
+
return withDates;
|
|
621
|
+
const noDates = createResolver({ ...base, dates: [] }, using, throwLostShift);
|
|
622
|
+
return (date, withHoliday) => (inDateUnits(dayNumberOf(date)) ? withDates : noDates)(date, withHoliday);
|
|
623
|
+
};
|
|
624
|
+
const basisNoDates = dateUnits.length > 0 ? createBasis({ ...compiled, dates: [] }, lookup) : basis;
|
|
579
625
|
const unused = new Set();
|
|
580
|
-
checkLostShifts(c, compiled, lookup,
|
|
626
|
+
checkLostShifts(c, compiled, lookup, rulesWindow);
|
|
581
627
|
dates.forEach((rule, j) => {
|
|
582
628
|
const fromYear = yearOf(rule.from);
|
|
583
629
|
const toYear = yearOf(rule.to);
|
|
@@ -661,7 +707,12 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
661
707
|
if (!inPeriod(rule, n))
|
|
662
708
|
return false;
|
|
663
709
|
try {
|
|
664
|
-
|
|
710
|
+
const date = dateOfDayNumber(n);
|
|
711
|
+
found =
|
|
712
|
+
matchPattern(rule, date, holidayOfSafe, basis, lookup.fromJp) ||
|
|
713
|
+
(basisNoDates !== basis &&
|
|
714
|
+
!inDateUnits(n) &&
|
|
715
|
+
matchPattern(rule, date, holidayOfSafe, basisNoDates, lookup.fromJp));
|
|
665
716
|
}
|
|
666
717
|
catch {
|
|
667
718
|
found = false;
|
|
@@ -781,6 +832,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
781
832
|
r.interval === null &&
|
|
782
833
|
r.months === null &&
|
|
783
834
|
!unused.has(r) &&
|
|
835
|
+
!sameValue(compiled.weekly[r.weekday], r.value) &&
|
|
784
836
|
periodsOverlap(rule, r));
|
|
785
837
|
for (const weekly of weeklies) {
|
|
786
838
|
c.info("counting-basis", rule.path, weekly.value === true
|
|
@@ -789,18 +841,25 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
789
841
|
"write regular closed weekdays as closedWeekdays if they should not be counted", weekly.path);
|
|
790
842
|
}
|
|
791
843
|
}
|
|
792
|
-
if (isCalendar && window && !dates.some((r) => r.value === true)) {
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
844
|
+
if (isCalendar && window && rulesWindow && !dates.some((r) => r.value === true)) {
|
|
845
|
+
const noDates = createResolver(without(compiled, null, true), lookup, throwLostShift);
|
|
846
|
+
const withDates = dateUnits.length > 0 ? createResolver(compiled, lookup, throwLostShift) : null;
|
|
847
|
+
const inRules = (n) => rulesWindow.ranges.some((r) => r.from <= n && n <= r.to);
|
|
848
|
+
const open = (resolve, n) => {
|
|
796
849
|
try {
|
|
797
|
-
|
|
850
|
+
return resolve(dateOfDayNumber(n)).day.value === true;
|
|
798
851
|
}
|
|
799
852
|
catch (error) {
|
|
800
853
|
if (!atEdge(n, error, window) && !isLostShift(error))
|
|
801
854
|
throw error;
|
|
802
|
-
|
|
855
|
+
return false;
|
|
803
856
|
}
|
|
857
|
+
};
|
|
858
|
+
let found = false;
|
|
859
|
+
eachDay(window, (n) => {
|
|
860
|
+
found =
|
|
861
|
+
(inRules(n) && open(noDates, n)) ||
|
|
862
|
+
(withDates !== null && inDateUnits(n) && open(withDates, n));
|
|
804
863
|
return found;
|
|
805
864
|
});
|
|
806
865
|
if (!found) {
|
|
@@ -847,8 +906,20 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
847
906
|
return values.get(n);
|
|
848
907
|
};
|
|
849
908
|
};
|
|
850
|
-
const redundant = (rule, base, days, original) => {
|
|
851
|
-
const
|
|
909
|
+
const redundant = (rule, base, days, original, split = false) => {
|
|
910
|
+
const make = (b, using) => split ? resolverIn(b, using) : createResolver(b, using, throwLostShift);
|
|
911
|
+
const resolve = make(without(base, rule, false), lookup);
|
|
912
|
+
const strictAfter = strictLookup ? make(without(base, rule, false), strictLookup) : null;
|
|
913
|
+
const strictBefore = strictLookup ? make(base, strictLookup) : null;
|
|
914
|
+
const throwsUnconfirmed = (r, n) => {
|
|
915
|
+
try {
|
|
916
|
+
r(dateOfDayNumber(n));
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
catch (error) {
|
|
920
|
+
return error.code === "unconfirmed-holiday";
|
|
921
|
+
}
|
|
922
|
+
};
|
|
852
923
|
for (const n of days) {
|
|
853
924
|
let value;
|
|
854
925
|
try {
|
|
@@ -864,6 +935,10 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
864
935
|
}
|
|
865
936
|
else if (!sameValue(before, value))
|
|
866
937
|
return false;
|
|
938
|
+
if (strictAfter &&
|
|
939
|
+
strictBefore &&
|
|
940
|
+
throwsUnconfirmed(strictBefore, n) !== throwsUnconfirmed(strictAfter, n))
|
|
941
|
+
return false;
|
|
867
942
|
}
|
|
868
943
|
return true;
|
|
869
944
|
};
|
|
@@ -920,7 +995,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
920
995
|
const decidedIn = (rule) => {
|
|
921
996
|
if (!decided && window) {
|
|
922
997
|
const map = new Map(candidates.map((r) => [r, new Set()]));
|
|
923
|
-
const resolveNow =
|
|
998
|
+
const resolveNow = resolverIn(current(counting.length > 0));
|
|
924
999
|
eachDay(window, (n) => {
|
|
925
1000
|
let by;
|
|
926
1001
|
try {
|
|
@@ -940,7 +1015,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
940
1015
|
const refresh = (affected) => {
|
|
941
1016
|
if (!decided)
|
|
942
1017
|
return;
|
|
943
|
-
const resolveNow =
|
|
1018
|
+
const resolveNow = resolverIn(current(counting.length > 0));
|
|
944
1019
|
for (const n of affected) {
|
|
945
1020
|
if (!inWindow(n) || unjudged.has(n))
|
|
946
1021
|
continue;
|
|
@@ -951,7 +1026,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
951
1026
|
decided.get(by)?.add(n);
|
|
952
1027
|
}
|
|
953
1028
|
};
|
|
954
|
-
const originalNow = originalOf(
|
|
1029
|
+
const originalNow = originalOf(resolverIn(current(counting.length > 0)));
|
|
955
1030
|
const unitsOf = new Map();
|
|
956
1031
|
const annualUnits = (rule) => {
|
|
957
1032
|
const known = unitsOf.get(rule);
|
|
@@ -976,8 +1051,8 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
976
1051
|
? annualUnits(rule)
|
|
977
1052
|
: days;
|
|
978
1053
|
const ok = checkedDays === days
|
|
979
|
-
? redundant(rule, base, days, () => rule.value)
|
|
980
|
-
: redundant(rule, base, checkedDays, originalNow);
|
|
1054
|
+
? redundant(rule, base, days, () => rule.value, true)
|
|
1055
|
+
: redundant(rule, base, checkedDays, originalNow, true);
|
|
981
1056
|
if (!ok)
|
|
982
1057
|
return false;
|
|
983
1058
|
affected = [...days, ...checkedDays];
|
|
@@ -1014,7 +1089,7 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
1014
1089
|
}
|
|
1015
1090
|
if (reported.size === 0)
|
|
1016
1091
|
return;
|
|
1017
|
-
const resolveFinal =
|
|
1092
|
+
const resolveFinal = resolverIn(current(true));
|
|
1018
1093
|
const relatedOf = (days) => {
|
|
1019
1094
|
const paths = new Set();
|
|
1020
1095
|
for (const n of days) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.8",
|
|
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",
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@types/node": "26.6.6",
|
|
95
|
-
"oxfmt": "0.
|
|
96
|
-
"oxlint": "1.
|
|
95
|
+
"oxfmt": "0.79.0",
|
|
96
|
+
"oxlint": "1.94.0",
|
|
97
97
|
"typescript": "6.0.3"
|
|
98
98
|
},
|
|
99
99
|
"engines": {
|