bizdays-toolkit 0.31.6 → 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 CHANGED
@@ -6,6 +6,25 @@ 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
+
9
28
  ## [0.31.6] - 2026-11-12
10
29
 
11
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`.
@@ -929,7 +948,8 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
929
948
 
930
949
  - 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
931
950
 
932
- [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.6...HEAD
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
933
953
  [0.31.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.5...v0.31.6
934
954
  [0.31.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.4...v0.31.5
935
955
  [0.31.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.3...v0.31.4
@@ -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
  * 営業時間表のような日ごとの値が設定の正本で、営業日の計算(加減算・調整・期日など)も同じ設定から行いたいときに使う
@@ -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"] ?? "closed";
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"] ?? 3660;
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
  }
@@ -345,7 +345,7 @@ export function combineCalendars(calendars, options) {
345
345
  if (!Array.isArray(calendars) || calendars.length < 2) {
346
346
  throw rangeError("invalid-argument", "calendars must be an array of two or more calendars");
347
347
  }
348
- calendars.forEach((c, i) => {
348
+ Array.from(calendars).forEach((c, i) => {
349
349
  if (!isCalendarLike(c))
350
350
  throw rangeError("invalid-argument", `calendars[${i}] is not a calendar`);
351
351
  if (calendars.indexOf(c) !== i) {
@@ -357,7 +357,7 @@ export function combineCalendars(calendars, options) {
357
357
  if (mode !== "all" && mode !== "any") {
358
358
  throw rangeError("invalid-option", 'open must be "all" or "any"');
359
359
  }
360
- const searchDayLimit = (o["searchDayLimit"] ?? 3660);
360
+ const searchDayLimit = (o["searchDayLimit"] === undefined ? 3660 : o["searchDayLimit"]);
361
361
  if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
362
362
  throw rangeError("invalid-option", "searchDayLimit must be a positive integer");
363
363
  }
@@ -435,7 +435,7 @@ export function createCalendarFromSchedule(schedule, isOpen, options) {
435
435
  throw rangeError("invalid-argument", "isOpen must be a function (value) => boolean");
436
436
  }
437
437
  const o = optionsObject(options, "createCalendarFromSchedule options", (v) => renameKeys("throw", ["fromSchedule"], "", v), false, "invalid-option");
438
- const searchDayLimit = (o["searchDayLimit"] ?? 3660);
438
+ const searchDayLimit = (o["searchDayLimit"] === undefined ? 3660 : o["searchDayLimit"]);
439
439
  if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
440
440
  throw rangeError("invalid-option", "searchDayLimit must be a positive integer");
441
441
  }
@@ -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
- /** 関係する別の位置(shadowed では覆っている先の規則、out-of-range では祝日の提供元) */
67
+ /**
68
+ * 関係する別の位置。shadowed では覆っている先の規則、redundant では取り除いたときに代わりに決める規則(1 つに定まる
69
+ * ときだけ)、counting-basis では数え方に入らない曜日の規則、out-of-range では祝日の提供元
70
+ */
68
71
  readonly relatedPath?: string;
69
72
  }
70
73
  /**
@@ -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;
@@ -64,7 +64,7 @@ function wallTime(hour, minute) {
64
64
  !Number.isInteger(minute) ||
65
65
  minute < 0 ||
66
66
  minute > 59) {
67
- const two = (v) => String(v).padStart(2, "0");
67
+ const two = (v) => typeof v === "number" ? String(v).padStart(2, "0") : describeValue(v);
68
68
  throw rangeError("invalid-time", `Invalid time: ${two(hour)}:${two(minute)}`);
69
69
  }
70
70
  return hour * 60 + minute;
@@ -121,7 +121,10 @@ export function toCivil(input, timeZone) {
121
121
  }
122
122
  const date = formatDate(input.year, input.month, input.day);
123
123
  if (typeof input.hour === "number") {
124
- return { date, minutes: wallTime(input.hour, input.minute ?? 0) };
124
+ return {
125
+ date,
126
+ minutes: wallTime(input.hour, input.minute === undefined ? 0 : input.minute),
127
+ };
125
128
  }
126
129
  return { date, minutes: null };
127
130
  }
@@ -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.split("-").length === 3
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) {
@@ -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 回ある時刻は先のほう(toInstant と同じ)
554
+ * 夏時間で存在しない時刻は飛んだ分だけ後ろに、2 回ある時刻は先のほう。時差は分の精度で扱う(toInstant と同じ)
555
555
  */
556
556
  instantOf(date: DateString, time: string): Date;
557
557
  /** 今日の日付(タイムゾーン) */
@@ -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"] ?? (hasHoliday ? "over-holiday" : "under-holiday");
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"] ?? "throw";
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"] ?? "accept";
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
  }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bizdays-toolkit",
3
- "version": "0.31.6",
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.77.0",
93
- "oxlint": "1.92.0",
95
+ "oxfmt": "0.78.0",
96
+ "oxlint": "1.93.0",
94
97
  "typescript": "6.0.3"
95
98
  },
96
99
  "engines": {