bizdays-toolkit 0.31.4 → 0.31.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 CHANGED
@@ -6,6 +6,37 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.31.6] - 2026-11-12
10
+
11
+ 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`.
12
+
13
+ ### Fixed
14
+
15
+ - `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
16
+ - `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`
17
+ - 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`
18
+ - 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)
19
+ - 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`
20
+ - 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
21
+
22
+ ## [0.31.5] - 2026-11-11
23
+
24
+ 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.
25
+
26
+ ### Fixed
27
+
28
+ - Schedules: a specific date, an annual date or a recurring rule written with `value: undefined` was dropped, so the day took the value of its weekday (for example, `dates: [{ date: "2026-12-31", value: undefined }]` returned the usual weekday value on 31 December, and a calendar made from the schedule with `(v) => v !== undefined` treated the day as open), while the guide says that `value: undefined` is the value `undefined` (as it already was in `weekdayValues` and `holidayPolicy`). These rules now apply and return `undefined` with their `reason` and `optionPath`. A rule without a `value` key still throws `invalid-option`. If you wrote `value: undefined` to mean "no rule", remove the rule
29
+ - A wrong weekday number in `weekStart`, and in an element of `weekdays` or `skipWeekdays` of a recurring rule (such as `7`, `-1`, `1.5` or `"1"`), threw `invalid-option`, while the same mistake in `closedWeekdays`, `weekday` and `holidayPolicy.sameAs` threw `invalid-weekday`. They now all throw `invalid-weekday` (the diagnostics report the same code); an empty array, a missing `weekStart` and a list with every weekday or with the rule's own weekday are still `invalid-option`. The rule is now written in the design decisions (8). If you branch on `invalid-option` for these, branch on `invalid-weekday`
30
+ - Schedules: `holidayPolicy` with both `sameAs` and `value` (such as `{ sameAs: 0, value: 99 }`, which can come from merging shared options deeply) silently used `sameAs`. It now throws `invalid-option`, as the design decisions (8) say for conflicting options. An explicit `sameAs: undefined` is now the same as leaving it out (design decisions 6): `{ sameAs: undefined, value: 9 }` uses the value, and `{ sameAs: undefined }` alone throws `invalid-option` (it threw `invalid-weekday`). `value: undefined` is still a value
31
+ - A Temporal-like date with a calendar other than ISO (such as `{ year: 2026, month: 11, day: 23, calendarId: "japanese" }`) threw `invalid-input` as a `RangeError`, while the design decisions (3) and the guide say that `invalid-input` is a `TypeError`. It is now a `TypeError` (the code is unchanged). If you caught it with `instanceof RangeError`, use `isBizdaysError` and `code`
32
+ - `migrateCalendarOptions` and `migrateScheduleOptions` treated an old name and its new name as a conflict when one of them was an explicit `undefined` (such as `{ closedAnnual: ["12-31"], closedAnnualDates: undefined }`), so they left the old name, which `createCalendar` reads without a conflict (design decisions 6). They now keep the one with a value under the new name, in either order of the keys. The elements of `changes` are now frozen, as the design decisions (4) say for returned objects
33
+ - An instant (a `Date` or a Temporal `Instant`) in the years 1000–9999 BC was converted to a date in the same year AD (for example, 15 January 1501 BC became `"1501-01-15"`), because the year was read without its era. It now throws `out-of-range`, as the design decisions (1) say. This affects every call that takes an instant, such as `toDateString`, `today`, `dateOf` and `isBusinessDay`, also with `outOfRangePolicy: "ignore"`
34
+ - `toInstant` and `instantOf` threw `out-of-range` for 1000-01-01 and 9999-12-31 (and, in some time zones, 1000-01-02 and 9999-12-30), although the date is within the years 1000–9999 (design decisions 1 limit dates; the instant itself may fall just outside those years in UTC, such as `+010000-01-01T10:59:00.000Z` for 9999-12-31 23:59 in `Pacific/Pago_Pago`). They now return the instant
35
+ - `holidaysInYear` of a calendar or a schedule without a holiday provider, or with `outOfRangePolicy: "ignore"` (and of calendars combined from them or made from such a schedule), returned an empty list for a year outside 1000–9999, while a calendar with the default policy threw `out-of-range`. It now throws `out-of-range` in every case; the rule is now written in the design decisions (1). If you relied on the empty list, check the year first
36
+ - Type descriptions: `searchDayLimit` (of `createCalendar`, `combineCalendars` and `createCalendarFromSchedule`) mentioned only the search for a business day; it now also says that `nextClosedDay` and `previousClosedDay` throw `no-closed-day` past the limit. `KnownErrorCode` now says that `out-of-range` also covers an instant outside the years 1000–9999 and a year outside them passed to `holidaysInYear`. `AnnualDate`, `AnnualRange`, `ScheduleAnnualDate` and `ScheduleAnnualRange` now say that a month and day that exists in no year (such as `"11-31"`) is `invalid-annual-date` and that `"02-29"` matches only in leap years. `wales` said that every holiday has a Welsh name; one-off bank holidays without a Welsh name on GOV.UK (such as the 2002 Golden Jubilee) have no `names.cy`
37
+ - Documentation: the README did not list `dataVersion` among the members of a holiday provider, although it is required (a provider without it throws `invalid-provider`). The guide and the design decisions (17) said that, with `unconfirmedHolidayPolicy: "throw"`, an nth-business-day rule evaluates every day of its month unless the options do not use holidays at all; in fact the count follows the calendar it is made on: a calendar counts on its options without its recurring rules, so its count looks up holidays only when `holidayPolicy` is not `"ignore"`, and a schedule's rule follows its `calendar`. The documents now say so; the behaviour is kept because it is the one that does not throw on days a prediction cannot affect (results are unchanged)
38
+ - Documentation: the design decisions (12) could be read as moving an annual date `"02-29"` to February 28 in other years; they now say that annual dates are not moved (as before, `"02-29"` matches only in leap years, and a month and day that exists in no year is `invalid-annual-date`), and the guide says the same. The guide's table of UK providers now says that Welsh names are included where GOV.UK has them, and the guide's section on the supported years now covers instants and the year of `holidaysInYear`. The design decisions (28) gave 1998 instead of 2000 as the first year of the government lists, and (4) now lists the returned objects that are not frozen (the `options` of the migration functions and the `Date` of `toInstant`). Results are unchanged
39
+
9
40
  ## [0.31.4] - 2026-11-10
10
41
 
11
42
  This version fixes calls that threw on days that do not affect their result, makes duplicate holiday providers count once as the design decisions say, and corrects type descriptions, messages and documents. Results of calls that did not throw do not change.
@@ -898,7 +929,9 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
898
929
 
899
930
  - 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
900
931
 
901
- [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.4...HEAD
932
+ [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.6...HEAD
933
+ [0.31.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.5...v0.31.6
934
+ [0.31.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.4...v0.31.5
902
935
  [0.31.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.3...v0.31.4
903
936
  [0.31.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.2...v0.31.3
904
937
  [0.31.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.1...v0.31.2
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 13.6 KB min+gzip (about 15.4 KB with Japanese holidays, about 15.8 KB with UK bank holidays, about 14.5 KB with French holidays, about 14.6 KB with Singapore holidays; measured for 0.31.1). 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
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
@@ -116,7 +116,7 @@ diagnoseCalendar({
116
116
 
117
117
  ### Other countries and regions
118
118
 
119
- A holiday provider is an object with `id`, `timeZone`, `supportedYears` and `holidaysInYear(year)`. `bizdays-toolkit/provider` exposes `nthWeekdayOfMonth` and `easterSunday`, which most countries' holidays are built from. See [providers.md](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/providers.md).
119
+ A holiday provider is an object with `id`, `timeZone`, `supportedYears`, `dataVersion` (a string) and `holidaysInYear(year)`. `bizdays-toolkit/provider` exposes `nthWeekdayOfMonth` and `easterSunday`, which most countries' holidays are built from. See [providers.md](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/providers.md).
120
120
 
121
121
  ## Documentation
122
122
 
@@ -17,7 +17,8 @@ import type { Holiday } from "./types.ts";
17
17
  */
18
18
  export type HolidayPolicy = "closed" | "open" | "ignore";
19
19
  /**
20
- * 毎年の月日 "MM-DD"(名前付き・有効期間付きも可)。
20
+ * 毎年の月日 "MM-DD"(名前付き・有効期間付きも可)。どの年にもない月日("11-31" など)は invalid-annual-date。
21
+ * "02-29" はうるう年だけに当たる(ほかの年の 2 月 28 日・3 月 1 日に読み替えない。decisions.md の 12 番)。
21
22
  * @public
22
23
  */
23
24
  export type AnnualDate = string | ({
@@ -25,7 +26,8 @@ export type AnnualDate = string | ({
25
26
  readonly name?: string;
26
27
  } & EffectivePeriod);
27
28
  /**
28
- * 毎年の月日の期間(from > to なら年をまたぐ。例: 12-31 〜 01-03)。
29
+ * 毎年の月日の期間(from > to なら年をまたぐ。例: 12-31 〜 01-03)。端の月日は AnnualDate と同じ。
30
+ * うるう年でない年は、端の "02-29" を除いた間の日だけを含む(from: "02-20", to: "02-29" は 2 月 28 日まで)。
29
31
  * @public
30
32
  */
31
33
  export interface AnnualRange extends EffectivePeriod {
@@ -73,7 +75,10 @@ export interface CalendarOptions<Kind extends string = string> extends HolidaySo
73
75
  readonly openRecurringRules?: readonly RecurringRule<Kind>[];
74
76
  /** 祝日の扱い(既定: "closed") */
75
77
  readonly holidayPolicy?: HolidayPolicy;
76
- /** 営業日を探すときに調べる最大日数(既定: 3660)。超えたら code: "no-business-day" の RangeError */
78
+ /**
79
+ * 営業日・休業日を探すときに調べる最大日数(既定: 3660)。超えたら、営業日の探索は code: "no-business-day"、
80
+ * 休業日の探索(nextClosedDay・previousClosedDay)は code: "no-closed-day" の RangeError
81
+ */
77
82
  readonly searchDayLimit?: number;
78
83
  /** @deprecated 0.30.0 で closedAnnualDates に改名した。1.0.0 で削除する */
79
84
  readonly closedAnnual?: readonly (AnnualDate | AnnualRange)[];
@@ -147,7 +152,10 @@ export interface CombineCalendarsOptions {
147
152
  * "any": いずれかのカレンダーが営業日(例: 複数の店舗のどこかが開いている日)
148
153
  */
149
154
  readonly open: "all" | "any";
150
- /** 営業日を探すときに調べる最大日数(既定: 3660)。超えたら code: "no-business-day" の RangeError */
155
+ /**
156
+ * 営業日・休業日を探すときに調べる最大日数(既定: 3660)。超えたら、営業日の探索は code: "no-business-day"、
157
+ * 休業日の探索(nextClosedDay・previousClosedDay)は code: "no-closed-day" の RangeError
158
+ */
151
159
  readonly searchDayLimit?: number;
152
160
  /** @deprecated 0.30.0 で searchDayLimit に改名した。1.0.0 で削除する */
153
161
  readonly maxSearchDays?: number;
@@ -304,7 +312,10 @@ export declare function combineCalendars<Kind extends string = string>(calendars
304
312
  * @public
305
313
  */
306
314
  export interface CalendarFromScheduleOptions {
307
- /** 営業日を探すときに調べる最大日数(既定: 3660)。超えたら code: "no-business-day" の RangeError */
315
+ /**
316
+ * 営業日・休業日を探すときに調べる最大日数(既定: 3660)。超えたら、営業日の探索は code: "no-business-day"、
317
+ * 休業日の探索(nextClosedDay・previousClosedDay)は code: "no-closed-day" の RangeError
318
+ */
308
319
  readonly searchDayLimit?: number;
309
320
  /** @deprecated 0.30.0 で searchDayLimit に改名した。1.0.0 で削除する */
310
321
  readonly maxSearchDays?: number;
@@ -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",
@@ -53,11 +53,13 @@ export function compileCalendarOptions(c, options) {
53
53
  if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
54
54
  c.error("invalid-option", "searchDayLimit", "must be a positive integer");
55
55
  }
56
- const annual = compileAnnualRules(c, "closedAnnualDates", o["closedAnnualDates"], () => false, true, false);
57
- const open = compileDateRules(c, "openDates", o["openDates"], () => true, true, false);
58
- const closed = compileDateRules(c, "closedDates", o["closedDates"], () => false, true, false);
59
- const openRecurringRules = compileRecurringRules(c, "openRecurringRules", o["openRecurringRules"], () => true, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "openRecurringRules"), jpUsage(source));
60
- const closedRecurringRules = compileRecurringRules(c, "closedRecurringRules", o["closedRecurringRules"], () => false, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "closedRecurringRules"), jpUsage(source));
56
+ const OPEN = { value: true };
57
+ const CLOSED = { value: false };
58
+ const annual = compileAnnualRules(c, "closedAnnualDates", o["closedAnnualDates"], () => CLOSED, true, false);
59
+ const open = compileDateRules(c, "openDates", o["openDates"], () => OPEN, true, false);
60
+ const closed = compileDateRules(c, "closedDates", o["closedDates"], () => CLOSED, true, false);
61
+ const openRecurringRules = compileRecurringRules(c, "openRecurringRules", o["openRecurringRules"], () => OPEN, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "openRecurringRules"), jpUsage(source));
62
+ const closedRecurringRules = compileRecurringRules(c, "closedRecurringRules", o["closedRecurringRules"], () => CLOSED, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "closedRecurringRules"), jpUsage(source));
61
63
  return {
62
64
  schedule: {
63
65
  source,
@@ -301,10 +303,9 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
301
303
  closingPeriod(input, closingDayOfMonth, rawOptions) {
302
304
  checkClosingDay(closingDayOfMonth);
303
305
  const options = adjustOptions(rawOptions, "closingPeriod options");
304
- const isMonth = typeof input === "string" && /^\d{4}-\d{2}$/.test(input);
305
- const month = isMonth
306
- ? parseMonth(input)
307
- : closingMonthOf(dateOf(input), closingDayOfMonth, options);
306
+ const month = typeof input !== "string" || readsAsDate(input)
307
+ ? closingMonthOf(dateOf(input), closingDayOfMonth, options)
308
+ : parseMonth(input);
308
309
  const to = closingDate(month, closingDayOfMonth, options);
309
310
  const from = addDays(closingDate(shiftMonth(month, -1), closingDayOfMonth, options), 1);
310
311
  if (from > to) {
@@ -67,7 +67,6 @@ export interface Diagnostic {
67
67
  /** 関係する別の位置(shadowed では覆っている先の規則、out-of-range では祝日の提供元) */
68
68
  readonly relatedPath?: string;
69
69
  }
70
- /** 診断を実行する。祝日の提供元の誤り(年ごとに初めて使うときに分かる)も error として返す */
71
70
  /**
72
71
  * 診断のオプション(第 2 引数)。
73
72
  * @public
@@ -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 from = rule.effectiveFrom ?? (rule.effectiveTo === null ? PATTERN_FROM : rule.effectiveTo - cycle + 1);
140
- const to = Math.min(rule.effectiveTo ?? Infinity, from + cycle - 1);
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) => sameValue(v, b[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
- sameValue(a[k], b[k])));
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 week = [0, 1, 2, 3, 4, 5, 6].map((i) => w + i);
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) => (found =
463
- inPeriod(rule, n) &&
464
- matchPattern(rule, fromDayNumber(n), holidayOfSafe, undefined, lookup.fromJp)));
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) => (found = resolve(fromDayNumber(n)).day.value === true));
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");
@@ -32,7 +32,10 @@ export type KnownErrorCode =
32
32
  | "invalid-option"
33
33
  /** 祝日の提供元どうしのタイムゾーンが異なり、timeZone の指定が必要 */
34
34
  | "time-zone-conflict"
35
- /** 対応している年の範囲の外(提供元の対応年、または日付の計算が 1000〜9999 年の外に出た)。bizdays-toolkit/provider の関数の年の引数の誤りは invalid-argument */
35
+ /**
36
+ * 対応している年の範囲の外(提供元の対応年、日付の計算や瞬間の変換が 1000〜9999 年の外に出た、祝日の一覧に渡した年が
37
+ * 1000〜9999 の外)。bizdays-toolkit/provider の関数の年の引数の誤りは invalid-argument
38
+ */
36
39
  | "out-of-range"
37
40
  /** 判定が未確定の祝日(confirmed: false)に触れた(unconfirmedHolidayPolicy: "throw") */
38
41
  | "unconfirmed-holiday"
@@ -29,9 +29,7 @@ export function validateTimeZone(timeZone) {
29
29
  throw rangeError("invalid-time-zone", `Invalid time zone: ${describeValue(timeZone)}`);
30
30
  }
31
31
  }
32
- export function instantToCivil(epochMilliseconds, timeZone) {
33
- if (!Number.isFinite(epochMilliseconds))
34
- throw rangeError("invalid-time", "Invalid instant");
32
+ function wallParts(epochMilliseconds, timeZone) {
35
33
  const parts = formatterFor(timeZone).formatToParts(new Date(epochMilliseconds));
36
34
  const get = (type) => {
37
35
  const p = parts.find((x) => x.type === type);
@@ -40,10 +38,25 @@ export function instantToCivil(epochMilliseconds, timeZone) {
40
38
  return Number(p.value);
41
39
  };
42
40
  return {
43
- date: formatDate(get("year"), get("month"), get("day")),
44
- minutes: get("hour") * 60 + get("minute"),
41
+ year: get("year"),
42
+ month: get("month"),
43
+ day: get("day"),
44
+ hour: get("hour"),
45
+ minute: get("minute"),
45
46
  };
46
47
  }
48
+ export function instantToCivil(epochMilliseconds, timeZone) {
49
+ if (!Number.isFinite(epochMilliseconds))
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
+ }
54
+ if (new Date(epochMilliseconds).getUTCFullYear() < 999) {
55
+ throw rangeError("out-of-range", "Instant out of range (1000-9999)");
56
+ }
57
+ const { year, month, day, hour, minute } = wallParts(epochMilliseconds, timeZone);
58
+ return { date: formatDate(year, month, day), minutes: hour * 60 + minute };
59
+ }
47
60
  function wallTime(hour, minute) {
48
61
  if (!Number.isInteger(hour) ||
49
62
  hour < 0 ||
@@ -101,7 +114,7 @@ export function toCivil(input, timeZone) {
101
114
  return instantToCivil(input.epochMilliseconds, timeZone);
102
115
  if (isDateLike(input)) {
103
116
  if (input.calendarId !== undefined && input.calendarId !== "iso8601") {
104
- throw rangeError("invalid-input", `Unsupported calendar: ${input.calendarId} (only iso8601)`);
117
+ throw typeError("invalid-input", `Unsupported calendar: ${describeValue(input.calendarId)} (only iso8601)`);
105
118
  }
106
119
  if (!Number.isInteger(input.year) || input.year < 1000 || input.year > 9999) {
107
120
  throw rangeError("invalid-date", `Invalid date: year must be an integer from 1000 to 9999: ${describeValue(input.year)}`);
@@ -129,10 +142,8 @@ export function civilToInstant(date, minutes, timeZone) {
129
142
  const { year, month, day } = parseDate(date);
130
143
  const wall = Date.UTC(year, month - 1, day, Math.floor(minutes / 60), minutes % 60);
131
144
  const offsetAt = (ms) => {
132
- const civil = instantToCivil(ms, timeZone);
133
- const c = parseDate(civil.date);
134
- const m = civil.minutes ?? 0;
135
- return Date.UTC(c.year, c.month - 1, c.day, Math.floor(m / 60), m % 60) - ms;
145
+ const w = wallParts(ms, timeZone);
146
+ return Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute) - ms;
136
147
  };
137
148
  const before = offsetAt(wall - 86_400_000);
138
149
  const after = offsetAt(wall + 86_400_000);
@@ -30,16 +30,20 @@ function renameObject(value, places, path, changes) {
30
30
  for (const [key, v] of Object.entries(value)) {
31
31
  const r = RENAMED_KEYS.find((x) => places.includes(x.place) && x.from === key);
32
32
  if (r === undefined) {
33
- out[key] = v;
33
+ const renamedFrom = RENAMED_KEYS.some((x) => places.includes(x.place) && x.to === key && Object.hasOwn(value, x.from));
34
+ if (!(renamedFrom && v === undefined))
35
+ out[key] = v;
34
36
  continue;
35
37
  }
36
- if (Object.hasOwn(value, r.to)) {
37
- changes.push({ path: join(path, key), from: r.from, to: r.to, conflicting: true });
38
+ const hasTo = Object.hasOwn(value, r.to);
39
+ if (v !== undefined && hasTo && value[r.to] !== undefined) {
40
+ changes.push(Object.freeze({ path: join(path, key), from: r.from, to: r.to, conflicting: true }));
38
41
  out[key] = v;
39
42
  continue;
40
43
  }
41
- changes.push({ path: join(path, key), from: r.from, to: r.to });
42
- out[r.to] = v;
44
+ changes.push(Object.freeze({ path: join(path, key), from: r.from, to: r.to }));
45
+ if (v !== undefined || !hasTo)
46
+ out[r.to] = v;
43
47
  }
44
48
  return out;
45
49
  }
@@ -49,7 +53,7 @@ function renameValues(value, place, key, path, changes) {
49
53
  const r = rules.find((x) => x.from === v);
50
54
  if (!r)
51
55
  return v;
52
- changes.push({ path: at, from: r.from, to: r.to });
56
+ changes.push(Object.freeze({ path: at, from: r.from, to: r.to }));
53
57
  return r.to;
54
58
  };
55
59
  return Array.isArray(value) ? value.map((v, i) => one(v, `${path}[${i}]`)) : one(value, path);
@@ -48,9 +48,10 @@ export function closingDayIn({ year, month }, closingDayOfMonth) {
48
48
  const last = lengthOfMonth(year, month);
49
49
  return closingDayOfMonth === -1 || closingDayOfMonth > last ? last : closingDayOfMonth;
50
50
  }
51
+ export const readsAsDate = (input) => input.split("-").length >= 3;
51
52
  export function closingPeriod(input, closingDayOfMonth) {
52
53
  checkClosingDay(closingDayOfMonth);
53
- const month = typeof input === "string" && input.split("-").length === 3
54
+ const month = typeof input === "string" && readsAsDate(input)
54
55
  ? parseMonth(closingMonth(input, closingDayOfMonth))
55
56
  : parseMonth(input);
56
57
  const previous = shiftMonth(month, -1);
@@ -403,7 +403,7 @@ export type ScheduleRecurringRule<Value, Kind extends string = string> = (Exclud
403
403
  readonly value: Value;
404
404
  };
405
405
  /**
406
- * 毎年の月日 "MM-DD" の値。
406
+ * 毎年の月日 "MM-DD" の値。月日は AnnualDate と同じ(どの年にもない月日は invalid-annual-date、"02-29" はうるう年だけ)。
407
407
  * @public
408
408
  */
409
409
  export interface ScheduleAnnualDate<Value> extends EffectivePeriod {
@@ -412,7 +412,7 @@ export interface ScheduleAnnualDate<Value> extends EffectivePeriod {
412
412
  readonly name?: string;
413
413
  }
414
414
  /**
415
- * 毎年の月日の期間の値(from > to なら年をまたぐ。例: 12-31 〜 01-03)。
415
+ * 毎年の月日の期間の値(from > to なら年をまたぐ。例: 12-31 〜 01-03)。端の月日と "02-29" の扱いは AnnualRange と同じ。
416
416
  * @public
417
417
  */
418
418
  export interface ScheduleAnnualRange<Value> extends EffectivePeriod {
@@ -80,14 +80,14 @@ export function compileDateRules(c, path, entries, valueOf, allowString, valueKe
80
80
  c.error("invalid-option", p, allowString ? "must be a date string or an object" : "must be an object");
81
81
  return;
82
82
  }
83
- const value = valueOf(entry, p);
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
86
  if ("date" in defined) {
87
87
  checkUnknownKeys(c, p, defined, ["date", "name", ...(valueKey ? ["value"] : [])]);
88
88
  const n = checkDate(c, `${p}.date`, entry["date"]);
89
- if (n !== undefined && value !== undefined)
90
- rules.push({ path: p, from: n, to: n, value, name });
89
+ if (n !== undefined && got !== undefined)
90
+ rules.push({ path: p, from: n, to: n, value: got.value, name });
91
91
  return;
92
92
  }
93
93
  if (!("from" in defined) || !("to" in defined)) {
@@ -103,8 +103,8 @@ export function compileDateRules(c, path, entries, valueOf, allowString, valueKe
103
103
  c.error("invalid-range", p, `"from" must not be after "to" (${String(entry["from"])} > ${String(entry["to"])})`);
104
104
  return;
105
105
  }
106
- if (value !== undefined)
107
- rules.push({ path: p, from, to, value, name });
106
+ if (got !== undefined)
107
+ rules.push({ path: p, from, to, value: got.value, name });
108
108
  });
109
109
  return rules;
110
110
  }
@@ -123,7 +123,7 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString, value
123
123
  c.error("invalid-option", p, allowString ? "must be an annual date string (MM-DD) or an object" : "must be an object");
124
124
  return;
125
125
  }
126
- const value = valueOf(entry, p);
126
+ const got = valueOf(entry, p);
127
127
  const name = checkName(c, p, entry["name"]);
128
128
  const period = checkPeriod(c, p, entry);
129
129
  const defined = withoutUndefined(entry, DATE_SHAPE_KEYS);
@@ -135,8 +135,8 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString, value
135
135
  ...PERIOD_KEYS,
136
136
  ]);
137
137
  const md = checkMonthDay(c, `${p}.date`, entry["date"]);
138
- if (md !== undefined && value !== undefined && period) {
139
- rules.push({ path: p, from: md, to: md, value, name, ...period });
138
+ if (md !== undefined && got !== undefined && period) {
139
+ rules.push({ path: p, from: md, to: md, value: got.value, name, ...period });
140
140
  }
141
141
  return;
142
142
  }
@@ -153,8 +153,8 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString, value
153
153
  ]);
154
154
  const from = checkMonthDay(c, `${p}.from`, entry["from"]);
155
155
  const to = checkMonthDay(c, `${p}.to`, entry["to"]);
156
- if (from !== undefined && to !== undefined && value !== undefined && period) {
157
- rules.push({ path: p, from, to, value, name, ...period });
156
+ if (from !== undefined && to !== undefined && got !== undefined && period) {
157
+ rules.push({ path: p, from, to, value: got.value, name, ...period });
158
158
  }
159
159
  });
160
160
  return rules;
@@ -189,10 +189,10 @@ const ON_HOLIDAY_RULES = [
189
189
  ];
190
190
  const isDayOfMonth = (v) => v === -1 || (Number.isInteger(v) && v >= 1 && v <= 31);
191
191
  const isMonth = (v) => Number.isInteger(v) && v >= 1 && v <= 12;
192
- function checkSet(c, path, raw, valid, expected) {
192
+ function checkSet(c, path, raw, valid, expected, elementCode = "invalid-option") {
193
193
  const list = Array.isArray(raw) ? raw : [raw];
194
194
  if (list.length === 0 || !list.every(valid)) {
195
- c.error("invalid-option", path, `must be ${expected}, or a non-empty array of them`);
195
+ c.error(list.length === 0 ? "invalid-option" : elementCode, path, `must be ${expected}, or a non-empty array of them`);
196
196
  return undefined;
197
197
  }
198
198
  return new Set(list);
@@ -216,7 +216,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
216
216
  checkUnknownKeys(c, p, renamedEntry, keys);
217
217
  const entry = withoutUndefined(renamedEntry);
218
218
  const nationalOfJp = jp !== "none" && reportNational(c, `${written}.kinds`, entry["kinds"], jp === "mixed");
219
- const value = valueOf(entry, p);
219
+ const got = valueOf(entry, p);
220
220
  const name = checkName(c, p, entry["name"]);
221
221
  const hasWeekday = "weekday" in entry;
222
222
  const hasDay = "dayOfMonth" in entry;
@@ -372,10 +372,14 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
372
372
  if (hasBusinessWeek) {
373
373
  if (isWeekday(entry["weekStart"]))
374
374
  weekStart = entry["weekStart"];
375
- else {
375
+ else if (!("weekStart" in entry)) {
376
376
  c.error("invalid-option", `${p}.weekStart`, 'is required with "businessDayOfWeek": an integer from 0 (Sunday) to 6 (Saturday) (the first day of the week)');
377
377
  ok = false;
378
378
  }
379
+ else {
380
+ c.error("invalid-weekday", `${p}.weekStart`, "must be an integer from 0 (Sunday) to 6 (Saturday) (the first day of the week)");
381
+ ok = false;
382
+ }
379
383
  }
380
384
  if (entry["holidayOverlapPolicy"] === "after-holiday") {
381
385
  c.error("invalid-option", `${p}.holidayOverlapPolicy`, `"after-holiday" cannot be used with "${key}" (shifting the nth business day has no meaning; use "under-holiday" or "over-holiday")`);
@@ -469,7 +473,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
469
473
  ok = false;
470
474
  }
471
475
  else {
472
- const set = checkSet(c, `${p}.weekdays`, entry["weekdays"], isWeekday, "a weekday (0 = Sunday to 6 = Saturday)");
476
+ const set = checkSet(c, `${p}.weekdays`, entry["weekdays"], isWeekday, "a weekday (0 = Sunday to 6 = Saturday)", "invalid-weekday");
473
477
  if (set)
474
478
  weekdays = set;
475
479
  else
@@ -508,7 +512,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
508
512
  ok = false;
509
513
  }
510
514
  else {
511
- const set = checkSet(c, `${p}.skipWeekdays`, entry["skipWeekdays"], isWeekday, "a weekday (0 = Sunday to 6 = Saturday)");
515
+ const set = checkSet(c, `${p}.skipWeekdays`, entry["skipWeekdays"], isWeekday, "a weekday (0 = Sunday to 6 = Saturday)", "invalid-weekday");
512
516
  if (set === undefined)
513
517
  ok = false;
514
518
  else if (set.size === 7) {
@@ -524,7 +528,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
524
528
  }
525
529
  }
526
530
  const period = checkPeriod(c, p, entry);
527
- if (ok && period && value !== undefined) {
531
+ if (ok && period && got !== undefined) {
528
532
  rules.push(Object.freeze({
529
533
  path: p,
530
534
  weekday,
@@ -548,7 +552,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
548
552
  weekdays,
549
553
  months,
550
554
  holidayOverlapPolicy: onHoliday,
551
- value,
555
+ value: got.value,
552
556
  name,
553
557
  ...period,
554
558
  }));
@@ -642,7 +646,7 @@ function requiredValue(c) {
642
646
  c.error("invalid-option", path, 'must have "value"');
643
647
  return undefined;
644
648
  }
645
- return entry["value"];
649
+ return { value: entry["value"] };
646
650
  };
647
651
  }
648
652
  function validateProvider(c, path, p) {
@@ -755,7 +759,7 @@ function loadProviderYear(provider, year) {
755
759
  if (!Array.isArray(list))
756
760
  throw providerDataError(provider, year, "holidaysInYear must return an array");
757
761
  const seen = new Set();
758
- return list.map((h, i) => {
762
+ return Array.from(list, (h, i) => {
759
763
  if (!isObject(h))
760
764
  throw providerDataError(provider, year, `item ${i} is not an object`);
761
765
  const { date, name, nameEn, kind, confirmed } = h;
@@ -845,6 +849,8 @@ export function createHolidayLookup(source) {
845
849
  function holidaysInYear(year) {
846
850
  if (!Number.isInteger(year))
847
851
  throw rangeError("invalid-argument", `Invalid year: ${describeValue(year)}`);
852
+ if (year < 1000 || year > 9999)
853
+ throw rangeError("out-of-range", `Year out of range (1000-9999): ${year}`);
848
854
  return Object.freeze([...holidayMap(year).values()].sort((a, b) => a.date < b.date ? -1 : a.date > b.date ? 1 : 0));
849
855
  }
850
856
  return {
@@ -941,16 +947,22 @@ export function compileScheduleOptions(c, options) {
941
947
  }
942
948
  let holiday = "ignore";
943
949
  const holidayRaw = renameValue(c, "schedule", "holidayPolicy", writtenKey(["source", "schedule"], written, "holidayPolicy"), o["holidayPolicy"]);
950
+ const hasSameAs = isObject(holidayRaw) && holidayRaw["sameAs"] !== undefined;
951
+ const hasValue = isObject(holidayRaw) && "value" in holidayRaw;
944
952
  if (holidayRaw === undefined || holidayRaw === "ignore") {
945
953
  holiday = "ignore";
946
954
  }
947
- else if (isObject(holidayRaw) && "sameAs" in holidayRaw) {
948
- if (isWeekday(holidayRaw["sameAs"]))
949
- holiday = Object.freeze({ sameAs: holidayRaw["sameAs"] });
955
+ else if (hasSameAs && hasValue) {
956
+ c.error("invalid-option", "holidayPolicy", 'cannot have both "sameAs" and "value"');
957
+ }
958
+ else if (hasSameAs) {
959
+ const sameAs = holidayRaw["sameAs"];
960
+ if (isWeekday(sameAs))
961
+ holiday = Object.freeze({ sameAs });
950
962
  else
951
963
  c.error("invalid-weekday", "holidayPolicy.sameAs", "must be an integer from 0 (Sunday) to 6 (Saturday)");
952
964
  }
953
- else if (isObject(holidayRaw) && "value" in holidayRaw) {
965
+ else if (hasValue) {
954
966
  holiday = Object.freeze({ value: holidayRaw["value"] });
955
967
  }
956
968
  else {
@@ -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
  * (必須にすると、自作の提供元が型エラーになるため)。
@@ -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
  }
@@ -23,7 +23,8 @@ export type UkHoliday = Holiday<UkHolidayKind>;
23
23
  */
24
24
  export declare const england: HolidayProvider<UkHolidayKind>;
25
25
  /**
26
- * Wales の bank holidays の提供元(GOV.UK の England and Wales)。名称にウェールズ語(names.cy)が付く。
26
+ * Wales の bank holidays の提供元(GOV.UK の England and Wales)。GOV.UK のウェールズ語版に名称がある祝日には、
27
+ * ウェールズ語の名称(names.cy)が付く(公式の名称がない臨時の祝日には付かない)。
27
28
  * @public
28
29
  */
29
30
  export declare const wales: HolidayProvider<UkHolidayKind>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bizdays-toolkit",
3
- "version": "0.31.4",
3
+ "version": "0.31.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",