bizdays-toolkit 0.31.5 → 0.31.7
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 +35 -1
- package/README.md +1 -1
- package/dist/core/calendar.d.ts +1 -1
- package/dist/core/calendar.js +10 -11
- package/dist/core/diagnose.d.ts +4 -1
- package/dist/core/diagnose.js +58 -10
- package/dist/core/input.d.ts +2 -1
- package/dist/core/input.js +9 -3
- package/dist/core/month.js +3 -4
- package/dist/core/schedule.d.ts +1 -1
- package/dist/core/schedule.js +26 -10
- package/dist/core/types.d.ts +2 -0
- package/dist/provider/index.js +1 -1
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,38 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.31.7] - 2026-11-12
|
|
10
|
+
|
|
11
|
+
This version makes three kinds of options that were silently accepted throw, as the design decisions (6, 8) promise, gives a code to the remaining exceptions without one, and corrects documents. Options that were written correctly give the same results as before. Options that write both a single date and a range in one entry, write `null` in one of seven options, or have a hole in an array now throw; each item below says how to rewrite them.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- An entry of `closedDates`, `openDates` and `closedAnnualDates` (and of a schedule's `dates` and `annualDates`) with both a single date (`date`) and a range (`from`/`to`), such as `{ date: "12-31", from: "12-29", to: "01-03" }`, was accepted and used only `date` (the diagnostics reported `from` and `to` as unknown options). It now throws `invalid-option` ("cannot have both"), and the diagnostics return it as an `error`, as the design decisions (8) say for conflicting options. Keep the form you mean and remove the other; an explicit `undefined` is still the same as leaving the key out
|
|
16
|
+
- `null` in seven options was silently replaced with the default, while `null` in every other option threw: `holidayPolicy` and `searchDayLimit` of `createCalendar`, `searchDayLimit` of `combineCalendars` and `createCalendarFromSchedule`, `outOfRangePolicy`, `unconfirmedHolidayPolicy`, and `holidayOverlapPolicy` of a recurring rule. They now throw `invalid-option` like other values the types do not accept, and the diagnostics return it as an `error`; the minute of a Temporal-like date-time (`minute: null`) now throws `invalid-time` instead of reading as 0. The design decisions (6) now say that `null` is not the same as leaving an option out (only `undefined` is; a schedule's `value: null` is still a value). If you wrote `null`, remove the key or write `undefined`
|
|
17
|
+
- A hole in an array (`[a, , b]`) was skipped in the options (`closedDates`, `openDates`, `closedAnnualDates`, the rules, `closedWeekdays`, `months`, `nth`, `weekdays`, `skipWeekdays` and the like, and a list of holiday providers), so a date or a rule left out of the array was silently lost, and `combineCalendars` with a hole threw `time-zone-conflict` instead of `invalid-argument`. A hole is now checked like an explicit `undefined` element and throws the same code; the design decisions (6) now say so. A hole in a schedule's `weekdayValues` is still the value `undefined`. If you build arrays by index, fill every element
|
|
18
|
+
- `monthOf` read only a string with exactly three hyphen-separated parts as a date, so a date-time string with an offset (such as `"2026-11-05T10:00-05:00"`) or `"2026-1-1-1"` threw `invalid-month`, while `closingPeriod` threw `invalid-date` for the same string (0.31.6). `monthOf` now reads strings the same way (three or more parts are a date); the design decisions (8) now list it. Valid months and dates give the same results
|
|
19
|
+
- The minute of a Temporal-like date-time that cannot be turned into a string (such as an array with a symbol) threw a `TypeError` without a `code` while building the message. It now throws `invalid-time`
|
|
20
|
+
- `diagnoseSchedule` did not report unknown keys inside the object of `holidayPolicy` (such as `{ value: null, sameAS: 0 }`, a typo of `sameAs`), although the design decisions (8) say that typos are found as `unknown-option`. It now reports them; the results are unchanged. The design decisions (31) now say that adding such a check where it was missing is a fix, not a new kind of diagnostic
|
|
21
|
+
- Type descriptions: `Diagnostic.relatedPath` now also describes `redundant` (the rule that decides instead) and `counting-basis` (the weekday rule that the count leaves out). `toInstant` and `instantOf` now say that the offset from UTC is used to the minute (in a period whose offset is not a whole number of minutes, such as local mean time or Liberia until 1972, the result can be up to 59 seconds off). The first sentence of `createCalendarFromSchedule` now ends with a full stop
|
|
22
|
+
- Documentation: the guide says the same about `toInstant`, and the guide and the design decisions (31) now say that the 28 years scanned by the diagnostics cover every combination of weekday and date only when they do not cross a year such as 2100 (which holds within 1901–2099); a rule with an open-ended effective period starting after 2072 can be reported as `never-matches` when it matches only in a later leap year. Results are unchanged
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- The npm keywords now also include `public-holidays`, `timezone` and `typescript`
|
|
27
|
+
|
|
28
|
+
## [0.31.6] - 2026-11-12
|
|
29
|
+
|
|
30
|
+
This version fixes option diagnostics that returned an `error` for options that can be created, exceptions without a `code`, and the code for malformed strings in `closingPeriod`, and corrects documents. Results of calls that already succeeded do not change; some calls that threw an exception without a `code` now throw one with a `code`, and a calendar's `closingPeriod` now reports a malformed month string as `invalid-month`.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- `diagnoseCalendar` and `diagnoseSchedule` returned an `error` (`out-of-range`, at `holidayProvider` even without a provider) for options with an effective period that starts or ends near the edge of the years 1000–9999 and is open on the other side (such as `effectiveFrom: "9999-12-31"` or `effectiveTo: "1000-06-01"`), although `createCalendar` and `createSchedule` accept such options. The diagnostics widened the period by the rule's cycle beyond those years. `diagnoseSchedule` returned the same `error` for a schedule with a `businessDayOfWeek` rule and a holiday provider whose supported years reach 1000 or 9999, because the first and last weeks run past those years. The diagnostics now keep the scan within 1000–9999; a day at the edge whose rule looks at a day outside those years does not match, and in a schedule the days of such a week are treated as days whose rules cannot be judged; the design decisions (17) now say so. An `out-of-range` thrown by a provider elsewhere is still reported as before
|
|
35
|
+
- `diagnoseSchedule` returned an `error` (`invalid-provider-data`, "Maximum call stack size exceeded") for a schedule whose values contain a cycle (such as an object that refers to itself), although `createSchedule` accepts it. Values are now compared with cycles taken into account (two cyclic values of the same shape are the same); values nested too deeply to compare are treated as different, so the diagnostics never report them as `redundant`
|
|
36
|
+
- A holiday provider that returned an array with holes, and `withSubstituteDays` given such an array, threw a `TypeError` without a `code` ("Cannot read properties of undefined"). A hole is now checked like an item that is not an object: evaluations throw `invalid-provider-data`, the diagnostics return it as an `error`, and `withSubstituteDays` throws `invalid-argument`, each as a `RangeError` (it was a `TypeError`); use `isBizdaysError` and `code` rather than `instanceof TypeError`
|
|
37
|
+
- An instant written as `{ epochMilliseconds }` beyond the range of `Date` (more than 8.64e15 milliseconds from 1970, such as `1e20`) threw `RangeError: Invalid time value` without a `code`; it now throws `out-of-range`. A Temporal-like date whose `calendarId` is not a string (such as a symbol) threw a `TypeError` without a `code`; it now throws `invalid-input` like other calendars (the message shows the value as other messages do)
|
|
38
|
+
- A calendar's `closingPeriod` read only `"YYYY-MM"` as a month and any other string as a date, so a malformed month (such as `"2026-1"`) threw `invalid-date`, while the function `closingPeriod` threw `invalid-month`. Both now read a string with three or more parts separated by hyphens as a date (or date-time) and any other string as a month, so `"2026-1"`, `"202611"` and `"2026/11"` throw `invalid-month` in both; the rule is now written in the design decisions (8). The function `closingPeriod` now throws `invalid-date` instead of `invalid-month` for a date-time string with an offset (such as `"2026-11-05T10:00-05:00"`), which it does not accept. Valid months, dates and date-times give the same results as before. If you branch on `invalid-date` for a malformed month passed to the method, branch on `invalid-month`
|
|
39
|
+
- Documentation: the provider guide, the description of `HolidayProvider` and the design decisions (24) now say that, within a run of holidays longer than 31 days, `"after-holiday"` rules are not moved and rules for the day before or after a holiday do not match (write a long closure with `closedDates` or `closedAnnualDates`); the guide already said that 31 days is the furthest a move reaches. The README now gives the bundle sizes measured for 0.31.6 (they were measured for 0.31.1). The guide and the design decisions (1) now say that evaluating a day inside the years 1000–9999 throws `out-of-range` when the evaluation needs a day outside them (the neighbouring day of a rule for the day before or after a holiday, the days an `"after-holiday"` rule looks back on, the week of `businessDayOfWeek`, the start of a closing period), with or without a holiday provider and with `outOfRangePolicy: "ignore"` too, because those days do not exist as dates; the guide described only searches that leave those years. Results are unchanged
|
|
40
|
+
|
|
9
41
|
## [0.31.5] - 2026-11-11
|
|
10
42
|
|
|
11
43
|
This version fixes results and errors that did not keep the guide, the type descriptions and the design decisions, and corrects documents. Schedules with `value: undefined` in a specific date, an annual date or a recurring rule now return `undefined` on those days, a wrong weekday number in three places now throws `invalid-weekday` instead of `invalid-option`, a schedule with both `sameAs` and `value` in `holidayPolicy` now throws, and calls that took an instant in the years BC or a year outside 1000–9999 now throw `out-of-range`. Other results do not change.
|
|
@@ -916,7 +948,9 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
|
|
|
916
948
|
|
|
917
949
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
918
950
|
|
|
919
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.
|
|
951
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.7...HEAD
|
|
952
|
+
[0.31.7]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.6...v0.31.7
|
|
953
|
+
[0.31.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.5...v0.31.6
|
|
920
954
|
[0.31.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.4...v0.31.5
|
|
921
955
|
[0.31.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.3...v0.31.4
|
|
922
956
|
[0.31.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.2...v0.31.3
|
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 14.0 KB min+gzip (about 15.8 KB with Japanese holidays, about 16.2 KB with UK bank holidays, about 14.9 KB with French holidays, about 15.0 KB with Singapore holidays; measured for 0.31.6). 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/calendar.d.ts
CHANGED
|
@@ -321,7 +321,7 @@ export interface CalendarFromScheduleOptions {
|
|
|
321
321
|
readonly maxSearchDays?: number;
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
|
-
* スケジュール(createSchedule)から営業日カレンダーを作る。isOpen が true
|
|
324
|
+
* スケジュール(createSchedule)から営業日カレンダーを作る。isOpen が true を返す値の日を営業日とする。
|
|
325
325
|
* isOpen は boolean を返す関数にする(boolean でない値を返すと code: "invalid-argument" の RangeError。作成時に曜日の値と
|
|
326
326
|
* holidayPolicy: { value } の値で呼んで確かめ、ほかの値の日は判定したときに確かめる)。
|
|
327
327
|
* 営業時間表のような日ごとの値が設定の正本で、営業日の計算(加減算・調整・期日など)も同じ設定から行いたいときに使う
|
package/dist/core/calendar.js
CHANGED
|
@@ -3,7 +3,7 @@ import { checkUnknownKeys, internalError, IssueCollector, describeValue, rangeEr
|
|
|
3
3
|
import { isOptionsObject } from "./options.js";
|
|
4
4
|
import { renameKeys, writtenKey } from "./renamed.js";
|
|
5
5
|
import { parseTimeOfDaySeconds, toCivil } from "./input.js";
|
|
6
|
-
import { checkClosingDay, closingDayIn, closingMonth as calendarClosingMonth, dayOfMonth, formatMonth, isDayOfMonthValue, parseMonth, shiftMonth, } from "./month.js";
|
|
6
|
+
import { checkClosingDay, closingDayIn, closingMonth as calendarClosingMonth, dayOfMonth, formatMonth, isDayOfMonthValue, parseMonth, readsAsDate, shiftMonth, } from "./month.js";
|
|
7
7
|
import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, infoOfSchedule, valuesOfSchedule, isWeekday, mapDays, RECURRING_RULE_KEYS, jpUsage, } from "./schedule.js";
|
|
8
8
|
export const CALENDAR_OPTION_KEYS = [
|
|
9
9
|
"holidayProvider",
|
|
@@ -37,7 +37,7 @@ export function compileCalendarOptions(c, options) {
|
|
|
37
37
|
c.error("invalid-option", "closedWeekdays", "must be an array");
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
rawWeekdays.forEach((w, i) => {
|
|
40
|
+
Array.from(rawWeekdays).forEach((w, i) => {
|
|
41
41
|
if (isWeekday(w))
|
|
42
42
|
closedWeekdays.add(w);
|
|
43
43
|
else
|
|
@@ -45,11 +45,11 @@ export function compileCalendarOptions(c, options) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
const holidayPolicy = o["holidayPolicy"]
|
|
48
|
+
const holidayPolicy = o["holidayPolicy"] === undefined ? "closed" : o["holidayPolicy"];
|
|
49
49
|
if (holidayPolicy !== "closed" && holidayPolicy !== "open" && holidayPolicy !== "ignore") {
|
|
50
50
|
c.error("invalid-option", "holidayPolicy", 'must be "closed", "open" or "ignore"');
|
|
51
51
|
}
|
|
52
|
-
const searchDayLimit = o["searchDayLimit"]
|
|
52
|
+
const searchDayLimit = o["searchDayLimit"] === undefined ? 3660 : o["searchDayLimit"];
|
|
53
53
|
if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
|
|
54
54
|
c.error("invalid-option", "searchDayLimit", "must be a positive integer");
|
|
55
55
|
}
|
|
@@ -303,10 +303,9 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
303
303
|
closingPeriod(input, closingDayOfMonth, rawOptions) {
|
|
304
304
|
checkClosingDay(closingDayOfMonth);
|
|
305
305
|
const options = adjustOptions(rawOptions, "closingPeriod options");
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
: closingMonthOf(dateOf(input), closingDayOfMonth, options);
|
|
306
|
+
const month = typeof input !== "string" || readsAsDate(input)
|
|
307
|
+
? closingMonthOf(dateOf(input), closingDayOfMonth, options)
|
|
308
|
+
: parseMonth(input);
|
|
310
309
|
const to = closingDate(month, closingDayOfMonth, options);
|
|
311
310
|
const from = addDays(closingDate(shiftMonth(month, -1), closingDayOfMonth, options), 1);
|
|
312
311
|
if (from > to) {
|
|
@@ -346,7 +345,7 @@ export function combineCalendars(calendars, options) {
|
|
|
346
345
|
if (!Array.isArray(calendars) || calendars.length < 2) {
|
|
347
346
|
throw rangeError("invalid-argument", "calendars must be an array of two or more calendars");
|
|
348
347
|
}
|
|
349
|
-
calendars.forEach((c, i) => {
|
|
348
|
+
Array.from(calendars).forEach((c, i) => {
|
|
350
349
|
if (!isCalendarLike(c))
|
|
351
350
|
throw rangeError("invalid-argument", `calendars[${i}] is not a calendar`);
|
|
352
351
|
if (calendars.indexOf(c) !== i) {
|
|
@@ -358,7 +357,7 @@ export function combineCalendars(calendars, options) {
|
|
|
358
357
|
if (mode !== "all" && mode !== "any") {
|
|
359
358
|
throw rangeError("invalid-option", 'open must be "all" or "any"');
|
|
360
359
|
}
|
|
361
|
-
const searchDayLimit = (o["searchDayLimit"]
|
|
360
|
+
const searchDayLimit = (o["searchDayLimit"] === undefined ? 3660 : o["searchDayLimit"]);
|
|
362
361
|
if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
|
|
363
362
|
throw rangeError("invalid-option", "searchDayLimit must be a positive integer");
|
|
364
363
|
}
|
|
@@ -436,7 +435,7 @@ export function createCalendarFromSchedule(schedule, isOpen, options) {
|
|
|
436
435
|
throw rangeError("invalid-argument", "isOpen must be a function (value) => boolean");
|
|
437
436
|
}
|
|
438
437
|
const o = optionsObject(options, "createCalendarFromSchedule options", (v) => renameKeys("throw", ["fromSchedule"], "", v), false, "invalid-option");
|
|
439
|
-
const searchDayLimit = (o["searchDayLimit"]
|
|
438
|
+
const searchDayLimit = (o["searchDayLimit"] === undefined ? 3660 : o["searchDayLimit"]);
|
|
440
439
|
if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
|
|
441
440
|
throw rangeError("invalid-option", "searchDayLimit must be a positive integer");
|
|
442
441
|
}
|
package/dist/core/diagnose.d.ts
CHANGED
|
@@ -64,7 +64,10 @@ export interface Diagnostic {
|
|
|
64
64
|
/** 設定の中の位置(例: "closedRecurringRules[1]"・"closedDates[0].date")。設定全体なら "" */
|
|
65
65
|
readonly path: string;
|
|
66
66
|
readonly message: string;
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* 関係する別の位置。shadowed では覆っている先の規則、redundant では取り除いたときに代わりに決める規則(1 つに定まる
|
|
69
|
+
* ときだけ)、counting-basis では数え方に入らない曜日の規則、out-of-range では祝日の提供元
|
|
70
|
+
*/
|
|
68
71
|
readonly relatedPath?: string;
|
|
69
72
|
}
|
|
70
73
|
/**
|
package/dist/core/diagnose.js
CHANGED
|
@@ -47,8 +47,12 @@ function closestOf(key, known) {
|
|
|
47
47
|
}
|
|
48
48
|
const PATTERN_FROM = toDayNumber("2001-01-01");
|
|
49
49
|
const PATTERN_DAYS = toDayNumber("2028-12-31") - PATTERN_FROM + 1;
|
|
50
|
+
const MIN_DAY = toDayNumber("1000-01-01");
|
|
51
|
+
const MAX_DAY = toDayNumber("9999-12-31");
|
|
50
52
|
const MAX_WINDOW_YEARS = 200;
|
|
51
53
|
const MAX_DATE_RULE_DAYS = 366 * MAX_WINDOW_YEARS;
|
|
54
|
+
const atCalendarEdge = (n, error) => (n < MIN_DAY + MAX_HOLIDAY_RUN || n > MAX_DAY - MAX_HOLIDAY_RUN) &&
|
|
55
|
+
error?.code === "out-of-range";
|
|
52
56
|
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
|
|
53
57
|
const lcm = (a, b) => (a / gcd(a, b)) * b;
|
|
54
58
|
function patternCycle(rules) {
|
|
@@ -100,7 +104,7 @@ function scanWindow(source, rules, cycle) {
|
|
|
100
104
|
continue;
|
|
101
105
|
const from = rule.effectiveFrom ?? rule.effectiveTo - cycle + 1;
|
|
102
106
|
const to = Math.min(rule.effectiveTo ?? from + cycle - 1, from + 366 * MAX_WINDOW_YEARS - 1);
|
|
103
|
-
ranges.push({ from, to });
|
|
107
|
+
ranges.push({ from: Math.max(from, MIN_DAY), to: Math.min(to, MAX_DAY) });
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
ranges.sort((a, b) => a.from - b.from);
|
|
@@ -136,8 +140,9 @@ function patternBits(rule) {
|
|
|
136
140
|
return bits;
|
|
137
141
|
}
|
|
138
142
|
function matchesAnyDay(rule, cycle) {
|
|
139
|
-
const
|
|
140
|
-
const
|
|
143
|
+
const start = rule.effectiveFrom ?? (rule.effectiveTo === null ? PATTERN_FROM : rule.effectiveTo - cycle + 1);
|
|
144
|
+
const from = Math.max(start, MIN_DAY);
|
|
145
|
+
const to = Math.min(rule.effectiveTo ?? Infinity, start + cycle - 1, MAX_DAY);
|
|
141
146
|
for (let n = from; n <= to; n++)
|
|
142
147
|
if (matchPattern(rule, fromDayNumber(n)))
|
|
143
148
|
return true;
|
|
@@ -194,15 +199,32 @@ function canCover(earlier, later) {
|
|
|
194
199
|
}
|
|
195
200
|
}
|
|
196
201
|
function sameValue(a, b) {
|
|
202
|
+
try {
|
|
203
|
+
return sameValueIn(a, b, new Map());
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (error instanceof RangeError)
|
|
207
|
+
return false;
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function sameValueIn(a, b, seen) {
|
|
197
212
|
if (Object.is(a, b))
|
|
198
213
|
return true;
|
|
199
214
|
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)
|
|
200
215
|
return false;
|
|
216
|
+
const pairs = seen.get(a);
|
|
217
|
+
if (pairs?.has(b))
|
|
218
|
+
return true;
|
|
219
|
+
if (pairs)
|
|
220
|
+
pairs.add(b);
|
|
221
|
+
else
|
|
222
|
+
seen.set(a, new Set([b]));
|
|
201
223
|
if (Array.isArray(a) || Array.isArray(b)) {
|
|
202
224
|
return (Array.isArray(a) &&
|
|
203
225
|
Array.isArray(b) &&
|
|
204
226
|
a.length === b.length &&
|
|
205
|
-
a.every((v, i) =>
|
|
227
|
+
a.every((v, i) => sameValueIn(v, b[i], seen)));
|
|
206
228
|
}
|
|
207
229
|
const plain = (o) => {
|
|
208
230
|
const proto = Object.getPrototypeOf(o);
|
|
@@ -214,7 +236,7 @@ function sameValue(a, b) {
|
|
|
214
236
|
const kb = Object.keys(b);
|
|
215
237
|
return (ka.length === kb.length &&
|
|
216
238
|
ka.every((k) => Object.hasOwn(b, k) &&
|
|
217
|
-
|
|
239
|
+
sameValueIn(a[k], b[k], seen)));
|
|
218
240
|
}
|
|
219
241
|
const yearOf = (dayNumber) => parseDate(fromDayNumber(dayNumber)).year;
|
|
220
242
|
function without(compiled, rule, dropDates) {
|
|
@@ -319,10 +341,16 @@ export function unjudgeableDays(compiled, window) {
|
|
|
319
341
|
}
|
|
320
342
|
const start = from - ((weekdayOf(fromDayNumber(from)) - r.weekStart + 7) % 7);
|
|
321
343
|
for (let w = start; w <= to; w += 7) {
|
|
322
|
-
const
|
|
344
|
+
const all = [0, 1, 2, 3, 4, 5, 6].map((i) => w + i);
|
|
345
|
+
const week = all.filter((n) => n >= MIN_DAY && n <= MAX_DAY);
|
|
323
346
|
const weekMonths = [...new Set(week.map(monthOf))];
|
|
324
347
|
if (!weekMonths.some(inMonths))
|
|
325
348
|
continue;
|
|
349
|
+
if (week.length < 7) {
|
|
350
|
+
for (const n of week)
|
|
351
|
+
days.add(n);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
326
354
|
if (weekMonths.map(throws).some(Boolean))
|
|
327
355
|
for (const n of week)
|
|
328
356
|
days.add(n);
|
|
@@ -459,9 +487,19 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
459
487
|
if (source.providers.length === 0 || !window)
|
|
460
488
|
return false;
|
|
461
489
|
let found = false;
|
|
462
|
-
eachDay(window, (n) =>
|
|
463
|
-
inPeriod(rule, n)
|
|
464
|
-
|
|
490
|
+
eachDay(window, (n) => {
|
|
491
|
+
if (!inPeriod(rule, n))
|
|
492
|
+
return false;
|
|
493
|
+
try {
|
|
494
|
+
found = matchPattern(rule, fromDayNumber(n), holidayOfSafe, undefined, lookup.fromJp);
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
if (!atCalendarEdge(n, error))
|
|
498
|
+
throw error;
|
|
499
|
+
found = false;
|
|
500
|
+
}
|
|
501
|
+
return found;
|
|
502
|
+
});
|
|
465
503
|
return found;
|
|
466
504
|
};
|
|
467
505
|
const businessDayRuleMatches = (rule) => {
|
|
@@ -604,7 +642,17 @@ function analyzeRules(c, compiled, isCalendar, unsure = () => false) {
|
|
|
604
642
|
if (isCalendar && window && !dates.some((r) => r.value === true)) {
|
|
605
643
|
const resolve = createResolver(without(compiled, null, true), lookup);
|
|
606
644
|
let found = false;
|
|
607
|
-
eachDay(window, (n) =>
|
|
645
|
+
eachDay(window, (n) => {
|
|
646
|
+
try {
|
|
647
|
+
found = resolve(fromDayNumber(n)).day.value === true;
|
|
648
|
+
}
|
|
649
|
+
catch (error) {
|
|
650
|
+
if (!atCalendarEdge(n, error))
|
|
651
|
+
throw error;
|
|
652
|
+
found = false;
|
|
653
|
+
}
|
|
654
|
+
return found;
|
|
655
|
+
});
|
|
608
656
|
if (!found) {
|
|
609
657
|
c.warning("no-business-day", "", `No day is a business day with these options (checked ${window.label}); ` +
|
|
610
658
|
"searching for a business day throws");
|
package/dist/core/input.d.ts
CHANGED
|
@@ -81,7 +81,8 @@ export declare function toDateTimeParts(input: DateInput, timeZone: string): Civ
|
|
|
81
81
|
/**
|
|
82
82
|
* 暦日と時刻("HH:mm" または "HH:mm:ss")から、タイムゾーンでのその瞬間を Date で返す(civilOf・toDateTimeParts の逆向き)。
|
|
83
83
|
* 夏時間の切り替えで存在しない時刻は、飛んだ分だけ後ろの瞬間(英国の 3 月の 01:30 は 02:30 BST)、2 回ある時刻は先のほう
|
|
84
|
-
* (Temporal の disambiguation: "compatible"
|
|
84
|
+
* (Temporal の disambiguation: "compatible" と同じ)。時差は分の精度で扱う(時差が分の倍数でない時期、たとえば標準時の
|
|
85
|
+
* 制定より前の地方平均時やリベリアの 1972 年までは、結果が最大 59 秒ずれ、秒を付けた時刻は civilOf で同じ分に戻らないことがある)。
|
|
85
86
|
* @public
|
|
86
87
|
*/
|
|
87
88
|
export declare function toInstant(date: DateString, time: string, timeZone: string): Date;
|
package/dist/core/input.js
CHANGED
|
@@ -48,6 +48,9 @@ function wallParts(epochMilliseconds, timeZone) {
|
|
|
48
48
|
export function instantToCivil(epochMilliseconds, timeZone) {
|
|
49
49
|
if (!Number.isFinite(epochMilliseconds))
|
|
50
50
|
throw rangeError("invalid-time", "Invalid instant");
|
|
51
|
+
if (Math.abs(epochMilliseconds) > 8.64e15) {
|
|
52
|
+
throw rangeError("out-of-range", "Instant out of range (1000-9999)");
|
|
53
|
+
}
|
|
51
54
|
if (new Date(epochMilliseconds).getUTCFullYear() < 999) {
|
|
52
55
|
throw rangeError("out-of-range", "Instant out of range (1000-9999)");
|
|
53
56
|
}
|
|
@@ -61,7 +64,7 @@ function wallTime(hour, minute) {
|
|
|
61
64
|
!Number.isInteger(minute) ||
|
|
62
65
|
minute < 0 ||
|
|
63
66
|
minute > 59) {
|
|
64
|
-
const two = (v) => String(v).padStart(2, "0");
|
|
67
|
+
const two = (v) => typeof v === "number" ? String(v).padStart(2, "0") : describeValue(v);
|
|
65
68
|
throw rangeError("invalid-time", `Invalid time: ${two(hour)}:${two(minute)}`);
|
|
66
69
|
}
|
|
67
70
|
return hour * 60 + minute;
|
|
@@ -111,14 +114,17 @@ export function toCivil(input, timeZone) {
|
|
|
111
114
|
return instantToCivil(input.epochMilliseconds, timeZone);
|
|
112
115
|
if (isDateLike(input)) {
|
|
113
116
|
if (input.calendarId !== undefined && input.calendarId !== "iso8601") {
|
|
114
|
-
throw typeError("invalid-input", `Unsupported calendar: ${input.calendarId} (only iso8601)`);
|
|
117
|
+
throw typeError("invalid-input", `Unsupported calendar: ${describeValue(input.calendarId)} (only iso8601)`);
|
|
115
118
|
}
|
|
116
119
|
if (!Number.isInteger(input.year) || input.year < 1000 || input.year > 9999) {
|
|
117
120
|
throw rangeError("invalid-date", `Invalid date: year must be an integer from 1000 to 9999: ${describeValue(input.year)}`);
|
|
118
121
|
}
|
|
119
122
|
const date = formatDate(input.year, input.month, input.day);
|
|
120
123
|
if (typeof input.hour === "number") {
|
|
121
|
-
return {
|
|
124
|
+
return {
|
|
125
|
+
date,
|
|
126
|
+
minutes: wallTime(input.hour, input.minute === undefined ? 0 : input.minute),
|
|
127
|
+
};
|
|
122
128
|
}
|
|
123
129
|
return { date, minutes: null };
|
|
124
130
|
}
|
package/dist/core/month.js
CHANGED
|
@@ -29,9 +29,7 @@ export function monthOf(input, offset = 0) {
|
|
|
29
29
|
if (!Number.isInteger(offset)) {
|
|
30
30
|
throw rangeError("invalid-argument", `offset must be an integer: ${describeValue(offset)}`);
|
|
31
31
|
}
|
|
32
|
-
const base = typeof input === "string" && input
|
|
33
|
-
? parseDate(input)
|
|
34
|
-
: parseMonth(input);
|
|
32
|
+
const base = typeof input === "string" && readsAsDate(input) ? parseDate(input) : parseMonth(input);
|
|
35
33
|
return formatMonth(shiftMonth(base, offset));
|
|
36
34
|
}
|
|
37
35
|
export function closingMonth(date, closingDayOfMonth) {
|
|
@@ -48,9 +46,10 @@ export function closingDayIn({ year, month }, closingDayOfMonth) {
|
|
|
48
46
|
const last = lengthOfMonth(year, month);
|
|
49
47
|
return closingDayOfMonth === -1 || closingDayOfMonth > last ? last : closingDayOfMonth;
|
|
50
48
|
}
|
|
49
|
+
export const readsAsDate = (input) => input.split("-").length >= 3;
|
|
51
50
|
export function closingPeriod(input, closingDayOfMonth) {
|
|
52
51
|
checkClosingDay(closingDayOfMonth);
|
|
53
|
-
const month = typeof input === "string" && input
|
|
52
|
+
const month = typeof input === "string" && readsAsDate(input)
|
|
54
53
|
? parseMonth(closingMonth(input, closingDayOfMonth))
|
|
55
54
|
: parseMonth(input);
|
|
56
55
|
const previous = shiftMonth(month, -1);
|
package/dist/core/schedule.d.ts
CHANGED
|
@@ -551,7 +551,7 @@ export interface HolidayLookup<Kind extends string = string> {
|
|
|
551
551
|
civilOf(input: DateInput): CivilDateTimeParts;
|
|
552
552
|
/**
|
|
553
553
|
* 暦日 "YYYY-MM-DD" と時刻("HH:mm" または "HH:mm:ss")から、タイムゾーンでのその瞬間を Date で返す(civilOf の逆向き)。
|
|
554
|
-
* 夏時間で存在しない時刻は飛んだ分だけ後ろに、2
|
|
554
|
+
* 夏時間で存在しない時刻は飛んだ分だけ後ろに、2 回ある時刻は先のほう。時差は分の精度で扱う(toInstant と同じ)
|
|
555
555
|
*/
|
|
556
556
|
instantOf(date: DateString, time: string): Date;
|
|
557
557
|
/** 今日の日付(タイムゾーン) */
|
package/dist/core/schedule.js
CHANGED
|
@@ -73,7 +73,7 @@ export function compileDateRules(c, path, entries, valueOf, allowString, valueKe
|
|
|
73
73
|
return [];
|
|
74
74
|
}
|
|
75
75
|
const rules = [];
|
|
76
|
-
entries.forEach((raw, i) => {
|
|
76
|
+
Array.from(entries).forEach((raw, i) => {
|
|
77
77
|
const p = `${path}[${i}]`;
|
|
78
78
|
const entry = allowString && typeof raw === "string" ? { date: raw } : raw;
|
|
79
79
|
if (!isObject(entry)) {
|
|
@@ -83,6 +83,10 @@ export function compileDateRules(c, path, entries, valueOf, allowString, valueKe
|
|
|
83
83
|
const got = valueOf(entry, p);
|
|
84
84
|
const name = checkName(c, p, entry["name"]);
|
|
85
85
|
const defined = withoutUndefined(entry, DATE_SHAPE_KEYS);
|
|
86
|
+
if ("date" in defined && ("from" in defined || "to" in defined)) {
|
|
87
|
+
c.error("invalid-option", p, 'cannot have both "date" and "from"/"to"');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
86
90
|
if ("date" in defined) {
|
|
87
91
|
checkUnknownKeys(c, p, defined, ["date", "name", ...(valueKey ? ["value"] : [])]);
|
|
88
92
|
const n = checkDate(c, `${p}.date`, entry["date"]);
|
|
@@ -116,7 +120,7 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString, value
|
|
|
116
120
|
return [];
|
|
117
121
|
}
|
|
118
122
|
const rules = [];
|
|
119
|
-
entries.forEach((raw, i) => {
|
|
123
|
+
Array.from(entries).forEach((raw, i) => {
|
|
120
124
|
const p = `${path}[${i}]`;
|
|
121
125
|
const entry = allowString && typeof raw === "string" ? { date: raw } : raw;
|
|
122
126
|
if (!isObject(entry)) {
|
|
@@ -127,6 +131,10 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString, value
|
|
|
127
131
|
const name = checkName(c, p, entry["name"]);
|
|
128
132
|
const period = checkPeriod(c, p, entry);
|
|
129
133
|
const defined = withoutUndefined(entry, DATE_SHAPE_KEYS);
|
|
134
|
+
if ("date" in defined && ("from" in defined || "to" in defined)) {
|
|
135
|
+
c.error("invalid-option", p, 'cannot have both "date" and "from"/"to"');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
130
138
|
if ("date" in defined) {
|
|
131
139
|
checkUnknownKeys(c, p, defined, [
|
|
132
140
|
"date",
|
|
@@ -191,7 +199,7 @@ const isDayOfMonth = (v) => v === -1 || (Number.isInteger(v) && v >= 1 && v <= 3
|
|
|
191
199
|
const isMonth = (v) => Number.isInteger(v) && v >= 1 && v <= 12;
|
|
192
200
|
function checkSet(c, path, raw, valid, expected, elementCode = "invalid-option") {
|
|
193
201
|
const list = Array.isArray(raw) ? raw : [raw];
|
|
194
|
-
if (list.length === 0 || !list.every(valid)) {
|
|
202
|
+
if (list.length === 0 || !Array.from(list).every(valid)) {
|
|
195
203
|
c.error(list.length === 0 ? "invalid-option" : elementCode, path, `must be ${expected}, or a non-empty array of them`);
|
|
196
204
|
return undefined;
|
|
197
205
|
}
|
|
@@ -205,7 +213,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
|
|
|
205
213
|
return [];
|
|
206
214
|
}
|
|
207
215
|
const rules = [];
|
|
208
|
-
entries.forEach((rawEntry, i) => {
|
|
216
|
+
Array.from(entries).forEach((rawEntry, i) => {
|
|
209
217
|
const p = `${path}[${i}]`;
|
|
210
218
|
if (!isObject(rawEntry)) {
|
|
211
219
|
c.error("invalid-option", p, "must be an object");
|
|
@@ -333,7 +341,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
|
|
|
333
341
|
}
|
|
334
342
|
else if (cycle !== null) {
|
|
335
343
|
const n = cycle;
|
|
336
|
-
if (!raw.every((v) => Number.isInteger(v) && v >= 1 && v <= n)) {
|
|
344
|
+
if (!Array.from(raw).every((v) => Number.isInteger(v) && v >= 1 && v <= n)) {
|
|
337
345
|
c.error("invalid-option", `${p}.positions`, `must be integers from 1 to ${n} (the cycle)`);
|
|
338
346
|
ok = false;
|
|
339
347
|
}
|
|
@@ -494,7 +502,11 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
|
|
|
494
502
|
ok = false;
|
|
495
503
|
}
|
|
496
504
|
}
|
|
497
|
-
const onHoliday = entry["holidayOverlapPolicy"]
|
|
505
|
+
const onHoliday = entry["holidayOverlapPolicy"] === undefined
|
|
506
|
+
? hasHoliday
|
|
507
|
+
? "over-holiday"
|
|
508
|
+
: "under-holiday"
|
|
509
|
+
: entry["holidayOverlapPolicy"];
|
|
498
510
|
if (!ON_HOLIDAY_RULES.includes(onHoliday)) {
|
|
499
511
|
c.error("invalid-option", `${p}.holidayOverlapPolicy`, `must be one of ${ON_HOLIDAY_RULES.map((v) => `"${v}"`).join(", ")}`);
|
|
500
512
|
ok = false;
|
|
@@ -712,7 +724,7 @@ export function compileHolidaySource(c, options) {
|
|
|
712
724
|
const list = raw === undefined ? [] : Array.isArray(raw) ? raw : [raw];
|
|
713
725
|
const providers = [];
|
|
714
726
|
const providerIndexes = [];
|
|
715
|
-
list.forEach((p, i) => {
|
|
727
|
+
Array.from(list).forEach((p, i) => {
|
|
716
728
|
const path = Array.isArray(raw) ? `holidayProvider[${i}]` : "holidayProvider";
|
|
717
729
|
if (validateProvider(c, path, p) && !providers.includes(p)) {
|
|
718
730
|
providers.push(p);
|
|
@@ -735,11 +747,13 @@ export function compileHolidaySource(c, options) {
|
|
|
735
747
|
}
|
|
736
748
|
timeZone = zones[0] ?? "UTC";
|
|
737
749
|
}
|
|
738
|
-
const outOfRangePolicy = options["outOfRangePolicy"]
|
|
750
|
+
const outOfRangePolicy = options["outOfRangePolicy"] === undefined ? "throw" : options["outOfRangePolicy"];
|
|
739
751
|
if (outOfRangePolicy !== "throw" && outOfRangePolicy !== "ignore") {
|
|
740
752
|
c.error("invalid-option", "outOfRangePolicy", 'must be "throw" or "ignore"');
|
|
741
753
|
}
|
|
742
|
-
const unconfirmed = options["unconfirmedHolidayPolicy"]
|
|
754
|
+
const unconfirmed = options["unconfirmedHolidayPolicy"] === undefined
|
|
755
|
+
? "accept"
|
|
756
|
+
: options["unconfirmedHolidayPolicy"];
|
|
743
757
|
if (unconfirmed !== "accept" && unconfirmed !== "throw") {
|
|
744
758
|
c.error("invalid-option", "unconfirmedHolidayPolicy", 'must be "accept" or "throw"');
|
|
745
759
|
}
|
|
@@ -759,7 +773,7 @@ function loadProviderYear(provider, year) {
|
|
|
759
773
|
if (!Array.isArray(list))
|
|
760
774
|
throw providerDataError(provider, year, "holidaysInYear must return an array");
|
|
761
775
|
const seen = new Set();
|
|
762
|
-
return
|
|
776
|
+
return Array.from(list, (h, i) => {
|
|
763
777
|
if (!isObject(h))
|
|
764
778
|
throw providerDataError(provider, year, `item ${i} is not an object`);
|
|
765
779
|
const { date, name, nameEn, kind, confirmed } = h;
|
|
@@ -947,6 +961,8 @@ export function compileScheduleOptions(c, options) {
|
|
|
947
961
|
}
|
|
948
962
|
let holiday = "ignore";
|
|
949
963
|
const holidayRaw = renameValue(c, "schedule", "holidayPolicy", writtenKey(["source", "schedule"], written, "holidayPolicy"), o["holidayPolicy"]);
|
|
964
|
+
if (isObject(holidayRaw))
|
|
965
|
+
checkUnknownKeys(c, "holidayPolicy", holidayRaw, ["sameAs", "value"]);
|
|
950
966
|
const hasSameAs = isObject(holidayRaw) && holidayRaw["sameAs"] !== undefined;
|
|
951
967
|
const hasValue = isObject(holidayRaw) && "value" in holidayRaw;
|
|
952
968
|
if (holidayRaw === undefined || holidayRaw === "ignore") {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface Holiday<Kind extends string = string> {
|
|
|
38
38
|
* holidaysInYear が返すデータは、年ごとに初めて使うときに検証され、誤りがあれば
|
|
39
39
|
* code: "invalid-provider-data" の例外になる。返した祝日は、契約の項目(date・name・nameEn・names・
|
|
40
40
|
* kind・confirmed・key)だけを持つ変更できないオブジェクトに複製される。
|
|
41
|
+
* 31 日を超えて続く祝日の期間では、"after-holiday" の振替と祝日の前後の規則は当てはまらない(前後を調べるのは 31 日まで。
|
|
42
|
+
* 長い休業は closedDates・closedAnnualDates で書く。decisions.md の 24 番)。
|
|
41
43
|
*
|
|
42
44
|
* 項目を足すときのバージョンは RELEASING.md の区分の表による。1.0.0 以降、マイナーバージョンで足す項目は省略可能なものに限る
|
|
43
45
|
* (必須にすると、自作の提供元が型エラーになるため)。
|
package/dist/provider/index.js
CHANGED
|
@@ -54,7 +54,7 @@ function checkHolidays(holidays) {
|
|
|
54
54
|
}
|
|
55
55
|
let year;
|
|
56
56
|
const seen = new Set();
|
|
57
|
-
holidays.forEach((h, i) => {
|
|
57
|
+
Array.from(holidays).forEach((h, i) => {
|
|
58
58
|
if (typeof h !== "object" || h === null) {
|
|
59
59
|
throw rangeError("invalid-argument", `holidays[${i}] is not an object`);
|
|
60
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.7",
|
|
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",
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
"holiday",
|
|
13
13
|
"holidays",
|
|
14
14
|
"japan",
|
|
15
|
+
"public-holidays",
|
|
15
16
|
"singapore",
|
|
17
|
+
"timezone",
|
|
18
|
+
"typescript",
|
|
16
19
|
"uk",
|
|
17
20
|
"workday",
|
|
18
21
|
"営業日",
|
|
@@ -89,8 +92,8 @@
|
|
|
89
92
|
},
|
|
90
93
|
"devDependencies": {
|
|
91
94
|
"@types/node": "26.6.6",
|
|
92
|
-
"oxfmt": "0.
|
|
93
|
-
"oxlint": "1.
|
|
95
|
+
"oxfmt": "0.78.0",
|
|
96
|
+
"oxlint": "1.93.0",
|
|
94
97
|
"typescript": "6.0.3"
|
|
95
98
|
},
|
|
96
99
|
"engines": {
|