bizdays-toolkit 0.30.7 → 0.30.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -3
- package/dist/core/calendar.d.ts +3 -2
- package/dist/core/calendar.js +5 -5
- package/dist/core/diagnose.d.ts +3 -2
- package/dist/core/diagnose.js +18 -9
- package/dist/core/input.js +1 -1
- package/dist/core/schedule.d.ts +6 -2
- package/dist/core/schedule.js +19 -8
- package/dist/jp/index.d.ts +1 -1
- package/dist/provider/index.d.ts +1 -0
- package/dist/provider/index.js +11 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,47 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.30.8] - 2026-11-06
|
|
8
|
+
|
|
9
|
+
品質改善提案(10 通目)の分です。文書・決定の文書・コメントが実装と食い違っていた箇所を直し、不具合を 4 件直しました。カレンダー・スケジュールの判定の結果は変わりません。変わるのは、診断の結果(カレンダーの個別の日付・毎年の月日の `value` に `unknown-option` が増える。誤った `counting-basis` が消え、曜日の規則ごとに出る)、`no-business-day` の例外のクラス(`Error` → `RangeError`。広がる向き)、`withSubstituteDays` が返す祝日の凍結です。あわせて、品質の仕組みを軽くしました(タイムゾーンを変えたテストを 4 ゾーンから 2 ゾーンに、診断の性質のテストを抜き出しに、全日の結果を比べる補助を 1 つに、同じ恒等式を確かめるテストを 1 か所に。詳しくは「開発」)。公開物の `.js` が変わるのは Fixed の 4 件と、到達しないコードを消した 1 行(`core/input.js`。「開発」)の分だけで、カレンダー・スケジュール・提供元の判定の結果は変わらないので、利用者の作業は要りません。
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 診断: 第 n 営業日の規則(`businessDayOfMonth`・`businessDayOfWeek`)の `counting-basis` を、同じ設定の最初の毎週の曜日の規則だけを見て出していた。有効期間が重ならない曜日の規則(例: `{ weekday: 3, effectiveTo: "2026-12-31" }` と `{ businessDayOfMonth: 1, effectiveFrom: "2027-01-01" }`)や、対応年の外で決して使われない曜日の規則(例: 既定の `outOfRangePolicy: "throw"` で `{ weekday: 3, effectiveTo: "1950-12-31" }`。`out-of-range` だけが出る)を理由にも出し、曜日の規則が 2 つ以上あっても最初の 1 つしか `relatedPath` に出さなかった。有効期間が重なり、使われている曜日の規則ごとに 1 件出すようにした。減る形: 上の 2 つの例(どちらも `counting-basis` が出なくなる。`outOfRangePolicy: "ignore"` では 1950 年の数え方に影響するので、2 つ目の例でも出す)と、第 n 営業日の規則より後ろにある曜日の規則が `shadowed`・`never-matches` のとき(判定の順番で、使われないと分かる前に見ていた。例: `[{ businessDayOfMonth: 1 }, { weekday: 3 }, { weekday: 3 }]` は 2 件ではなく 1 件)。増える形: `{ weekday: 3 }`・`{ weekday: 6 }`・`{ businessDayOfMonth: 1 }` のように曜日の規則が 2 つ(2 件)、開く規則 `{ weekday: 6 }` と閉じる規則 `{ weekday: 3 }` に 1 つずつ(2 件。0.30.7 までは開く規則の 1 件だけ)。誤った診断を直す修正で、判定の結果は変わらない(オラクルは `counting-basis` を「出たら前提があるか」の一方向だけで、有効期間を見ずに確かめていたので見つけなかった。逆向きと件数も確かめるようにした。種類は正解と突き合わせる仕組みの不足)
|
|
14
|
+
- 診断: カレンダーの個別の日付・毎年の月日(`closedDates`・`openDates`・`closedAnnualDates`)の要素に書いた `value`(スケジュールの書き方の流用)を、黙って通していた。作成時は今までどおり無視し、診断で `unknown-option`(`path` は `closedDates[0].value` の形)を出す(打ち間違いは診断で見つかるという 8 番の約束のとおりにする。スケジュールの `dates`・`annualDates` の `value` は今までどおり既知のキー)
|
|
15
|
+
- `bizdays-toolkit/provider` の `withSubstituteDays`: 入力のまま返す祝日を凍結していなかった(振替日だけ凍結していた。4 番の「返すものはすべて凍結」から外れていた)。契約の項目だけを持つ凍結した複製にした。返す配列の凍結と戻り値の型の `readonly` は、`push` していたコードや可変の配列の型に代入しているコードが通らなくなるので、パッチではなく 0.31.0 で行う(RELEASING.md の区分)
|
|
16
|
+
- `no-business-day` の例外のクラスが経路で違っていた(探索と第 n 営業日は `Error`、`closingPeriod` は `RangeError`)。どれも `RangeError` にした。`RangeError` は `Error` でもあるので、`instanceof Error` で受けていたコードはそのまま通り、`instanceof RangeError` で受けていたコードは新たに捕まる(広がる向き)
|
|
17
|
+
- 文書を直した(コードの挙動は変わらない):
|
|
18
|
+
- ガイド(英日)の「設定の診断」の `redundant` の説明: 「毎年の月日と繰り返しの規則は個別の日付を除いた設定で調べる」と無条件に書いていた。0.30.3 から、自分の設定を基準に第 n 営業日を数える規則があれば、個別の日付は数え方を変えるので残し、毎年の月日は取り除いて変わりうる月・週の日をすべて調べる(0.30.3 の Fixed のとおり。例は `test/diagnose.test.ts` の「第 n 営業日の規則があると、数え方を変える個別の日付・毎年の月日は redundant にしない」)
|
|
19
|
+
- ガイド(英日)の診断の表の `counting-basis` の行と `src/core/diagnose.ts` の冒頭のコメント: `businessDayOfMonth` の規則だけを書いていたが、週の第 n 営業日の規則(`businessDayOfWeek`)でも出る。`{ businessDayOfWeek: -1, weekStart: 1 }` と `{ weekday: 0 }` の設定の単体テストを `test/counting-basis.test.ts` に足した
|
|
20
|
+
- ガイド(英日)の「未確定の祝日」: 「`holidaysInYear`・`holidaysBetween` は投げない」を、未確定の祝日では投げない、に限った(対応年の外の `out-of-range` と、提供元のデータの誤りの `invalid-provider-data` は投げる)
|
|
21
|
+
- ガイド(英日)と `BusinessDayOnOrAfterOptions.cutoff` の TSDoc: `cutoff` が `"HH:mm"` だけを受け付ける理由(入力の時刻は分の精度で比べるので、秒を持つ締め時刻は入力の秒と比べられない)を書いた。秒の受け付けは 0.31.0 で扱う
|
|
22
|
+
|
|
23
|
+
### 開発
|
|
24
|
+
|
|
25
|
+
- 診断のオラクル: `counting-basis` の確かめを、第 n 営業日の規則と毎週の曜日の規則の有効期間が重なる組を前提にし、前提があるのに出ないとき・出た件数が組の数と違うときも失敗にした。項目の一覧(`test/fixtures/oracle-items.json`)に、有効期間が重ならない組を作る 4 項目(閉じる・開く規則の両方の `{ weekday: 2, effectiveTo: "2025-06-30" }` と `{ businessDayOfMonth: 2, effectiveFrom: "2025-07-01" }`)を足した(71 → 75 項目)
|
|
26
|
+
- 前の版との比較: 特徴 `counting-rule-with-period-weekly-rule`(`etc/result-changes.json` で `counting-basis` が消える差分を許す)と `calendar-date-with-value`(増える向きなので許可は足さない)を足し、固定の設定 4 つ(`fixed-counting-basis-no-overlap`・`fixed-counting-basis-two-weekly`・`fixed-counting-basis-shadowed-weekly`・`fixed-calendar-date-with-value`)を足した
|
|
27
|
+
- 決定の文書: 3 番に「同じ `code` は同じクラスで投げる」を足した
|
|
28
|
+
- `counting-basis` の判定を、規則どうしの走査の後の第 2 の走査にした(規則の並び順で結果が変わらないように)
|
|
29
|
+
- `./diagnose` の gzip のサイズ(測定 26,322。上限 26,500)。`counting-basis` の判定の直しで増えた
|
|
30
|
+
- 決定の文書: 「版と互換性」の章の見出しの直後にあった番号のない箇条 2 つ(オラクルの完全性を判定する期間、週の第 n 営業日の規則の判定できない月の限界)を 31 番に移した。`KNOWN_INCOMPLETE` に載せるときの手順は RELEASING.md の「診断のオラクル」の行と重なっていたので決定の文書からは消し、31 番(オラクルの完全性の箇条の直後)に手順の場所だけを書いた。章の見出しと最初の決定の見出しの間に本文があれば失敗にする検査を `scripts/check-package.ts` に足し、`scripts/tool-selftest.ts` にその誤りを足した(目次の検査は見出しだけを見るので、見出しのない本文を見つけられなかった)
|
|
31
|
+
- 「0.31.0 の P1」を「診断の判定の作り直し(0.31.0)」と言葉で書いた(決定の文書・RELEASING.md・この CHANGELOG の 0.30.4 と 0.30.6 の節・飛ばしの理由。P1 はどの文書にも定義のない名前だったため)
|
|
32
|
+
- API どうしの整合のテスト(`test/consistency.test.ts`)の名前の番号を整合 1〜11 に振り直した(「整合 5」が 6 件あり、失敗の報告から文書の行を引けなかった)。RELEASING.md の「API どうしの整合」の行は、関係の数を書かずに、関係とテストの番号を並べた
|
|
33
|
+
- `bizdays-toolkit/jp` の `jp` の TSDoc に 0.30.0 の旧名 `holidays` が残っていたのを `holidayProvider` に直した。`scripts/check-names.ts` の旧名の残りの検査(C14)は `holidays` をキーの形でしか探していなかったので、日本語の TSDoc で引数名として書く形(「の holidays に」)を足した
|
|
34
|
+
- `src/core/input.ts` の到達しない `replace(" ", "T")` を消した(直前の正規表現が区切りを `T` に限るので、空白を含む値はこの行に届かない。`core/input.js` の 1 行が変わるが、挙動は同じ)
|
|
35
|
+
- `check-package`: `src` が実行環境のタイムゾーンに依存する API(ローカル時刻の `Date` の API・`getTimezoneOffset`・`toLocale…String`・`new Date(年, 月, …)`・`timeZone` を渡さない `Intl.DateTimeFormat`)を使っていないことを確かめるようにし、`tool-selftest` にその誤りを 2 件足した
|
|
36
|
+
- タイムゾーンを変えたテスト(`scripts/test-tz.ts`)を UTC・Asia/Tokyo・America/Los_Angeles・Pacific/Chatham の 4 ゾーンから America/Los_Angeles・Pacific/Chatham の 2 ゾーンにした(理由は decisions.md の 35 番。1 コアの手元で 209 秒 → 104 秒)
|
|
37
|
+
- `check-names`: 報告のパスの区切りを `/` にそろえた(Windows では `\` で出ていて、期待と突き合わせにくかった)。旧名の表に `holidays` がないときは、日本語の TSDoc の引数名の形の検査(0.30.8 の ZIP-A で足した)を黙って外さず、一緒に消すよう失敗にする
|
|
38
|
+
- 前の版との比較(`scripts/result-compare.ts`): 意図した差分として許した設定の `id` と対象を一覧に出すようにした(意図しない差分が出たときに、許した側と見比べるため)。固定の設定 `fixed-counting-basis-open-closed-weekly`(開く規則と閉じる規則に曜日の規則が 1 つずつ。`counting-basis` が 2 件に増える形)を足した
|
|
39
|
+
- `src/core/input.ts`: `Date.parse` にオフセット付きの文字列だけを渡している理由をコメントに書いた
|
|
40
|
+
- 開発用のツールを更新: oxlint 1.88.0 → 1.91.0、oxfmt 0.73.0 → 0.76.0、`@types/node` 24.19.2 → 26.6.6(どれも既存のファイルの整形と lint の結果は変わらない)
|
|
41
|
+
- `check-package` の実行環境のタイムゾーンに依存する API の検査を直した: 引数の中の括弧を 1 段まで読む(`new Date(Number(y), m)` を見逃していた)、`new` を付けない `Intl.DateTimeFormat(…)` と `timeZone: undefined` も不可にした、文字列を渡す `new Date("…")` を不可にし、`Date.parse` は `src/core/input.ts` の 1 か所(オフセット付きに限った文字列)だけを許して回数が変わったら失敗にした、行末の `//` コメントも検査の前に除くようにした(コメントに書いた形で誤って失敗していた)。`tool-selftest` に文字列を渡す `new Date` の誤りを足した
|
|
42
|
+
- 診断の性質のテスト(`test/diagnose-properties.test.ts`)を、ほかの全件のテストと同じ「`pnpm check` は抜き出し、全件は CI」の形にした: 設定は毎回作り(乱数の列は変わらない。生成範囲の記録はカレンダーを作る時点で特徴を集めるので、記録の仕組み `scripts/record-generator-features.ts` は全件を動かす)、`pnpm check` では 3 件に 1 件の決まった抜き出しだけを確かめ、全件は `DIAGNOSE_PROPERTY_FULL=1` で CI の `diagnose-consistency` ジョブ。タイムゾーンを変えた実行では 3 つとも飛ばす(暦日だけで決まる。試行を減らして動かしていた `tzRuns`・`tzCountingRuns` は消した)。1 コアの手元で `pnpm test` のこのファイルの分が約 45 秒 → 12 秒
|
|
43
|
+
- 変形しても結果が同じ(`test/metamorphic.test.ts`)の全件(`METAMORPHIC_FULL=1`、関係ごとに 40 件)を CI の `diagnose-consistency` ジョブで動かすようにした(RELEASING.md に全件の環境変数だけがあり、動かす場所がなかった。36 番の「黙って外れる確認を作らない」)
|
|
44
|
+
- 全日の結果を比べる補助を `test/support/compare.ts` に 1 つにした(`daysOf`・`dayLine`・`linesOf`・`removeItem`)。診断の性質・診断のオラクル・整合・和集合・失敗の注入のテストと `test/support/provider.ts` が別々に持っていた、期間の全日の列・1 日の結果の文字列・項目の取り除きを置き換えた(約束は変えない。変形のテストの全項目の比較、整合のテストの `valueOn` の比較、失敗の注入のテストの `isBusinessDay` と例外の有無の比較は、比べる約束が違うので残した)
|
|
45
|
+
- 同じ恒等式を 3 か所で確かめていたのを 1 か所にした: `diff(a, add(a, n)) = n`・`add(end, −n) = start`・加算の結果は営業日・逆向きの差は −n、次の営業日は翌日からの営業日の一覧の最初・前の営業日は前日以前の営業日、を `test/consistency.test.ts` の整合 2・3(目録の設定)で確かめる。`test/properties.test.ts` の性質「addBusinessDays の結果は営業日で、n 進めて −n 戻ると元の営業日に戻る」「nextBusinessDay との間に営業日はなく、previousBusinessDay で戻る」と、`test/naming.test.ts` の T3 のカレンダーの対を消した(T3 は日付の `diffDays`・`addDays` の対だけ残す)。生成範囲の記録は変わらない(残る性質が同じ設定の作り方を使う。`record-generator-features.ts --check` で確かめた)
|
|
46
|
+
- `check-package` の実行環境のタイムゾーンに依存する API の検査: 文字列の中身を先に空にしてから `//` のコメントを除くようにした(`" //"` を含む文字列を行末のコメントと誤認して、その行の残りが黙って検査から外れていた)
|
|
47
|
+
|
|
7
48
|
## [0.30.7] - 2026-11-05
|
|
8
49
|
|
|
9
50
|
テスト拡充案の第 3 段です。0.30.6 の取り込みで持ち越した項目を片付け、そこで見つけた診断の不具合を 2 つ直したので、公開物の `.js` は 0.30.6 から変わります(Fixed。変わるのは `./diagnose` だけで、カレンダー・スケジュールの判定の結果は変わりません)。テストと道具では、変形しても結果が同じことの検査、文書の例と文章の主張の検査、オラクルの完全性を失敗にする切り替えを入れ、設定の結果の差分の旧名の比較の穴を直しました。設定の結果の差分の定期実行(テスト拡充案の T8)は入れず、手動の広い比較として入れました。自前の変異テスト(T9)は、0.31.0 の診断の作り直しの前に行います。
|
|
@@ -53,7 +94,7 @@
|
|
|
53
94
|
|
|
54
95
|
### 開発
|
|
55
96
|
|
|
56
|
-
- サイズの上限: 上限を 25,800 から 26,500 に上げた `./diagnose`(測定 26,158)。理由: Fixed の 3
|
|
97
|
+
- サイズの上限: 上限を 25,800 から 26,500 に上げた `./diagnose`(測定 26,158)。理由: Fixed の 3 件目(基準のカレンダーが投げる月を判定できない月として扱い、確かでない診断を出さない)の修正で増えたため。診断の判定の作り直し(0.31.0)の分は見込まず、そのときにあらためて測って上げる
|
|
57
98
|
- 診断のオラクル: カナリア(完全性の報告に必ず出る設定)が取り除ける理由を確かめた。開く規則「5・7 月の月曜」が開きうる祝日(自作の提供元の 5・7 月の月曜の祝日)を、`holidayOverlapPolicy` の既定(`"under-holiday"`)では開かないため。`"over-holiday"` にすると取り除けなくなることを確かめるテストを足し、コメントの理由を直した(コメントの主張を確かめていなかった穴。種類 C)
|
|
58
99
|
- 診断のオラクル: `ORACLE_FULL` なしの `ORACLE_SHARD` を例外にした(`pnpm check` の抜き出しの間隔 111 と分ける数の公約数で、分が 0 件になっていた)。どのテストも、試した設定が 0 件なら失敗にする。失敗のメッセージを 1 つの関数にまとめ、設定を作り直せる情報(項目・休業日の扱いの方針・定休日・取り除いた項目)を入れた(黙って空振りする穴。種類 C)
|
|
59
100
|
- 生成範囲: 危険の分かっている組み合わせ(第 n 営業日(月・週)× 個別の日付、第 n 営業日(月)× 毎年の月日、祝日の規則 × 臨時営業日、祝日の翌日・前日 × `skipWeekdays` × 個別の日付、和集合の提供元 × `kinds`)の一覧(`test/support/combinations.ts`)を作り、呼び出し側ごとに 1 回以上作ることを確かめる(作れない組み合わせは事実の理由を付けて除く)。個々の特徴の包含だけでは組み合わせを守れなかった(生成器の偏りの穴。種類 A)
|
|
@@ -104,7 +145,7 @@
|
|
|
104
145
|
- 規則と設定の目録 `test/support/catalog.ts` を置き、乱数のテスト(`test/properties.test.ts`・`test/diagnose-properties.test.ts`)と `scripts/result-compare.ts` の生成器を目録に切り替えた。`test/catalog.test.ts` が、目録を `etc/api.md` の公開の型(繰り返しの規則の形・設定のキー・選択肢の値)と突き合わせ、生成器が目録のすべての形・キー・値を作ることを確かめる(生成器の偏りの穴を塞ぐ。第 n 営業日の規則が生成器になく、誤った `redundant` を見逃した種類)
|
|
105
146
|
- `test/properties.test.ts` のカレンダーに、目録の繰り返しの規則を入れた(これまでは繰り返しの規則のないカレンダーだけを試していた)。営業日のないカレンダーになった試行は、性質の前提を満たさないので飛ばす(1 割まで)
|
|
106
147
|
- `test/diagnose-properties.test.ts` は、対応年の短い自作の提供元(`test/support/provider.ts`)で全日を比べる(400 日の抜き出しをやめた)
|
|
107
|
-
- 診断の総当たりのオラクル `test/diagnose-oracle.test.ts` を入れた。目録の規則の形の代表と個別の日付・毎年の月日の 2 つまでの組み合わせで、出た項目を取り除いて全日の結果を比べ、`expired`・`no-business-day`・`counting-basis` の約束も確かめる。`pnpm check` は決まった抜き出し、CI の `oracle` ジョブはすべての組み合わせを試し、完全性(取り除けるのに何も出ない項目)を Job Summary
|
|
148
|
+
- 診断の総当たりのオラクル `test/diagnose-oracle.test.ts` を入れた。目録の規則の形の代表と個別の日付・毎年の月日の 2 つまでの組み合わせで、出た項目を取り除いて全日の結果を比べ、`expired`・`no-business-day`・`counting-basis` の約束も確かめる。`pnpm check` は決まった抜き出し、CI の `oracle` ジョブはすべての組み合わせを試し、完全性(取り除けるのに何も出ない項目)を Job Summary に報告する。出た項目をまとめて取り除いても変わらない性質(診断の判定の作り直し(0.31.0)の正解の定義)は、印を付けて用意した(`ORACLE_JOINT=1` で試せる)。0.30.2 に向けると、すべての組み合わせで第 n 営業日の誤った `redundant` を検出する(正解と突き合わせる仕組みの不在の穴を塞ぐ)
|
|
108
149
|
- `scripts/test-tz.ts`: タイムゾーンを変えた実行では、オラクルを飛ばす(暦日だけで決まるので)
|
|
109
150
|
- `RELEASING.md`: 品質の確認に目録とオラクルを足し、手元の確認は前の版のタグを読める状態で通すことを書いた
|
|
110
151
|
- サイズ(gzip): `./diagnose` 25,321 → 25,360(測定 25,360。上の Fixed の文の分)。上限は変えていない
|
|
@@ -892,7 +933,8 @@
|
|
|
892
933
|
|
|
893
934
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
894
935
|
|
|
895
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.
|
|
936
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.8...HEAD
|
|
937
|
+
[0.30.8]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.7...v0.30.8
|
|
896
938
|
[0.30.7]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.6...v0.30.7
|
|
897
939
|
[0.30.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.5...v0.30.6
|
|
898
940
|
[0.30.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.4...v0.30.5
|
package/dist/core/calendar.d.ts
CHANGED
|
@@ -160,6 +160,7 @@ export interface CombineCalendarsOptions {
|
|
|
160
160
|
export interface BusinessDayOnOrAfterOptions {
|
|
161
161
|
/**
|
|
162
162
|
* 締め時刻 "HH:mm"(カレンダーのタイムゾーン)。
|
|
163
|
+
* "HH:mm" のみ。入力の時刻は分の精度で比べるため(秒を持つ締め時刻は、入力の秒と比べられない)。
|
|
163
164
|
* 入力の時刻がこの時刻以降なら、その日は対象にしない。時刻を持たない入力(暦日の文字列・Temporal の PlainDate など)
|
|
164
165
|
* と組み合わせると code: "invalid-argument" の Error(締め時刻が黙って無視されるのを防ぐため)
|
|
165
166
|
*/
|
|
@@ -239,7 +240,7 @@ export interface Calendar<Kind extends string = string> extends HolidayLookup<Ki
|
|
|
239
240
|
adjust(input: DateInput, options: AdjustOptions): DateString;
|
|
240
241
|
/**
|
|
241
242
|
* 月 "YYYY-MM" の第 n 営業日。n が負なら月末から数える(-1 は最終営業日)。
|
|
242
|
-
* その月の営業日が足りなければ code: "no-business-day" の
|
|
243
|
+
* その月の営業日が足りなければ code: "no-business-day" の RangeError
|
|
243
244
|
*/
|
|
244
245
|
nthBusinessDayOfMonth(month: MonthString, n: number): DateString;
|
|
245
246
|
/** 月 "YYYY-MM" の最初の営業日(nthBusinessDayOfMonth(month, 1)) */
|
|
@@ -262,7 +263,7 @@ export interface Calendar<Kind extends string = string> extends HolidayLookup<Ki
|
|
|
262
263
|
* 営業日を考慮した締め日で区切ったときの、その月分の期間(両端を含む暦日。前月の調整後の締め日の翌日から
|
|
263
264
|
* 当月の調整後の締め日まで)。暦日を渡すと、その日が属する期間(closingMonth で求めた月の期間)。
|
|
264
265
|
* 月を渡して、その月に固有の期間がない(前月の締め日から当月の締め日までに営業日がない)ときは
|
|
265
|
-
* code: "no-business-day" の
|
|
266
|
+
* code: "no-business-day" の RangeError。返す値は変更できず、name は付かない
|
|
266
267
|
*/
|
|
267
268
|
closingPeriod(input: DateInput | MonthString, closingDayOfMonth: number, options: AdjustOptions): {
|
|
268
269
|
readonly from: DateString;
|
package/dist/core/calendar.js
CHANGED
|
@@ -51,9 +51,9 @@ export function compileCalendarOptions(c, options) {
|
|
|
51
51
|
if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
|
|
52
52
|
c.error("invalid-option", "searchDayLimit", "must be a positive integer");
|
|
53
53
|
}
|
|
54
|
-
const annual = compileAnnualRules(c, "closedAnnualDates", o["closedAnnualDates"], () => false, true);
|
|
55
|
-
const open = compileDateRules(c, "openDates", o["openDates"], () => true, true);
|
|
56
|
-
const closed = compileDateRules(c, "closedDates", o["closedDates"], () => false, true);
|
|
54
|
+
const annual = compileAnnualRules(c, "closedAnnualDates", o["closedAnnualDates"], () => false, true, false);
|
|
55
|
+
const open = compileDateRules(c, "openDates", o["openDates"], () => true, true, false);
|
|
56
|
+
const closed = compileDateRules(c, "closedDates", o["closedDates"], () => false, true, false);
|
|
57
57
|
const openRecurringRules = compileRecurringRules(c, "openRecurringRules", o["openRecurringRules"], () => true, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "openRecurringRules"), jpUsage(source));
|
|
58
58
|
const closedRecurringRules = compileRecurringRules(c, "closedRecurringRules", o["closedRecurringRules"], () => false, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "closedRecurringRules"), jpUsage(source));
|
|
59
59
|
return {
|
|
@@ -130,7 +130,7 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
130
130
|
if (isOpen(date))
|
|
131
131
|
return date;
|
|
132
132
|
}
|
|
133
|
-
throw
|
|
133
|
+
throw rangeError("no-business-day", `No business day found within ${searchDayLimit} days from ${start}`);
|
|
134
134
|
}
|
|
135
135
|
function countOpen(from, toExclusive) {
|
|
136
136
|
let count = 0;
|
|
@@ -213,7 +213,7 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
213
213
|
const days = businessDaysOfMonth(month);
|
|
214
214
|
const found = n > 0 ? days[n - 1] : days[days.length + n];
|
|
215
215
|
if (found === undefined) {
|
|
216
|
-
throw
|
|
216
|
+
throw rangeError("no-business-day", `${month} has ${days.length} business day(s); requested ${n > 0 ? "" : "last "}#${Math.abs(n)}`);
|
|
217
217
|
}
|
|
218
218
|
return found;
|
|
219
219
|
}
|
package/dist/core/diagnose.d.ts
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* no-business-day … 営業日が 1 日もない設定(営業日カレンダーのみ)
|
|
14
14
|
* - info … redundant: 取り除いても結果が変わらない規則・設定(判定に祝日を使わない設定の unconfirmedHolidayPolicy: "throw" を含む)
|
|
15
15
|
* expired: 第 2 引数の asOf より前に終わった規則・日付(asOf を渡したときだけ)
|
|
16
|
-
* counting-basis: 第 n 営業日の規則(businessDayOfMonth)の数える基準は繰り返しの規則を除くので、
|
|
17
|
-
* 同じ設定の毎週の曜日の規則({ weekday })の曜日は営業日として数えられる(relatedPath
|
|
16
|
+
* counting-basis: 第 n 営業日の規則(businessDayOfMonth・businessDayOfWeek)の数える基準は繰り返しの規則を除くので、
|
|
17
|
+
* 同じ設定の毎週の曜日の規則({ weekday })の曜日は営業日として数えられる(relatedPath にその規則)。
|
|
18
|
+
* 有効期間が重なり、使われている曜日の規則ごとに 1 件
|
|
18
19
|
*
|
|
19
20
|
* 未確定の祝日の扱い(unconfirmedHolidayPolicy)は診断では常に "accept" で評価する。診断は設定の形を調べるもので、
|
|
20
21
|
* 祝日が確定しているかどうかは関係がなく、"throw" のまま評価すると例外を握りつぶして「当てはまらない」と誤判定するため
|
package/dist/core/diagnose.js
CHANGED
|
@@ -155,6 +155,8 @@ function annualBits(rule) {
|
|
|
155
155
|
return Uint8Array.from(LEAP_MONTH_DAYS, (md) => (matchMonthDay(rule, md) ? 1 : 0));
|
|
156
156
|
}
|
|
157
157
|
const isSubset = (a, b) => a.every((v, i) => v === 0 || b[i] === 1);
|
|
158
|
+
const periodsOverlap = (a, b) => (a.effectiveFrom ?? -Infinity) <= (b.effectiveTo ?? Infinity) &&
|
|
159
|
+
(b.effectiveFrom ?? -Infinity) <= (a.effectiveTo ?? Infinity);
|
|
158
160
|
const periodCovers = (earlier, later) => (earlier.effectiveFrom === null ||
|
|
159
161
|
(later.effectiveFrom !== null && earlier.effectiveFrom <= later.effectiveFrom)) &&
|
|
160
162
|
(earlier.effectiveTo === null ||
|
|
@@ -481,15 +483,6 @@ function analyzeRules(c, compiled, isCalendar) {
|
|
|
481
483
|
compiled.holiday.value === false) {
|
|
482
484
|
c.info("redundant", `${rule.path}.holidayOverlapPolicy`, 'This option does not change the result: holidays are closed (holidayPolicy: "closed"), so an nth business day is never a holiday');
|
|
483
485
|
}
|
|
484
|
-
if (businessDayBased && rule.basis === null) {
|
|
485
|
-
const weekly = recurring.find((r) => r.weekday !== null && r.nth === null && r.interval === null && r.months === null);
|
|
486
|
-
if (weekly) {
|
|
487
|
-
c.info("counting-basis", rule.path, weekly.value === true
|
|
488
|
-
? `The business days are counted without recurring rules, so the days opened by the weekday rule ${weekly.path} are not counted`
|
|
489
|
-
: `The business days are counted without recurring rules, so the weekday rule ${weekly.path} does not reduce the count; ` +
|
|
490
|
-
"write regular closed weekdays as closedWeekdays if they should not be counted", weekly.path);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
486
|
const k = recurring.findIndex((r, i) => i < j &&
|
|
494
487
|
canCover(r, rule) &&
|
|
495
488
|
periodCovers(r, rule) &&
|
|
@@ -527,6 +520,22 @@ function analyzeRules(c, compiled, isCalendar) {
|
|
|
527
520
|
unused.add(rule);
|
|
528
521
|
c.warning("shadowed", rule.path, `This rule is never used: the earlier rule ${recurring[k].path} covers all of its days`, recurring[k].path);
|
|
529
522
|
});
|
|
523
|
+
for (const rule of recurring) {
|
|
524
|
+
if (rule.businessDays === null || rule.basis !== null)
|
|
525
|
+
continue;
|
|
526
|
+
const weeklies = recurring.filter((r) => r.weekday !== null &&
|
|
527
|
+
r.nth === null &&
|
|
528
|
+
r.interval === null &&
|
|
529
|
+
r.months === null &&
|
|
530
|
+
!unused.has(r) &&
|
|
531
|
+
periodsOverlap(rule, r));
|
|
532
|
+
for (const weekly of weeklies) {
|
|
533
|
+
c.info("counting-basis", rule.path, weekly.value === true
|
|
534
|
+
? `The business days are counted without recurring rules, so the days opened by the weekday rule ${weekly.path} are not counted`
|
|
535
|
+
: `The business days are counted without recurring rules, so the weekday rule ${weekly.path} does not reduce the count; ` +
|
|
536
|
+
"write regular closed weekdays as closedWeekdays if they should not be counted", weekly.path);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
530
539
|
if (isCalendar && window && !dates.some((r) => r.value === true)) {
|
|
531
540
|
const resolve = createResolver(without(compiled, null, true), lookup);
|
|
532
541
|
let found = false;
|
package/dist/core/input.js
CHANGED
|
@@ -73,7 +73,7 @@ function parseString(value, timeZone) {
|
|
|
73
73
|
const offset = m[5];
|
|
74
74
|
if (offset === undefined)
|
|
75
75
|
return { date, minutes };
|
|
76
|
-
const normalized = value.replace(
|
|
76
|
+
const normalized = value.replace(/([+-]\d{2})(\d{2})$/, "$1:$2");
|
|
77
77
|
const ms = Date.parse(normalized);
|
|
78
78
|
if (Number.isNaN(ms)) {
|
|
79
79
|
throw rangeError("invalid-time", `Invalid date/time string: ${JSON.stringify(value)}`);
|
package/dist/core/schedule.d.ts
CHANGED
|
@@ -618,9 +618,13 @@ export declare const inPeriod: (rule: CompiledPeriod, n: number) => boolean;
|
|
|
618
618
|
* @internal 個別の日付の規則を検証して取り込む。
|
|
619
619
|
* entry は "YYYY-MM-DD"・{ date }・{ from, to } のいずれか。値は valueOf で決める
|
|
620
620
|
*/
|
|
621
|
-
export declare function compileDateRules<Value>(c: IssueCollector, path: string, entries: unknown, valueOf: (entry: Record<string, unknown>, path: string) => Value | undefined, allowString: boolean
|
|
621
|
+
export declare function compileDateRules<Value>(c: IssueCollector, path: string, entries: unknown, valueOf: (entry: Record<string, unknown>, path: string) => Value | undefined, allowString: boolean,
|
|
622
|
+
/** 要素の value を既知のキーにするか(スケジュールは true。カレンダーは false で、書くと診断の unknown-option) */
|
|
623
|
+
valueKey: boolean): DateRule<Value>[];
|
|
622
624
|
/** @internal 毎年の月日の規則を検証して取り込む(entry は "MM-DD"・{ date }・{ from, to }) */
|
|
623
|
-
export declare function compileAnnualRules<Value>(c: IssueCollector, path: string, entries: unknown, valueOf: (entry: Record<string, unknown>, path: string) => Value | undefined, allowString: boolean
|
|
625
|
+
export declare function compileAnnualRules<Value>(c: IssueCollector, path: string, entries: unknown, valueOf: (entry: Record<string, unknown>, path: string) => Value | undefined, allowString: boolean,
|
|
626
|
+
/** 要素の value を既知のキーにするか(スケジュールは true。カレンダーは false で、書くと診断の unknown-option) */
|
|
627
|
+
valueKey: boolean): AnnualRule<Value>[];
|
|
624
628
|
/** @internal 繰り返しの規則(検証済み) */
|
|
625
629
|
export interface RecurringRuleCompiled<Value> extends CompiledPeriod {
|
|
626
630
|
/** 設定の中の位置(例: "closedRecurringRules[0]") */
|
package/dist/core/schedule.js
CHANGED
|
@@ -63,7 +63,7 @@ function checkMonthDay(c, path, value) {
|
|
|
63
63
|
}
|
|
64
64
|
return value;
|
|
65
65
|
}
|
|
66
|
-
export function compileDateRules(c, path, entries, valueOf, allowString) {
|
|
66
|
+
export function compileDateRules(c, path, entries, valueOf, allowString, valueKey) {
|
|
67
67
|
if (entries === undefined)
|
|
68
68
|
return [];
|
|
69
69
|
if (!Array.isArray(entries)) {
|
|
@@ -81,7 +81,7 @@ export function compileDateRules(c, path, entries, valueOf, allowString) {
|
|
|
81
81
|
const value = valueOf(entry, p);
|
|
82
82
|
const name = checkName(c, p, entry["name"]);
|
|
83
83
|
if ("date" in entry) {
|
|
84
|
-
checkUnknownKeys(c, p, entry, ["date", "name", "value"]);
|
|
84
|
+
checkUnknownKeys(c, p, entry, ["date", "name", ...(valueKey ? ["value"] : [])]);
|
|
85
85
|
const n = checkDate(c, `${p}.date`, entry["date"]);
|
|
86
86
|
if (n !== undefined && value !== undefined)
|
|
87
87
|
rules.push({ path: p, from: n, to: n, value, name });
|
|
@@ -91,7 +91,7 @@ export function compileDateRules(c, path, entries, valueOf, allowString) {
|
|
|
91
91
|
c.error("invalid-option", p, 'must have "date" or both "from" and "to"');
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
checkUnknownKeys(c, p, entry, ["from", "to", "name", "value"]);
|
|
94
|
+
checkUnknownKeys(c, p, entry, ["from", "to", "name", ...(valueKey ? ["value"] : [])]);
|
|
95
95
|
const from = checkDate(c, `${p}.from`, entry["from"]);
|
|
96
96
|
const to = checkDate(c, `${p}.to`, entry["to"]);
|
|
97
97
|
if (from === undefined || to === undefined)
|
|
@@ -105,7 +105,7 @@ export function compileDateRules(c, path, entries, valueOf, allowString) {
|
|
|
105
105
|
});
|
|
106
106
|
return rules;
|
|
107
107
|
}
|
|
108
|
-
export function compileAnnualRules(c, path, entries, valueOf, allowString) {
|
|
108
|
+
export function compileAnnualRules(c, path, entries, valueOf, allowString, valueKey) {
|
|
109
109
|
if (entries === undefined)
|
|
110
110
|
return [];
|
|
111
111
|
if (!Array.isArray(entries)) {
|
|
@@ -124,7 +124,12 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString) {
|
|
|
124
124
|
const name = checkName(c, p, entry["name"]);
|
|
125
125
|
const period = checkPeriod(c, p, entry);
|
|
126
126
|
if ("date" in entry) {
|
|
127
|
-
checkUnknownKeys(c, p, entry, [
|
|
127
|
+
checkUnknownKeys(c, p, entry, [
|
|
128
|
+
"date",
|
|
129
|
+
"name",
|
|
130
|
+
...(valueKey ? ["value"] : []),
|
|
131
|
+
...PERIOD_KEYS,
|
|
132
|
+
]);
|
|
128
133
|
const md = checkMonthDay(c, `${p}.date`, entry["date"]);
|
|
129
134
|
if (md !== undefined && value !== undefined && period) {
|
|
130
135
|
rules.push({ path: p, from: md, to: md, value, name, ...period });
|
|
@@ -135,7 +140,13 @@ export function compileAnnualRules(c, path, entries, valueOf, allowString) {
|
|
|
135
140
|
c.error("invalid-option", p, 'must have "date" or both "from" and "to"');
|
|
136
141
|
return;
|
|
137
142
|
}
|
|
138
|
-
checkUnknownKeys(c, p, entry, [
|
|
143
|
+
checkUnknownKeys(c, p, entry, [
|
|
144
|
+
"from",
|
|
145
|
+
"to",
|
|
146
|
+
"name",
|
|
147
|
+
...(valueKey ? ["value"] : []),
|
|
148
|
+
...PERIOD_KEYS,
|
|
149
|
+
]);
|
|
139
150
|
const from = checkMonthDay(c, `${p}.from`, entry["from"]);
|
|
140
151
|
const to = checkMonthDay(c, `${p}.to`, entry["to"]);
|
|
141
152
|
if (from !== undefined && to !== undefined && value !== undefined && period) {
|
|
@@ -951,8 +962,8 @@ export function compileScheduleOptions(c, options) {
|
|
|
951
962
|
else {
|
|
952
963
|
c.error("invalid-option", "holidayPolicy", 'must be "ignore", { sameAs: weekday } or { value }');
|
|
953
964
|
}
|
|
954
|
-
const annual = compileAnnualRules(c, "annualDates", o["annualDates"], requiredValue(c), false);
|
|
955
|
-
const dates = compileDateRules(c, "dates", o["dates"], requiredValue(c), false);
|
|
965
|
+
const annual = compileAnnualRules(c, "annualDates", o["annualDates"], requiredValue(c), false, true);
|
|
966
|
+
const dates = compileDateRules(c, "dates", o["dates"], requiredValue(c), false, true);
|
|
956
967
|
const recurring = compileRecurringRules(c, "recurringRules", o["recurringRules"], requiredValue(c), [...RECURRING_RULE_KEYS, "value"], "schedule", writtenKey(["source", "schedule"], written, "recurringRules"), jpUsage(source));
|
|
957
968
|
for (const rule of recurring) {
|
|
958
969
|
if (rule.businessDays === null)
|
package/dist/jp/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type { JpHolidayKind, KnownJpHolidayKey, KnownJpHolidayKind } from "./rul
|
|
|
21
21
|
*/
|
|
22
22
|
export type JpHoliday = Holiday<JpHolidayKind>;
|
|
23
23
|
/**
|
|
24
|
-
* 日本の祝日の提供元(createCalendar・createSchedule の
|
|
24
|
+
* 日本の祝日の提供元(createCalendar・createSchedule の holidayProvider に渡す)。
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
export declare const jp: HolidayProvider<JpHolidayKind>;
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ export interface WithSubstituteDaysOptions<Kind extends string> {
|
|
|
86
86
|
* 振替日は年をまたぐことがある(12 月 31 日が祝日の国で日曜日なら翌年の 1 月 1 日)。提供元の holidaysInYear は
|
|
87
87
|
* その年の日付だけを返す契約なので、そうなる国では翌年の分として扱うこと。
|
|
88
88
|
* 国民の休日(2 つの祝日に挟まれた日)のような国に固有の規則は含まない。
|
|
89
|
+
* 返す祝日はどれも凍結している(入力のまま返す祝日も、契約の項目だけを持つ複製)。
|
|
89
90
|
*
|
|
90
91
|
* @example 米国の連邦祝日(土曜日は前の金曜日、日曜日は次の月曜日)
|
|
91
92
|
* withSubstituteDays(federal, { directions: { 6: "previous", 0: "next" }, kind: "observed",
|
package/dist/provider/index.js
CHANGED
|
@@ -114,7 +114,17 @@ export function withSubstituteDays(holidays, options) {
|
|
|
114
114
|
const { directions: rules, kind, renameSubstitute: name, originalPolicy: original, } = checkOptions(options);
|
|
115
115
|
const sorted = [...input].sort((a, b) => (a.date < b.date ? -1 : 1));
|
|
116
116
|
const taken = new Set(sorted.map((h) => h.date));
|
|
117
|
-
const result = sorted
|
|
117
|
+
const result = sorted
|
|
118
|
+
.filter((h) => original !== "drop" || rules[weekdayOf(h.date)] === undefined)
|
|
119
|
+
.map((h) => Object.freeze({
|
|
120
|
+
date: h.date,
|
|
121
|
+
name: h.name,
|
|
122
|
+
nameEn: h.nameEn,
|
|
123
|
+
...(h.names === undefined ? {} : { names: h.names }),
|
|
124
|
+
kind: h.kind,
|
|
125
|
+
confirmed: h.confirmed,
|
|
126
|
+
...(h.key === undefined ? {} : { key: h.key }),
|
|
127
|
+
}));
|
|
118
128
|
for (const h of sorted) {
|
|
119
129
|
const direction = rules[weekdayOf(h.date)];
|
|
120
130
|
if (direction === undefined)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.8",
|
|
4
4
|
"description": "Holidays, business-day calendar and day-by-day schedules (e.g. store hours) with time zone support. Japanese holidays verified against the Cabinet Office data; UK bank holidays (England, Wales, Scotland, Northern Ireland) verified against GOV.UK and The Gazette; French public holidays (metropole, Alsace-Moselle) verified against data.gouv.fr; Singapore public holidays verified against data.gov.sg. / 祝日と営業日のカレンダー(タイムゾーン対応・日本の祝日は内閣府、英国の bank holidays は GOV.UK と The Gazette、フランスの祝日は data.gouv.fr、シンガポールの祝日は data.gov.sg のデータで全日照合)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bank-holidays",
|
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
"api:update": "pnpm build && node scripts/api-report.ts --update"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@types/node": "
|
|
91
|
-
"oxfmt": "0.
|
|
92
|
-
"oxlint": "1.
|
|
90
|
+
"@types/node": "26.6.6",
|
|
91
|
+
"oxfmt": "0.76.0",
|
|
92
|
+
"oxlint": "1.91.0",
|
|
93
93
|
"typescript": "6.0.3"
|
|
94
94
|
},
|
|
95
95
|
"engines": {
|