bizdays-toolkit 0.30.1 → 0.30.3
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 +61 -1
- package/README.md +2 -3
- package/dist/core/calendar.d.ts +1 -1
- package/dist/core/diagnose.d.ts +1 -1
- package/dist/core/diagnose.js +111 -10
- package/dist/core/errors.d.ts +2 -0
- package/dist/core/month.d.ts +1 -1
- package/dist/core/renamed.d.ts +2 -2
- package/dist/core/schedule.d.ts +2 -2
- package/dist/core/schedule.js +7 -4
- package/dist/uk/rules.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,64 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.30.3] - 2026-11-01
|
|
8
|
+
|
|
9
|
+
診断の不具合を直すパッチ版です。あわせて、0.30.2 の後に main で整えた決定の文書・規約・CI を含みます。カレンダー・スケジュールの判定の結果は変わりません。
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 診断: 営業日カレンダーの繰り返しの規則(閉じる・開くの両方)に第 n 営業日の規則(`businessDayOfMonth`・`businessDayOfWeek`)がある設定で、数え方を変える個別の日付・毎年の月日(とそれに関わる規則)を、取り除くと同じ月・週の別の日の結果が変わるのに `redundant` としていた。`docs/decisions.md` の 16 番(第 n 営業日を数える基準には個別の日付と毎年の月日が入る)から外れていた、0.30.2 以前からある不具合。取り除いて変わりうる月・週の日をすべて調べ、規則の判定の基準にも個別の日付を残すようにした。判定できない日は、取り除ける側に倒さない(31 番)。これまでは規則どうしの診断の途中で判定が例外になると、その結果を捨てて祝日の提供元の誤り(`invalid-provider-data` など)として報告していたが、その項目を `redundant` にしないで診断を続けるようにした(判定が例外になる設定は、手元では作れていない)。該当する設定では診断の結果から `redundant` が減るので、診断の結果を `deepEqual` で比べているテストは期待値が変わることがある。減ったのは取り除くと結果が変わる項目なので、新しい結果を期待値にする。入った版を問わず不具合の修正はパッチ、という規約(`RELEASING.md` の「区分」)の最初の適用
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- 旧名を受け付ける期間を「0.30.x の間」と書いていた箇所(決定の文書の 10・37 番、`RELEASING.md` の設定の結果の差分の行、移行ガイド、テストとスクリプトのコメント)を「1.0.0 より前の版」に直した。0.31.0 以降のマイナー版でも旧名は受け付け、1.0.0 で `invalid-option` にする(移行ガイドの冒頭の「1.0.0 まで」と同じ)。長く続いた挙動の扱いで CHANGELOG に書くものを「決めた結果と理由」にそろえた
|
|
18
|
+
- README(英日)から npm のダウンロード数のバッジを外した(shields.io が npm の API のレート制限を受け、「rate limited by upstream service」と表示されていたため)
|
|
19
|
+
- `docs/decisions.md` を、時系列に並んだ 56 の番号から、話題ごとの 11 章・39 の番号に整理し直した。各決定は今の決定・理由・退けた案だけにし、版ごとの追記・提案書の番号・測定値は CHANGELOG と git の履歴に任せた。冒頭に目次と番号の付け方(番号は ID で振り直さない、新しい決定は章の中に置いて通しの番号を振る、追記を重ねず本文を書き換える)を、末尾に旧番号との対応表(残し続ける)を置いた。ソース・スクリプト・テスト・ワークフロー・文書の番号の参照を新しい番号に直した。CHANGELOG の 0.30.2 までの節の番号は旧番号のまま
|
|
20
|
+
- `docs/decisions.md` の整理で落ちていた決定を戻した: ウェールズ語の名称を GOV.UK のリポジトリの翻訳ファイルで照合する例外(29 番)、`src` が Node.js 固有の機能を使わない検査(35 番)、和集合の `"regular"` で退けた 2 案(10 番)と結果の比較で退けた案(37 番)、`withSubstituteDays` の定義(26 番)、スケジュールの第 n 営業日の基準と `"over-holiday"` の `redundant`(16 番)、英国の臨時の祝日の名前の付け方(28 番)、時刻を数値で受けない理由(7 番)、0.23.0〜0.29.0 を欠番にした理由(9 番)。新たに例外を投げる変更は 1.0.0 以降はメジャー版であることを 6・32 番と `RELEASING.md` に書き、旧番号の対応表の行き先の漏れを足した。あわせて、整理で省いた細部のうち決定にあたるもの(`decidedByPath`・`asOf`・ID `"JP"` の判定の細部、`Policy` の選択肢の部分集合、`?: never` の項目に TSDoc を付けないことなど)を本文に戻し、誤った `key` の修正をマイナー版、性能・サイズの改善をパッチと `RELEASING.md` の区分に書いた
|
|
21
|
+
- `RELEASING.md` と `docs/decisions.md` の役割を分けた: 版の区分・互換性の約束・手順・検査の一覧は `RELEASING.md` だけに書き、決定の文書の 32・33・35〜37・39 番はその理由と退けた案だけにした(同じ規則を 2 か所に書かない。36 番)。`RELEASING.md` の箇条からは理由を除き、決定の番号を指すようにした。残っていた重複(誤った `key` の直し方、提供元の内部の置き換えの条件、黙って外れる検査を作らないこと、`src` の移植性の検査)も規則を `RELEASING.md` に、理由を決定の文書に分けた
|
|
22
|
+
- 外部のレビューを受けて直した: 決定の文書の 27 番に 4 か国目を選んだときに見送った候補(香港・米国・ドイツ)と理由を戻した。公開から複数のマイナー版を経た挙動が文書と違うときは、直す前にコードを直す(パッチ)・文書を挙動に合わせる・マイナー版で扱うのどれにするかを決め、その結果を CHANGELOG に書くことを `RELEASING.md` の「区分」と 32 番に足した。`scripts/result-compare.ts` の冒頭のコメントを、診断の結果が誤った診断の修正で消えうるという今の約束に合わせた
|
|
23
|
+
- 規約を見直した(`docs/decisions.md` の 25・26・32・33・37 番、`RELEASING.md`): 約束した挙動から外れていた不具合の修正は、入った版を問わずパッチにする(これまでは直前の版で入った退行だけ)。誤った診断を直したときは、前の版の診断の結果が消えることがある。性能の比較は、正しさのために遅くなることを CHANGELOG に書いた版を通す。同梱の提供元の内部は、前の版との祝日データの比較で差分がなければ置き換えてよい。誤った祝日の `key` を直す手順を決めた
|
|
24
|
+
- ガイド(英日)の「0.30.0 より前に保存した設定」に 0.30.2 で足した、書き換えた後に診断を実行する例の設定が、`timeZone` を書いていないので `time-zone-conflict`(error)になっていた(日本と英国の提供元はタイムゾーンが違う)。例は `deprecated-option` だけを取り出していたので、コード例の検査は通っていた。`timeZone: "Asia/Tokyo"` と `holidayPolicy: "open"` を足し、診断の結果をすべて示す形にした(誤りがあれば例の検査で止まる)
|
|
25
|
+
|
|
26
|
+
### 開発
|
|
27
|
+
|
|
28
|
+
- `test/diagnose.test.ts`・`test/diagnose-properties.test.ts`: 上の Fixed の 4 例(月・週の第 n 営業日、閉じる・開く規則)と、スケジュールの第 n 営業日の規則では結果が変わらないことのテストを足した。性質のテストの設定の生成に第 n 営業日の規則を足し、第 n 営業日の規則と個別の日付を必ず持つ設定の性質を足した(0.30.2 では失敗する。生成に入っていなかったので、この不具合を見逃していた)
|
|
29
|
+
- `scripts/result-compare.ts`: 意図した差分を、診断の消えた結果のコード(`removedCodes`)で絞れるようにした。上の Fixed の差分を、第 n 営業日の規則と個別の日付・毎年の月日を持つ設定の `redundant` が消えたものだけに絞って許す(`counting-rules-with-dates`)。上の Fixed の例を固定の設定に足した(週の第 n 営業日の例は、それがない 0.22.2 とは比べない)
|
|
30
|
+
- サイズの上限: `./diagnose` を 25,000 から 25,800 に上げた(上の Fixed で上限を超えたため。測定値に小さな余裕を足した値)
|
|
31
|
+
- サイズ(gzip): `./diagnose` 24,753 → 25,321(測定 25,321)。ルート 17,997(測定 17,997)と `./jp` 20,226(測定 20,226)は変わらない
|
|
32
|
+
- Node.js 26 が LTS に入ったので、CI の `check` の行列を 22.23.4・24.22.2・26.13.0 に上げ(2026-10-21 のセキュリティリリース、24 系はその後の不具合の修正(2026-10-28)、26 の LTS の最初の版)、ビルド・ブラウザー・ランタイム・比較・公開・監視のジョブの固定の版を 26.13.0 にした。`compat` は engines の下限の 22.12.0 だけにした(26 は `check` で確かめるようになり、LTS 入りを控えた系列は今はない)。`RELEASING.md` の npm 12 の動作要件を今の値(`>=26.0.0` を含む)に、公開物の互換性の行の `compat` の版を直した。開発環境とそろえ、npm を 12.2.1、pnpm を 12.16.1 に上げた(どちらも公開から 48 時間を過ぎた版)
|
|
33
|
+
- `scripts/check-package.ts`: 決定の文書の目次が本文の章・見出しと一致すること(番号の重複も)を確かめる。CHANGELOG の 0.30.2 までの節の番号は旧番号の対応表で確かめ、`` `docs/decisions.md` の N 番 `` のようにバッククォートで囲んだ参照も確かめるようにした(これまでは見ていなかった)。「番」を書き忘れた参照(`decisions.md の 15`)は形の誤りとして止める
|
|
34
|
+
- `scripts/bench-compare.ts`: CHANGELOG の今の版(または [Unreleased])の「開発」に決まった言葉で理由を書いた版は、2 倍を超えて遅くなっても表に記録して合格にする(言葉は `RELEASING.md` の品質の確認の表)
|
|
35
|
+
- `etc/result-changes.json` に 0.30.1 の修正(和集合の旧名 `"national"`)を足した。公開済みの 0.30.0 → 0.30.1 を比べたとき、意図した修正ではなく診断の退行だけが「許していない差分」として出る
|
|
36
|
+
|
|
37
|
+
- `scripts/result-compare.ts`: 意図した差分を許す特徴を、比べた対象ごとに付けるようにした。0.30.2 では合成の組の相手の特徴まで付けていたので、相手だけが日本の提供元と `kinds: ["regular"]` を持つ組では、元のカレンダー単独の差分まで許していた。合成だけ組の両方の設定から、ほかはその設定だけから付ける。日本の提供元だけの設定の `"national"` の特徴は、同じ配列に同じ形で `"regular"` を含む規則もあるときだけ付ける(名前を `kinds-national-and-regular-with-jp-only` に改めた。前の版が 0.30.1 のときだけ効く項目)
|
|
38
|
+
- `test/fixtures/national-union-0.22.2.json` の出典の説明で、`"national"` の扱いの根拠を旧 55 番としていたのを旧 54 番(今の 10 番)に直した
|
|
39
|
+
|
|
40
|
+
## [0.30.2] - 2026-10-30
|
|
41
|
+
|
|
42
|
+
0.30.0・0.30.1 の改名の後始末の続きの版です。新しい設定・関数・診断コードはありません。公開物の `.js` の挙動が変わるのは Fixed の 1 つ(診断の結果)で、カレンダー・スケジュールの判定の結果は変わりません。
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- 診断: 日本の提供元だけの設定で、`"regular"` と旧名の `"national"` の同じ規則(祝日・祝日の翌日・祝前日の規則)が `shadowed` にならず、両方が `redundant` と出ていた。0.30.1 の退行で、`RELEASING.md` の互換性の約束(診断の結果は増えるだけ)から外れていた。0.30.0 と同じく、後の規則を `shadowed`(`relatedPath` は前の規則)として出す。ID `"JP"` の提供元が種別 `"national"` の祝日を返す設定では、意味が一致しないので同じものとして比べない。和集合では今までどおり `redundant` で見つかる。パッチで出す根拠は `docs/decisions.md` の 55 番(この版で、パッチ版で入った退行も対象にした)
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- `docs/migration.md` の 0.30.0: 日本の提供元とほかの提供元を合わせた設定の `kinds` の `"regular"` が、0.30.0 から日本の国民の祝日にも当たることを「返す値」の注 2 に書いた(`"regular"` を検索する手順と、0.22.x と同じ結果にする書き方)。旧名を使っていない設定なので診断も `migrate…` も知らせず、0.30.0 の節の「移行」にも欠けていた。冒頭の検索の案内に、`withSubstituteDays` の呼び出しの `name:` を足した
|
|
51
|
+
- 0.30.1 の節の補足: 冒頭の「`.js` の挙動が変わるのは Fixed の 1 つだけ」は誤りだった。ほかに、`migrate…` が和集合で `"national"` を書き換えなくなったこと(Changed に記載。0.30.0 の約束に戻す修正なので、本来は Fixed)と、上の診断の退行も `.js` の挙動の変化だった
|
|
52
|
+
- ガイド(英日): 書き換えた設定を診断にかけ、`deprecated-option` が残っていないことを確かめる手順と例を足した(和集合の `"national"` は `migrate…` が書き換えない)。`shadowed` と `redundant` は規則を 1 つずつ外したときの判定で、複数の規則が出たら 1 つ外すたびに診断をやり直すことを足した
|
|
53
|
+
- 和集合の `"national"` の `deprecated-option` の長いメッセージを、作成時ではなく診断のときに組み立てるようにした。診断が返すメッセージは変わらない(作成時は警告を使わないので、ルートのバンドルから文を外した)
|
|
54
|
+
- README(英日)の版の固定の例を、具体的な版から `"x.y.z"` にした。minify + gzip のサイズを測り直した(ルート 13.0 → 12.9 KB、日本込み 14.7 → 14.6 KB、フランス込み・シンガポール込み 13.9 → 13.8 KB)
|
|
55
|
+
- ソースのコメントとテストで、`"national"` の扱いの根拠を 55 番としていたのを 54 番に直した
|
|
56
|
+
- `docs/decisions.md`: 54 番に 0.30.2 の追記(返す値の改名は「改名は結果を変えない」の例外であること、規則どうしの診断の項を実際の挙動に合わせた)を足し、55 番の対象を「直前の版(マイナー版・パッチ版)」に改め、56 番(同じ設定の結果を前の版と CI で比べる)を足した。旧名を本文に持つ 14・16・36・43・44 番に、0.30.0 の改名の追記を足した。`RELEASING.md`: パッチの区分を「直前の版」に改め、互換性の約束の診断の項に前の版の結果は新しい版でも返すことを、品質の確認に決定の文書の旧名と返す値の改名の確かめ方を足した
|
|
57
|
+
|
|
58
|
+
### 開発
|
|
59
|
+
|
|
60
|
+
- CI に `result-compare` ジョブを足した(`scripts/result-compare.ts`)。種で決まる設定の集まりと過去の退行を再現する固定の設定を、公開済みの前の版と今回の `dist` に渡し、カレンダー(直接・合成・スケジュールから)とスケジュールの結果を 1 日ずつ比べ、診断は前の版の結果がすべて含まれることを確かめる。意図した差分は `etc/result-changes.json` に特徴・版・出典を書いたものだけを許す。0.30.x の間は 0.22.2 とも旧名の設定で比べる。公開済みの版どうしで確かめると、0.22.2 → 0.30.0 で和集合の `"national"` の退行を、0.30.0 → 0.30.1 で上の診断の退行を検出する
|
|
61
|
+
- `scripts/check-names.ts`: 前の版を動かす `scripts/result-compare.ts` を、旧名の検査(C14)の対象から外した
|
|
62
|
+
- `test/national-union.test.ts` に、日本の提供元だけの設定の `shadowed` の確認を足した
|
|
63
|
+
- サイズ(gzip): ルート 18,054 → 17,997(測定 17,997)、`./jp` 20,288 → 20,226(測定 20,226)、`./diagnose` 24,492 → 24,753(測定 24,753)。上限は変えていない
|
|
64
|
+
|
|
7
65
|
## [0.30.1] - 2026-10-30
|
|
8
66
|
|
|
9
67
|
0.30.0 の改名の後始末の版です。新しい設定・関数・診断コードはありません。公開物の `.js` の挙動が変わるのは Fixed の 1 つだけです。
|
|
@@ -729,7 +787,9 @@
|
|
|
729
787
|
|
|
730
788
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
731
789
|
|
|
732
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.
|
|
790
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.3...HEAD
|
|
791
|
+
[0.30.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.2...v0.30.3
|
|
792
|
+
[0.30.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.1...v0.30.2
|
|
733
793
|
[0.30.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.0...v0.30.1
|
|
734
794
|
[0.30.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.2...v0.30.0
|
|
735
795
|
[0.22.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.1...v0.22.2
|
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<a href="https://www.npmjs.com/package/bizdays-toolkit"><img src="https://img.shields.io/npm/v/bizdays-toolkit" alt="npm version"></a>
|
|
10
|
-
<a href="https://www.npmjs.com/package/bizdays-toolkit"><img src="https://img.shields.io/npm/d18m/bizdays-toolkit" alt="npm downloads"></a>
|
|
11
10
|
<a href="https://github.com/inohan77/bizdays-toolkit/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/inohan77/bizdays-toolkit/ci.yml?branch=main&label=CI" alt="CI status"></a>
|
|
12
11
|
<a href="https://github.com/inohan77/bizdays-toolkit/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/bizdays-toolkit" alt="license"></a>
|
|
13
12
|
<img src="https://img.shields.io/node/v/bizdays-toolkit" alt="Node.js version">
|
|
@@ -24,7 +23,7 @@ A business-day calendar that combines public holidays with company or store clos
|
|
|
24
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
|
|
25
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
|
|
26
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
|
|
27
|
-
- **Lightweight, zero dependencies, time-zone safe**: about
|
|
26
|
+
- **Lightweight, zero dependencies, time-zone safe**: about 12.9 KB min+gzip (about 14.6 KB with Japanese holidays, about 15.1 KB with UK bank holidays, about 13.8 KB with French holidays, about 13.8 KB with Singapore holidays; measured for 0.30.2). 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
|
|
28
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
|
|
29
28
|
|
|
30
29
|
## Installation
|
|
@@ -132,7 +131,7 @@ A holiday provider is an object with `id`, `timeZone`, `supportedYears` and `hol
|
|
|
132
131
|
Versioning follows [Semantic Versioning](https://semver.org/). See [RELEASING.md](https://github.com/inohan77/bizdays-toolkit/blob/main/RELEASING.md) (Japanese) for details.
|
|
133
132
|
|
|
134
133
|
- Official data updates (new, moved and one-off holidays by law, Official Gazette or proclamation, fixed equinox days in Japan, newly published years on GOV.UK, changes to the French Labour Code, newly gazetted years and revised dates in Singapore) are released as **patch** versions, so they reach you with either `^` or `~`
|
|
135
|
-
- To freeze the holiday results, pin an exact version (for example `"bizdays-toolkit": "
|
|
134
|
+
- To freeze the holiday results, pin an exact version (for example `"bizdays-toolkit": "x.y.z"`)
|
|
136
135
|
- The reflected data is shown by the provider's `dataVersion` (for Japan, the year and month of the Official Gazette reflected; for the UK, France and Singapore, the year and month of the GOV.UK, data.gouv.fr or data.gov.sg data reflected) and `confirmedThrough` (`jp.dataVersion`, `england.confirmedThrough` and so on). The module-level constants `dataVersion` and `confirmedThrough` in `bizdays-toolkit/jp` and `bizdays-toolkit/uk` are deprecated since 0.12.0 and will be removed in 1.0.0
|
|
137
136
|
- Before 1.0.0, minor versions may contain breaking changes. What you need to change when moving between minor versions is listed in the [migration guide](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/migration.md) (Japanese) and in the "移行" (migration) part of each version in the CHANGELOG
|
|
138
137
|
- Decision reasons (`reason`), holiday kinds (`kind`), error codes and diagnostic codes may gain values in future versions. When you branch on their values, handle "anything else" too (see "互換性の約束", the compatibility promise, in [RELEASING.md](https://github.com/inohan77/bizdays-toolkit/blob/main/RELEASING.md))
|
package/dist/core/calendar.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 祝日と、会社・店舗の休業日を組み合わせた営業日カレンダー。
|
|
3
|
-
* 1 日の判定の優先順位は docs/guide.md の「Business-day calendars」と docs/decisions.md の
|
|
3
|
+
* 1 日の判定の優先順位は docs/guide.md の「Business-day calendars」と docs/decisions.md の 11 番。
|
|
4
4
|
*
|
|
5
5
|
* 内部では、営業日かどうか(真偽値)を返すスケジュール(createSchedule)として作っている。
|
|
6
6
|
* 営業日の探索・調整・月の営業日などの機能は buildCalendar に切り出し、作成済みのカレンダーを
|
package/dist/core/diagnose.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { type ScheduleOptions } from "./schedule.ts";
|
|
|
35
35
|
* - "warning": 作れるが、意図と違う可能性が高い
|
|
36
36
|
* - "info": 結果には影響しないが、整理できる
|
|
37
37
|
*
|
|
38
|
-
* 出力の列挙だが、重さの段階は増やさないため閉じた型にしている(docs/decisions.md の
|
|
38
|
+
* 出力の列挙だが、重さの段階は増やさないため閉じた型にしている(docs/decisions.md の 2 番)。
|
|
39
39
|
* @public
|
|
40
40
|
*/
|
|
41
41
|
export type DiagnosticSeverity = "error" | "warning" | "info";
|
package/dist/core/diagnose.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lengthOfMonth, fromDayNumber, isValidDate, parseDate, toDayNumber, } from "./date.js";
|
|
1
|
+
import { lengthOfMonth, fromDayNumber, isValidDate, parseDate, toDayNumber, weekdayOf, } from "./date.js";
|
|
2
2
|
import { compileCalendarOptions } from "./calendar.js";
|
|
3
3
|
import { IssueCollector, rangeError } from "./errors.js";
|
|
4
4
|
import { RENAMED_KEYS, RENAMED_VALUES } from "./renamed.js";
|
|
@@ -333,6 +333,24 @@ function analyze(c, compiled, isCalendar) {
|
|
|
333
333
|
return found;
|
|
334
334
|
};
|
|
335
335
|
const setCovers = (a, b) => a === null || (b !== null && [...b].every((v) => a.has(v)));
|
|
336
|
+
const renamedKind = RENAMED_VALUES.find((x) => x.key === "kinds");
|
|
337
|
+
let nationalAsRegular;
|
|
338
|
+
const kindsOf = (r) => {
|
|
339
|
+
if (!r.nationalOfJp || r.kinds === null)
|
|
340
|
+
return r.kinds;
|
|
341
|
+
if (nationalAsRegular === undefined) {
|
|
342
|
+
let found = false;
|
|
343
|
+
if (window && jpUsage(source) === "only") {
|
|
344
|
+
eachDay(window, (n) => (found = holidayOfSafe(fromDayNumber(n))?.kind === renamedKind.from));
|
|
345
|
+
nationalAsRegular = !found;
|
|
346
|
+
}
|
|
347
|
+
else
|
|
348
|
+
nationalAsRegular = false;
|
|
349
|
+
}
|
|
350
|
+
return nationalAsRegular
|
|
351
|
+
? new Set([...r.kinds].map((k) => (k === renamedKind.from ? renamedKind.to : k)))
|
|
352
|
+
: r.kinds;
|
|
353
|
+
};
|
|
336
354
|
const sameSkip = (a, b) => a.skipWeekdays === null
|
|
337
355
|
? b.skipWeekdays === null
|
|
338
356
|
: b.skipWeekdays !== null &&
|
|
@@ -394,14 +412,14 @@ function analyze(c, compiled, isCalendar) {
|
|
|
394
412
|
sameSkip(r, rule) &&
|
|
395
413
|
(rule.holiday
|
|
396
414
|
? r.holiday &&
|
|
397
|
-
setCovers(r
|
|
415
|
+
setCovers(kindsOf(r), kindsOf(rule)) &&
|
|
398
416
|
setCovers(r.keys, rule.keys) &&
|
|
399
417
|
setCovers(r.weekdays, rule.weekdays) &&
|
|
400
418
|
setCovers(r.months, rule.months)
|
|
401
419
|
: rule.dayAfterHoliday || rule.dayBeforeHoliday
|
|
402
420
|
? r.dayAfterHoliday === rule.dayAfterHoliday &&
|
|
403
421
|
r.dayBeforeHoliday === rule.dayBeforeHoliday &&
|
|
404
|
-
setCovers(r
|
|
422
|
+
setCovers(kindsOf(r), kindsOf(rule)) &&
|
|
405
423
|
setCovers(r.keys, rule.keys) &&
|
|
406
424
|
setCovers(r.weekdays, rule.weekdays) &&
|
|
407
425
|
setCovers(r.months, rule.months)
|
|
@@ -434,18 +452,76 @@ function analyze(c, compiled, isCalendar) {
|
|
|
434
452
|
"searching for a business day throws");
|
|
435
453
|
}
|
|
436
454
|
}
|
|
437
|
-
const
|
|
455
|
+
const counting = recurring.filter((r) => r.businessDays !== null && r.calendar === null);
|
|
456
|
+
const countsMonth = counting.some((r) => r.weekStart === null);
|
|
457
|
+
const weekStarts = [
|
|
458
|
+
...new Set(counting.flatMap((r) => (r.weekStart === null ? [] : [r.weekStart]))),
|
|
459
|
+
];
|
|
460
|
+
const countingUnits = (days) => {
|
|
461
|
+
const out = new Set();
|
|
462
|
+
for (const n of days) {
|
|
463
|
+
out.add(n);
|
|
464
|
+
if (countsMonth) {
|
|
465
|
+
const { year, month, day } = parseDate(fromDayNumber(n));
|
|
466
|
+
for (let k = 0; k < lengthOfMonth(year, month); k++)
|
|
467
|
+
out.add(n - day + 1 + k);
|
|
468
|
+
}
|
|
469
|
+
for (const start of weekStarts) {
|
|
470
|
+
const first = n - ((weekdayOf(fromDayNumber(n)) - start + 7) % 7);
|
|
471
|
+
for (let k = 0; k < 7; k++)
|
|
472
|
+
out.add(first + k);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return out;
|
|
476
|
+
};
|
|
477
|
+
const FAILED = Symbol("failed");
|
|
478
|
+
const originalOf = (resolve) => {
|
|
479
|
+
const values = new Map();
|
|
480
|
+
return (n) => {
|
|
481
|
+
if (!values.has(n)) {
|
|
482
|
+
let value;
|
|
483
|
+
try {
|
|
484
|
+
value = resolve(fromDayNumber(n)).day.value;
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
value = FAILED;
|
|
488
|
+
}
|
|
489
|
+
values.set(n, value);
|
|
490
|
+
}
|
|
491
|
+
return values.get(n);
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
const redundant = (rule, base, days, original) => {
|
|
438
495
|
const resolve = createResolver(without(base, rule, false), lookup);
|
|
439
|
-
|
|
496
|
+
for (const n of days) {
|
|
497
|
+
let value;
|
|
498
|
+
try {
|
|
499
|
+
value = resolve(fromDayNumber(n)).day.value;
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
value = FAILED;
|
|
503
|
+
}
|
|
504
|
+
const before = original(n);
|
|
505
|
+
if (value === FAILED || before === FAILED) {
|
|
506
|
+
if (value !== before)
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
else if (!sameValue(before, value))
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
return true;
|
|
440
513
|
};
|
|
441
514
|
const full = createResolver(compiled, lookup);
|
|
515
|
+
const originalFull = originalOf(full);
|
|
442
516
|
for (const rule of dates) {
|
|
443
517
|
if (unused.has(rule))
|
|
444
518
|
continue;
|
|
445
519
|
const decided = [];
|
|
520
|
+
const span = [];
|
|
446
521
|
let checked = 0;
|
|
447
522
|
const last = Math.min(rule.to, rule.from + MAX_DATE_RULE_DAYS - 1);
|
|
448
523
|
for (let n = rule.from; n <= last; n++) {
|
|
524
|
+
span.push(n);
|
|
449
525
|
let decidedBy;
|
|
450
526
|
try {
|
|
451
527
|
decidedBy = full(fromDayNumber(n)).rule;
|
|
@@ -457,7 +533,10 @@ function analyze(c, compiled, isCalendar) {
|
|
|
457
533
|
if (decidedBy === rule)
|
|
458
534
|
decided.push(n);
|
|
459
535
|
}
|
|
460
|
-
|
|
536
|
+
const ok = counting.length > 0
|
|
537
|
+
? redundant(rule, compiled, countingUnits(span), originalFull)
|
|
538
|
+
: redundant(rule, compiled, decided, () => rule.value);
|
|
539
|
+
if (checked > 0 && ok) {
|
|
461
540
|
c.info("redundant", rule.path, decided.length === 0
|
|
462
541
|
? "This rule is never used: earlier rules cover all of its days"
|
|
463
542
|
: "Removing this rule does not change any result");
|
|
@@ -468,17 +547,35 @@ function analyze(c, compiled, isCalendar) {
|
|
|
468
547
|
const candidates = [...annual, ...recurring].filter((r) => !unused.has(r));
|
|
469
548
|
if (candidates.length === 0)
|
|
470
549
|
return;
|
|
471
|
-
const base = without(compiled, null, true);
|
|
550
|
+
const base = counting.length > 0 ? compiled : without(compiled, null, true);
|
|
472
551
|
const resolveBase = createResolver(base, lookup);
|
|
552
|
+
const originalBase = originalOf(resolveBase);
|
|
473
553
|
const decided = new Map(candidates.map((r) => [r, []]));
|
|
474
554
|
eachDay(window, (n) => {
|
|
475
|
-
|
|
555
|
+
let rule;
|
|
556
|
+
try {
|
|
557
|
+
rule = resolveBase(fromDayNumber(n)).rule;
|
|
558
|
+
}
|
|
559
|
+
catch {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
476
562
|
if (rule)
|
|
477
563
|
decided.get(rule)?.push(n);
|
|
478
564
|
});
|
|
565
|
+
const annualUnits = (rule) => {
|
|
566
|
+
const matched = [];
|
|
567
|
+
eachDay(window, (n) => {
|
|
568
|
+
if (matchMonthDay(rule, fromDayNumber(n).slice(5)))
|
|
569
|
+
matched.push(n);
|
|
570
|
+
});
|
|
571
|
+
return countingUnits(matched);
|
|
572
|
+
};
|
|
479
573
|
for (const rule of candidates) {
|
|
480
574
|
const days = decided.get(rule);
|
|
481
|
-
|
|
575
|
+
const ok = counting.length > 0 && annual.includes(rule)
|
|
576
|
+
? redundant(rule, base, annualUnits(rule), originalBase)
|
|
577
|
+
: redundant(rule, base, days, () => rule.value);
|
|
578
|
+
if (!ok)
|
|
482
579
|
continue;
|
|
483
580
|
c.info("redundant", rule.path, days.length === 0
|
|
484
581
|
? `This rule is never used: other rules decide every day it matches (checked ${window.label})`
|
|
@@ -544,7 +641,11 @@ function run(c, compiled, isCalendar, asOf) {
|
|
|
544
641
|
c.error(code === "out-of-range" ? "out-of-range" : "invalid-provider-data", "holidayProvider", error instanceof Error ? error.message : String(error));
|
|
545
642
|
}
|
|
546
643
|
}
|
|
547
|
-
return Object.freeze(c.issues.map(({ unknownKey, knownKeys, ...issue }) => {
|
|
644
|
+
return Object.freeze(c.issues.map(({ unknownKey, knownKeys, nationalInUnion, ...issue }) => {
|
|
645
|
+
if (nationalInUnion) {
|
|
646
|
+
const { from, to } = RENAMED_VALUES.find((r) => r.key === "kinds");
|
|
647
|
+
issue.message += `; here it matches Japan's "${to}" and other providers' "${from}" holidays. From 1.0.0 it is an invalid-option with a "JP" provider: wrap the Japanese provider and rename your own "${from}" kind (see the migration guide)`;
|
|
648
|
+
}
|
|
548
649
|
const suggestion = unknownKey === undefined || knownKeys === undefined
|
|
549
650
|
? undefined
|
|
550
651
|
: closestKey(unknownKey, knownKeys);
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -74,6 +74,8 @@ export interface Issue {
|
|
|
74
74
|
/** unknown-option の知らないキーと既知のキー(診断で候補を挙げるため。結果には出さない) */
|
|
75
75
|
readonly unknownKey?: string;
|
|
76
76
|
readonly knownKeys?: readonly string[];
|
|
77
|
+
/** 和集合の設定の kinds の "national"(診断で、当てている祝日と 1.0.0 での扱いを添えるため。結果には出さない) */
|
|
78
|
+
readonly nationalInUnion?: true;
|
|
77
79
|
}
|
|
78
80
|
/** @internal 問題を集める */
|
|
79
81
|
export declare class IssueCollector {
|
package/dist/core/month.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare function monthOf(input: DateString | MonthString, offset?: number
|
|
|
50
50
|
export declare function closingMonth(date: DateString, closingDayOfMonth: number): MonthString;
|
|
51
51
|
/** @internal 締め日の検証(closingMonth・closingPeriod・営業日カレンダーの締め日で共用) */
|
|
52
52
|
export declare function checkClosingDay(closingDayOfMonth: number): void;
|
|
53
|
-
/** @internal その月の締め日(日)。-1 またはその月の日数以上なら末日(decisions.md の
|
|
53
|
+
/** @internal その月の締め日(日)。-1 またはその月の日数以上なら末日(decisions.md の 23 番の読み替えはここだけで行う) */
|
|
54
54
|
export declare function closingDayIn({ year, month }: YearMonth, closingDayOfMonth: number): number;
|
|
55
55
|
/**
|
|
56
56
|
* 締め日で区切ったときの、その月分の期間(両端を含む暦日)。closingMonth の逆算。
|
package/dist/core/renamed.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 0.30.0 で改名した設定のキーと値の表(docs/decisions.md の
|
|
2
|
+
* 0.30.0 で改名した設定のキーと値の表(docs/decisions.md の 10 番、docs/migration.md の 0.30.0)。
|
|
3
3
|
* 検証の入口での読み替え・診断の deprecated-option・migrate… 関数が、この表だけを使う。
|
|
4
4
|
*/
|
|
5
5
|
import { type IssueCollector } from "./errors.ts";
|
|
@@ -23,7 +23,7 @@ export interface RenamedValue {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* @internal 改名した値の表(0.30.0)。kinds の "national" は、ID が "JP" の祝日の提供元を使う設定でだけ扱いを変える。
|
|
26
|
-
* 作成と診断は値を読み替えずに知らせ(schedule.ts の reportNational)、migrate… は日本の提供元だけの設定で書き換える(docs/decisions.md の
|
|
26
|
+
* 作成と診断は値を読み替えずに知らせ(schedule.ts の reportNational)、migrate… は日本の提供元だけの設定で書き換える(docs/decisions.md の 10 番)
|
|
27
27
|
*/
|
|
28
28
|
export declare const RENAMED_VALUES: readonly RenamedValue[];
|
|
29
29
|
/** @internal 改名を見つけたときの扱い(作成・診断は記録して読み替える。合成などの記録先がない設定は読み替えるだけ) */
|
package/dist/core/schedule.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 日ごとに値を返すスケジュール(営業時間・受付枠など、曜日・祝日・特定日で変わるもの)。
|
|
3
|
-
* 1 日の値を決める優先順位は docs/guide.md の「Day-by-day values」と docs/decisions.md の
|
|
3
|
+
* 1 日の値を決める優先順位は docs/guide.md の「Day-by-day values」と docs/decisions.md の 11 番。
|
|
4
4
|
* 営業日カレンダー(createCalendar)は、このスケジュールの真偽値版として作られている。
|
|
5
5
|
*/
|
|
6
6
|
import { type DateString, type Weekday } from "./date.ts";
|
|
@@ -657,7 +657,7 @@ export interface RecurringRuleCompiled<Value> extends CompiledPeriod {
|
|
|
657
657
|
readonly holiday: boolean;
|
|
658
658
|
/** 祝日・祝日の翌日・祝前日の規則で絞る種別(null はすべての祝日) */
|
|
659
659
|
readonly kinds: ReadonlySet<string> | null;
|
|
660
|
-
/** kinds の旧名 "national" を、日本の提供元が返した "regular" の祝日にも当てるか(docs/decisions.md の
|
|
660
|
+
/** kinds の旧名 "national" を、日本の提供元が返した "regular" の祝日にも当てるか(docs/decisions.md の 10 番) */
|
|
661
661
|
readonly nationalOfJp: boolean;
|
|
662
662
|
/** 祝日・祝日の翌日・祝前日の規則で絞る識別子(null はすべての祝日) */
|
|
663
663
|
readonly keys: ReadonlySet<string> | null;
|
package/dist/core/schedule.js
CHANGED
|
@@ -673,10 +673,13 @@ function reportNational(c, path, kinds, mixed) {
|
|
|
673
673
|
if (v !== from)
|
|
674
674
|
return;
|
|
675
675
|
found = true;
|
|
676
|
-
c.
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
676
|
+
c.issues.push({
|
|
677
|
+
severity: "warning",
|
|
678
|
+
code: "deprecated-option",
|
|
679
|
+
path: `${path}[${i}]`,
|
|
680
|
+
message: `"${from}" was renamed to "${to}" in 0.30.0`,
|
|
681
|
+
...(mixed ? { nationalInUnion: true } : {}),
|
|
682
|
+
});
|
|
680
683
|
});
|
|
681
684
|
return found;
|
|
682
685
|
}
|
package/dist/uk/rules.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - 臨時の祝日・移動: 布告ごとの日付をテーブルで持つ
|
|
8
8
|
* - 識別子(key): 毎年の祝日に GOV.UK の区分名から 1 つ(KnownUkHolidayKey)。振替日は元の祝日の key、臨時の祝日は持たない
|
|
9
9
|
*
|
|
10
|
-
* 年ごとの正(GOV.UK・当時の政府の一覧・布告)と検証のフィクスチャは decisions.md の
|
|
10
|
+
* 年ごとの正(GOV.UK・当時の政府の一覧・布告)と検証のフィクスチャは decisions.md の 28 番。
|
|
11
11
|
* CONFIRMED_THROUGH より後の年は、規則による予測(confirmed: false)。
|
|
12
12
|
*/
|
|
13
13
|
import type { Holiday } from "../core/types.ts";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.3",
|
|
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",
|