bizdays-toolkit 0.30.0 → 0.30.2
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 +53 -1
- package/README.md +3 -3
- package/dist/core/calendar.d.ts +2 -14
- package/dist/core/calendar.js +3 -3
- package/dist/core/diagnose.js +40 -9
- package/dist/core/errors.d.ts +2 -0
- package/dist/core/migrate.js +5 -4
- package/dist/core/renamed.d.ts +2 -1
- package/dist/core/schedule.d.ts +29 -36
- package/dist/core/schedule.js +46 -17
- package/dist/core/types.d.ts +4 -1
- package/dist/fr/index.d.ts +2 -2
- package/dist/sg/index.d.ts +1 -1
- package/dist/uk/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,56 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.30.2] - 2026-10-30
|
|
8
|
+
|
|
9
|
+
0.30.0・0.30.1 の改名の後始末の続きの版です。新しい設定・関数・診断コードはありません。公開物の `.js` の挙動が変わるのは Fixed の 1 つ(診断の結果)で、カレンダー・スケジュールの判定の結果は変わりません。
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 診断: 日本の提供元だけの設定で、`"regular"` と旧名の `"national"` の同じ規則(祝日・祝日の翌日・祝前日の規則)が `shadowed` にならず、両方が `redundant` と出ていた。0.30.1 の退行で、`RELEASING.md` の互換性の約束(診断の結果は増えるだけ)から外れていた。0.30.0 と同じく、後の規則を `shadowed`(`relatedPath` は前の規則)として出す。ID `"JP"` の提供元が種別 `"national"` の祝日を返す設定では、意味が一致しないので同じものとして比べない。和集合では今までどおり `redundant` で見つかる。パッチで出す根拠は `docs/decisions.md` の 55 番(この版で、パッチ版で入った退行も対象にした)
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- `docs/migration.md` の 0.30.0: 日本の提供元とほかの提供元を合わせた設定の `kinds` の `"regular"` が、0.30.0 から日本の国民の祝日にも当たることを「返す値」の注 2 に書いた(`"regular"` を検索する手順と、0.22.x と同じ結果にする書き方)。旧名を使っていない設定なので診断も `migrate…` も知らせず、0.30.0 の節の「移行」にも欠けていた。冒頭の検索の案内に、`withSubstituteDays` の呼び出しの `name:` を足した
|
|
18
|
+
- 0.30.1 の節の補足: 冒頭の「`.js` の挙動が変わるのは Fixed の 1 つだけ」は誤りだった。ほかに、`migrate…` が和集合で `"national"` を書き換えなくなったこと(Changed に記載。0.30.0 の約束に戻す修正なので、本来は Fixed)と、上の診断の退行も `.js` の挙動の変化だった
|
|
19
|
+
- ガイド(英日): 書き換えた設定を診断にかけ、`deprecated-option` が残っていないことを確かめる手順と例を足した(和集合の `"national"` は `migrate…` が書き換えない)。`shadowed` と `redundant` は規則を 1 つずつ外したときの判定で、複数の規則が出たら 1 つ外すたびに診断をやり直すことを足した
|
|
20
|
+
- 和集合の `"national"` の `deprecated-option` の長いメッセージを、作成時ではなく診断のときに組み立てるようにした。診断が返すメッセージは変わらない(作成時は警告を使わないので、ルートのバンドルから文を外した)
|
|
21
|
+
- README(英日)の版の固定の例を、具体的な版から `"x.y.z"` にした。minify + gzip のサイズを測り直した(ルート 13.0 → 12.9 KB、日本込み 14.7 → 14.6 KB、フランス込み・シンガポール込み 13.9 → 13.8 KB)
|
|
22
|
+
- ソースのコメントとテストで、`"national"` の扱いの根拠を 55 番としていたのを 54 番に直した
|
|
23
|
+
- `docs/decisions.md`: 54 番に 0.30.2 の追記(返す値の改名は「改名は結果を変えない」の例外であること、規則どうしの診断の項を実際の挙動に合わせた)を足し、55 番の対象を「直前の版(マイナー版・パッチ版)」に改め、56 番(同じ設定の結果を前の版と CI で比べる)を足した。旧名を本文に持つ 14・16・36・43・44 番に、0.30.0 の改名の追記を足した。`RELEASING.md`: パッチの区分を「直前の版」に改め、互換性の約束の診断の項に前の版の結果は新しい版でも返すことを、品質の確認に決定の文書の旧名と返す値の改名の確かめ方を足した
|
|
24
|
+
|
|
25
|
+
### 開発
|
|
26
|
+
|
|
27
|
+
- 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 で上の診断の退行を検出する
|
|
28
|
+
- `scripts/check-names.ts`: 前の版を動かす `scripts/result-compare.ts` を、旧名の検査(C14)の対象から外した
|
|
29
|
+
- `test/national-union.test.ts` に、日本の提供元だけの設定の `shadowed` の確認を足した
|
|
30
|
+
- サイズ(gzip): ルート 18,054 → 17,997(測定 17,997)、`./jp` 20,288 → 20,226(測定 20,226)、`./diagnose` 24,492 → 24,753(測定 24,753)。上限は変えていない
|
|
31
|
+
|
|
32
|
+
## [0.30.1] - 2026-10-30
|
|
33
|
+
|
|
34
|
+
0.30.0 の改名の後始末の版です。新しい設定・関数・診断コードはありません。公開物の `.js` の挙動が変わるのは Fixed の 1 つだけです。
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- 日本の祝日の提供元とほかの提供元を合わせた設定(`holidayProvider: [jp, england]` など)で、旧名の `kinds: ["national"]` が、ほかの提供元の `"regular"` の祝日(英国の bank holidays など)にも当たっていた。0.30.0 の退行で、改名は結果を変えないという約束(`docs/decisions.md` の 54 番)から外れていた。0.22.x と同じく、「種別が `"national"` の祝日、または ID が `"JP"` の提供元が返した `"regular"` の祝日」に当てる。日本の提供元だけの設定の結果は変わらない。パッチで出す根拠は `docs/decisions.md` の 55 番。`id` を変えて包んだ日本の提供元は ID `"JP"` の提供元とみなさないので、`"national"` は 0.30.0 と同じく何にも当たらない(下の Changed の診断のメッセージが理由を示す。`docs/migration.md`)
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- 診断: 和集合の設定の `"national"` の `deprecated-option` のメッセージに、当てている祝日と、1.0.0 で ID `"JP"` の提供元を含む設定の `"national"` が `invalid-option` になることを添えた。ID `"JP"` の提供元がない設定で `"national"` の規則が何にも当たらないときは、`never-matches` のメッセージに改名の前の名前の可能性を添えた(`code` は変わらない)
|
|
43
|
+
- `migrateCalendarOptions`・`migrateScheduleOptions`: `kinds` の `"national"` は、祝日の提供元がすべて ID `"JP"` のときだけ書き換える。和集合では、新しい名前の `"regular"` がほかの提供元の祝日にも当たるので書き換えず、`changes` にも出さない(0.30.0 は和集合でも書き換えていた)
|
|
44
|
+
- ガイド(英日): 保存した設定の `"national"` を `migrate…` で書き換えるには、読み込み時に付ける提供元を入れてから呼ぶこと(提供元がなければ書き換えない)、週の第 n 営業日(`businessDayOfWeek`)も週が対応年の外にかかる日は `out-of-range` になることを足した。月の関数の引数名を `closingDayOfMonth`・`input` に直した
|
|
45
|
+
- `docs/migration.md`: 和集合での `"national"` の扱いと 1.0.0 以降の書き方(日本の提供元を包んで種別を付け替える)、`id` を変えて包んだ提供元の注、週の第 n 営業日と対応年の端、0.30.0 の引数の名前の表を足した。「旧名は取り消し線と診断が示す」を、`combineCalendars`・`createCalendarFromSchedule`・`dueDate`・`withSubstituteDays` の設定の旧名は示さないので検索すること、に直した
|
|
46
|
+
- 型定義の説明: `skipWeekdays` の説明が書けない項目(`WeekdayPattern.dayOfMonth`・`DayOfMonthPattern.weekday`)に付いていたのを正しい項目に移し、例の旧名 `day` を `dayOfMonth` に直した。`@example`・TSDoc の旧名(`holidays`・`recurring` など)を直し、`BusinessDayOfWeekPattern` に対応年の端の挙動を、`HolidayProvider.id` に ISO にない地域の ID(`"FR-AM"`)を書いた。`.js` は変わらない
|
|
47
|
+
- README の祝日の種別の説明を今の値に直した。README(英日)の minify + gzip のサイズを測り直した(ルート 12.7 → 13.0 KB、日本込み 14.4 → 14.7 KB、英国込み 14.8 → 15.1 KB、フランス込み・シンガポール込み 13.6 → 13.9 KB)。`docs/providers.md` のコード例のコメントに残っていた置き換えの取り残し("US federal holidayProvider:" → "US federal holidays:")を直した
|
|
48
|
+
- `docs/decisions.md`: 55 番(直前の版で入った退行の修正はパッチ)を足し、42・50・52・54 番に追記した。`RELEASING.md`: パッチの区分に退行の修正を足し、互換性の約束から型の名前の列挙をやめ、旧名(`outOfRange`)を直した。`src/core/schedule.ts`・`calendar.ts` の冒頭の判定の順番の写しを削り、ガイドと 12 番を指すようにした
|
|
49
|
+
|
|
50
|
+
### 開発
|
|
51
|
+
|
|
52
|
+
- `scripts/check-names.ts` に、形を分けるための `?: never` の項目に TSDoc が付いていないこと(C13)と、今の状態を書いた文書・スクリプト・型定義の TSDoc に 0.30.0 の旧名が残っていないこと(C14)の検査を足した(`etc/naming.md`)。0.30.0 に当てると、C13 は 2 か所、C14 はガイドの引数名・RELEASING.md・`check-readme-examples.ts` の補い・型定義の `@example` と `day:` を検出する
|
|
53
|
+
- `scripts/check-size.ts`: 上限を変えた版で、CHANGELOG の測定値(「(測定 N)」の形)を 1 つも照合できなければ失敗にし、照合した件数を出すようにした。0.30.0 の節は測定値をこの形で書いておらず、照合が 0 件のまま合格していた(記載の値は、測定の後の内部の関数名の変更で公開物と 6〜7 バイト違っていた)
|
|
54
|
+
- 和集合の `"national"` のテスト(`test/national-union.test.ts`)を足した。日本の提供元を包んだ設定との関係を対応年のすべてで確かめ、公開済みの 0.22.2 の結果(2020〜2027 年)を錨にする(`test/fixtures/national-union-0.22.2.json`)
|
|
55
|
+
- サイズ(gzip): ルート 17,646 → 18,054(測定 18,054)、`./jp` 19,890 → 20,288(測定 20,288)、`./diagnose` 23,919 → 24,492(測定 24,492)。和集合の `"national"` の判定とメッセージのため。上限は変えていない(ルート・`./jp`・`./diagnose` は上限の 97〜98%)
|
|
56
|
+
|
|
7
57
|
## [0.30.0] - 2026-10-27
|
|
8
58
|
|
|
9
59
|
公開する名前を 1 つの規則に合わせて改めた版です(`docs/decisions.md` の 54 番)。名前の整理の版を区切るため、版の番号を 0.30.0 にしました(0.23.0〜0.29.0 は欠番)。旧名は 1.0.0 まで受け付けます。作業は「移行」と `docs/migration.md` の 0.30.0 の節にあります。
|
|
@@ -704,7 +754,9 @@
|
|
|
704
754
|
|
|
705
755
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
706
756
|
|
|
707
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.
|
|
757
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.2...HEAD
|
|
758
|
+
[0.30.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.1...v0.30.2
|
|
759
|
+
[0.30.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.0...v0.30.1
|
|
708
760
|
[0.30.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.2...v0.30.0
|
|
709
761
|
[0.22.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.1...v0.22.2
|
|
710
762
|
[0.22.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.0...v0.22.1
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ A business-day calendar that combines public holidays with company or store clos
|
|
|
24
24
|
- **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
25
|
- **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
26
|
- **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 12.
|
|
27
|
+
- **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
28
|
- **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
29
|
|
|
30
30
|
## Installation
|
|
@@ -69,7 +69,7 @@ The [guide](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md)
|
|
|
69
69
|
| `metropole`, `alsaceMoselle` | `bizdays-toolkit/fr` | `Europe/Paris` | 2000–2099 | data.gouv.fr "Jours fériés en France" |
|
|
70
70
|
| `sg` | `bizdays-toolkit/sg` | `Asia/Singapore` | 2020–2027 | data.gov.sg (Ministry of Manpower) |
|
|
71
71
|
|
|
72
|
-
Each holiday carries its date, name (and English name), `kind` (
|
|
72
|
+
Each holiday carries its date, name (and English name), `kind` (such as `regular`, `substitute` and `special`; the values differ by country) and `confirmed` (whether the date is officially fixed; the Japanese equinox days and UK bank holidays after the last published year are predictions). Years after the supported range are an error unless `outOfRangePolicy: "ignore"` is set, and `unconfirmedHolidayPolicy: "throw"` stops any result that would depend on a predicted holiday. Details: [Bundled holiday providers](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#bundled-holiday-providers), [Unconfirmed holidays](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#unconfirmed-holidays).
|
|
73
73
|
|
|
74
74
|
### Business-day calendars and recurring rules
|
|
75
75
|
|
|
@@ -132,7 +132,7 @@ A holiday provider is an object with `id`, `timeZone`, `supportedYears` and `hol
|
|
|
132
132
|
Versioning follows [Semantic Versioning](https://semver.org/). See [RELEASING.md](https://github.com/inohan77/bizdays-toolkit/blob/main/RELEASING.md) (Japanese) for details.
|
|
133
133
|
|
|
134
134
|
- 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": "
|
|
135
|
+
- To freeze the holiday results, pin an exact version (for example `"bizdays-toolkit": "x.y.z"`)
|
|
136
136
|
- 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
137
|
- 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
138
|
- 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,18 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 祝日と、会社・店舗の休業日を組み合わせた営業日カレンダー。
|
|
3
|
-
*
|
|
4
|
-
* 1 日の判定は次の優先順位で行う(上が優先):
|
|
5
|
-
* 1. openDates … 臨時営業日(個別の日付・期間)
|
|
6
|
-
* 2. closedDates … 臨時休業日(個別の日付・期間)
|
|
7
|
-
* 3. closedAnnualDates … 毎年の休業日(月日・月日の期間。年をまたぐ期間も可)
|
|
8
|
-
* 4. openRecurringRules・closedRecurringRules(holidayOverlapPolicy: "over-holiday")… 祝日でも当てはめる繰り返しの規則
|
|
9
|
-
* 5. 祝日 … holidayPolicy に従う(closed: 休業 / open: 営業 / ignore: 判定に使わない)
|
|
10
|
-
* 6. openRecurringRules・closedRecurringRules("under-holiday"・"after-holiday" の振替先)… 繰り返しの規則
|
|
11
|
-
* 7. closedWeekdays … 定休日の曜日
|
|
12
|
-
* 8. それ以外は営業日
|
|
13
|
-
*
|
|
14
|
-
* 繰り返しの規則は openRecurringRules が closedRecurringRules より優先。"after-holiday" の規則は、
|
|
15
|
-
* 祝日には当てはめず、その日以降で最初の祝日でない日に当てはめる(振替)
|
|
3
|
+
* 1 日の判定の優先順位は docs/guide.md の「Business-day calendars」と docs/decisions.md の 12 番。
|
|
16
4
|
*
|
|
17
5
|
* 内部では、営業日かどうか(真偽値)を返すスケジュール(createSchedule)として作っている。
|
|
18
6
|
* 営業日の探索・調整・月の営業日などの機能は buildCalendar に切り出し、作成済みのカレンダーを
|
|
@@ -325,7 +313,7 @@ export interface CalendarFromScheduleOptions {
|
|
|
325
313
|
* (営業日カレンダーを別に書いて同期を取る必要がなくなる)。
|
|
326
314
|
*
|
|
327
315
|
* - isOpen は値だけで決まる純粋な関数であること(日付・時刻・外部の状態を見ない)。営業日の探索は isOpen を繰り返し呼ぶので、
|
|
328
|
-
* 結果が変わる関数を渡すと探索の結果が呼ぶたびに変わる。日付で変えたい条件は、スケジュールの規則(dates・
|
|
316
|
+
* 結果が変わる関数を渡すと探索の結果が呼ぶたびに変わる。日付で変えたい条件は、スケジュールの規則(dates・recurringRules)に書く
|
|
329
317
|
* - dayInfoOn の reason は、スケジュールの reason と営業・休業の組み合わせ(date → "open-date"/"closed-date"、annual → "open-annual"/
|
|
330
318
|
* "closed-annual"、recurring → "open-recurring"/"closed-recurring"、holiday → "holiday"、weekday → "open-weekday"/"closed-weekday")。
|
|
331
319
|
* name・holiday・shiftedFrom・optionPath はスケジュールの結果をそのまま引き継ぐ
|
package/dist/core/calendar.js
CHANGED
|
@@ -3,7 +3,7 @@ import { checkUnknownKeys, IssueCollector, plainError, rangeError } from "./erro
|
|
|
3
3
|
import { renameKeys, writtenKey } from "./renamed.js";
|
|
4
4
|
import { parseTimeOfDay, toCivil } from "./input.js";
|
|
5
5
|
import { checkClosingDay, closingDayIn, closingMonth as calendarClosingMonth, dayOfMonth, formatMonth, isDayOfMonthValue, parseMonth, shiftMonth, } from "./month.js";
|
|
6
|
-
import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, infoOfSchedule, isWeekday, mapDays, RECURRING_RULE_KEYS,
|
|
6
|
+
import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, infoOfSchedule, isWeekday, mapDays, RECURRING_RULE_KEYS, jpUsage, } from "./schedule.js";
|
|
7
7
|
const CALENDAR_OPTION_KEYS = [
|
|
8
8
|
"holidayProvider",
|
|
9
9
|
"timeZone",
|
|
@@ -54,8 +54,8 @@ export function compileCalendarOptions(c, options) {
|
|
|
54
54
|
const annual = compileAnnualRules(c, "closedAnnualDates", o["closedAnnualDates"], () => false, true);
|
|
55
55
|
const open = compileDateRules(c, "openDates", o["openDates"], () => true, true);
|
|
56
56
|
const closed = compileDateRules(c, "closedDates", o["closedDates"], () => false, true);
|
|
57
|
-
const openRecurringRules = compileRecurringRules(c, "openRecurringRules", o["openRecurringRules"], () => true, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "openRecurringRules"),
|
|
58
|
-
const closedRecurringRules = compileRecurringRules(c, "closedRecurringRules", o["closedRecurringRules"], () => false, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "closedRecurringRules"),
|
|
57
|
+
const openRecurringRules = compileRecurringRules(c, "openRecurringRules", o["openRecurringRules"], () => true, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "openRecurringRules"), jpUsage(source));
|
|
58
|
+
const closedRecurringRules = compileRecurringRules(c, "closedRecurringRules", o["closedRecurringRules"], () => false, RECURRING_RULE_KEYS, "calendar", writtenKey(places, written, "closedRecurringRules"), jpUsage(source));
|
|
59
59
|
return {
|
|
60
60
|
schedule: {
|
|
61
61
|
source,
|
package/dist/core/diagnose.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { lengthOfMonth, fromDayNumber, isValidDate, parseDate, toDayNumber, } from "./date.js";
|
|
2
2
|
import { compileCalendarOptions } from "./calendar.js";
|
|
3
3
|
import { IssueCollector, rangeError } from "./errors.js";
|
|
4
|
-
import { RENAMED_KEYS } from "./renamed.js";
|
|
5
|
-
import { compileScheduleOptions, createBasis, createHolidayLookup, createResolver, inPeriod, matchMonthDay, matchPattern, } from "./schedule.js";
|
|
4
|
+
import { RENAMED_KEYS, RENAMED_VALUES } from "./renamed.js";
|
|
5
|
+
import { compileScheduleOptions, createBasis, createHolidayLookup, createResolver, inPeriod, jpUsage, matchMonthDay, matchPattern, } from "./schedule.js";
|
|
6
6
|
function editDistance(a, b) {
|
|
7
7
|
const d = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
|
|
8
8
|
for (let i = 1; i <= a.length; i++) {
|
|
@@ -310,7 +310,9 @@ function analyze(c, compiled, isCalendar) {
|
|
|
310
310
|
if (source.providers.length === 0 || !window)
|
|
311
311
|
return false;
|
|
312
312
|
let found = false;
|
|
313
|
-
eachDay(window, (n) => (found =
|
|
313
|
+
eachDay(window, (n) => (found =
|
|
314
|
+
inPeriod(rule, n) &&
|
|
315
|
+
matchPattern(rule, fromDayNumber(n), holidayOfSafe, undefined, lookup.fromJp)));
|
|
314
316
|
return found;
|
|
315
317
|
};
|
|
316
318
|
const businessDayRuleMatches = (rule) => {
|
|
@@ -321,7 +323,7 @@ function analyze(c, compiled, isCalendar) {
|
|
|
321
323
|
if (!inPeriod(rule, n))
|
|
322
324
|
return false;
|
|
323
325
|
try {
|
|
324
|
-
found = matchPattern(rule, fromDayNumber(n), holidayOfSafe, basis);
|
|
326
|
+
found = matchPattern(rule, fromDayNumber(n), holidayOfSafe, basis, lookup.fromJp);
|
|
325
327
|
}
|
|
326
328
|
catch {
|
|
327
329
|
found = false;
|
|
@@ -331,6 +333,24 @@ function analyze(c, compiled, isCalendar) {
|
|
|
331
333
|
return found;
|
|
332
334
|
};
|
|
333
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
|
+
};
|
|
334
354
|
const sameSkip = (a, b) => a.skipWeekdays === null
|
|
335
355
|
? b.skipWeekdays === null
|
|
336
356
|
: b.skipWeekdays !== null &&
|
|
@@ -347,7 +367,11 @@ function analyze(c, compiled, isCalendar) {
|
|
|
347
367
|
: matchesAnyDay(rule, cycle);
|
|
348
368
|
if (!matches) {
|
|
349
369
|
unused.add(rule);
|
|
350
|
-
|
|
370
|
+
const national = holidayBased &&
|
|
371
|
+
source.providers.length > 0 &&
|
|
372
|
+
jpUsage(source) === "none" &&
|
|
373
|
+
rule.kinds?.has(RENAMED_VALUES.find((x) => x.key === "kinds").from) === true;
|
|
374
|
+
c.warning("never-matches", rule.path, (holidayBased
|
|
351
375
|
? source.providers.length === 0
|
|
352
376
|
? "This rule matches no day: there are no holidays without a holiday provider"
|
|
353
377
|
: rule.holiday
|
|
@@ -361,7 +385,10 @@ function analyze(c, compiled, isCalendar) {
|
|
|
361
385
|
: "This rule matches no day: no month has that many business days of the counting basis in the selected months within its effective period"
|
|
362
386
|
: rule.effectiveFrom === null && rule.effectiveTo === null
|
|
363
387
|
? "This rule matches no day (for example, a day that does not exist in the selected months)"
|
|
364
|
-
: "This rule matches no day within its effective period")
|
|
388
|
+
: "This rule matches no day within its effective period") +
|
|
389
|
+
(national
|
|
390
|
+
? '; "national" was renamed to "regular" in 0.30.0 and is not read so without a provider whose ID is "JP"'
|
|
391
|
+
: ""));
|
|
365
392
|
return;
|
|
366
393
|
}
|
|
367
394
|
if (businessDayBased &&
|
|
@@ -385,14 +412,14 @@ function analyze(c, compiled, isCalendar) {
|
|
|
385
412
|
sameSkip(r, rule) &&
|
|
386
413
|
(rule.holiday
|
|
387
414
|
? r.holiday &&
|
|
388
|
-
setCovers(r
|
|
415
|
+
setCovers(kindsOf(r), kindsOf(rule)) &&
|
|
389
416
|
setCovers(r.keys, rule.keys) &&
|
|
390
417
|
setCovers(r.weekdays, rule.weekdays) &&
|
|
391
418
|
setCovers(r.months, rule.months)
|
|
392
419
|
: rule.dayAfterHoliday || rule.dayBeforeHoliday
|
|
393
420
|
? r.dayAfterHoliday === rule.dayAfterHoliday &&
|
|
394
421
|
r.dayBeforeHoliday === rule.dayBeforeHoliday &&
|
|
395
|
-
setCovers(r
|
|
422
|
+
setCovers(kindsOf(r), kindsOf(rule)) &&
|
|
396
423
|
setCovers(r.keys, rule.keys) &&
|
|
397
424
|
setCovers(r.weekdays, rule.weekdays) &&
|
|
398
425
|
setCovers(r.months, rule.months)
|
|
@@ -535,7 +562,11 @@ function run(c, compiled, isCalendar, asOf) {
|
|
|
535
562
|
c.error(code === "out-of-range" ? "out-of-range" : "invalid-provider-data", "holidayProvider", error instanceof Error ? error.message : String(error));
|
|
536
563
|
}
|
|
537
564
|
}
|
|
538
|
-
return Object.freeze(c.issues.map(({ unknownKey, knownKeys, ...issue }) => {
|
|
565
|
+
return Object.freeze(c.issues.map(({ unknownKey, knownKeys, nationalInUnion, ...issue }) => {
|
|
566
|
+
if (nationalInUnion) {
|
|
567
|
+
const { from, to } = RENAMED_VALUES.find((r) => r.key === "kinds");
|
|
568
|
+
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)`;
|
|
569
|
+
}
|
|
539
570
|
const suggestion = unknownKey === undefined || knownKeys === undefined
|
|
540
571
|
? undefined
|
|
541
572
|
: 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/migrate.js
CHANGED
|
@@ -22,10 +22,11 @@ function clone(v) {
|
|
|
22
22
|
return out;
|
|
23
23
|
}
|
|
24
24
|
const join = (path, key) => (path ? `${path}.${key}` : key);
|
|
25
|
-
function
|
|
25
|
+
function onlyJp(options) {
|
|
26
26
|
const raw = options["holidayProvider"] ?? options["holidays"];
|
|
27
|
-
const list = Array.isArray(raw) ? raw : [raw];
|
|
28
|
-
return list.
|
|
27
|
+
const list = raw === undefined ? [] : Array.isArray(raw) ? raw : [raw];
|
|
28
|
+
return (list.length > 0 &&
|
|
29
|
+
list.every((p) => typeof p === "object" && p !== null && p.id === "JP"));
|
|
29
30
|
}
|
|
30
31
|
function renameObject(value, places, path, changes) {
|
|
31
32
|
const out = {};
|
|
@@ -61,7 +62,7 @@ function migrate(input, places, ruleLists, policyValueKey) {
|
|
|
61
62
|
throw typeError("invalid-argument", "options must be a plain object");
|
|
62
63
|
const changes = [];
|
|
63
64
|
const copied = clone(input);
|
|
64
|
-
const jp =
|
|
65
|
+
const jp = onlyJp(copied);
|
|
65
66
|
const written = new Map();
|
|
66
67
|
for (const key of Object.keys(copied)) {
|
|
67
68
|
const r = RENAMED_KEYS.find((x) => places.includes(x.place) && x.from === key);
|
package/dist/core/renamed.d.ts
CHANGED
|
@@ -22,7 +22,8 @@ export interface RenamedValue {
|
|
|
22
22
|
readonly to: string;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* @internal 改名した値の表(0.30.0)。kinds の "national" は、ID が "JP"
|
|
25
|
+
* @internal 改名した値の表(0.30.0)。kinds の "national" は、ID が "JP" の祝日の提供元を使う設定でだけ扱いを変える。
|
|
26
|
+
* 作成と診断は値を読み替えずに知らせ(schedule.ts の reportNational)、migrate… は日本の提供元だけの設定で書き換える(docs/decisions.md の 54 番)
|
|
26
27
|
*/
|
|
27
28
|
export declare const RENAMED_VALUES: readonly RenamedValue[];
|
|
28
29
|
/** @internal 改名を見つけたときの扱い(作成・診断は記録して読み替える。合成などの記録先がない設定は読み替えるだけ) */
|
package/dist/core/schedule.d.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 日ごとに値を返すスケジュール(営業時間・受付枠など、曜日・祝日・特定日で変わるもの)。
|
|
3
|
-
*
|
|
4
|
-
* 1 日の値は次の優先順位で決まる(上が優先):
|
|
5
|
-
* 1. dates … 個別の日付・期間(配列で先に書いたものが優先)
|
|
6
|
-
* 2. annual … 毎年の月日・月日の期間(年をまたぐ期間も可。配列で先に書いたものが優先)
|
|
7
|
-
* 3. recurring(holidayOverlapPolicy: "over-holiday")… 祝日でも当てはめる繰り返しの規則
|
|
8
|
-
* 4. 祝日 … holiday の規則("weekday": 曜日どおり / { sameAs: 曜日 }: その曜日の値 / { value }: 指定の値)
|
|
9
|
-
* 5. recurring("under-holiday"・"after-holiday" の振替先)… 繰り返しの規則(配列で先に書いたものが優先)
|
|
10
|
-
* 6. weekly … 曜日ごとの値
|
|
11
|
-
*
|
|
12
|
-
* "under-holiday" の規則は、祝日の扱いが "weekday"(曜日どおり)なら祝日にも当てはまる。
|
|
13
|
-
* "after-holiday" の規則は、祝日には当てはめず、その日以降で最初の祝日でない日に当てはめる(振替)。
|
|
14
|
-
* 毎年の月日・繰り返しの規則の有効期間(effectiveFrom・effectiveTo)の外では、その規則は書かれていないのと同じ。
|
|
15
|
-
* 祝日の翌日の規則(dayAfterHoliday)は、前日が祝日でその日自身は祝日でない日に当てはまる(提供元の祝日だけで判定)。
|
|
16
|
-
* 祝前日の規則(dayBeforeHoliday)は、翌日が祝日でその日自身は祝日でない日に当てはまる(同じく提供元の祝日だけ)。
|
|
17
|
-
* 祝日の規則(holiday: true。kinds で種別を、keys で個別の祝日を絞れる)は、「祝日の上」の段階で判定する
|
|
18
|
-
*
|
|
3
|
+
* 1 日の値を決める優先順位は docs/guide.md の「Day-by-day values」と docs/decisions.md の 12 番。
|
|
19
4
|
* 営業日カレンダー(createCalendar)は、このスケジュールの真偽値版として作られている。
|
|
20
5
|
*/
|
|
21
6
|
import { type DateString, type Weekday } from "./date.ts";
|
|
@@ -100,12 +85,6 @@ export interface WeekdayPattern {
|
|
|
100
85
|
readonly anchor?: DateString;
|
|
101
86
|
/** 当てはめる月(省略時はすべての月) */
|
|
102
87
|
readonly months?: readonly Month[];
|
|
103
|
-
/**
|
|
104
|
-
* holidayOverlapPolicy: "after-holiday" と組で、祝日に加えて飛ばす曜日(0 = 日曜日〜6 = 土曜日)。
|
|
105
|
-
* 本来の日が祝日かこの曜日なら、その日以降で最初の、祝日でもこの曜日でもない日に振り替える
|
|
106
|
-
* (例: 月曜定休で、月曜が祝日なら翌平日(土曜日には落とさない)は { weekday: 1, holidayOverlapPolicy: "after-holiday", skipWeekdays: [6] })。
|
|
107
|
-
* weekday 自身は含められない。"after-holiday" 以外と組にすると invalid-option
|
|
108
|
-
*/
|
|
109
88
|
readonly dayOfMonth?: never;
|
|
110
89
|
readonly businessDayOfMonth?: never;
|
|
111
90
|
readonly calendar?: never;
|
|
@@ -129,11 +108,6 @@ export interface DayOfMonthPattern {
|
|
|
129
108
|
readonly dayOfMonth: DayOfMonth | readonly DayOfMonth[];
|
|
130
109
|
/** 当てはめる月(省略時はすべての月) */
|
|
131
110
|
readonly months?: readonly Month[];
|
|
132
|
-
/**
|
|
133
|
-
* holidayOverlapPolicy: "after-holiday" と組で、祝日に加えて飛ばす曜日。本来の日が祝日かこの曜日なら、その日以降で最初の、
|
|
134
|
-
* 祝日でもこの曜日でもない日に振り替える(例: 「6 月 15 日は創立記念日。土日祝なら翌営業日」は
|
|
135
|
-
* { day: 15, months: [6], holidayOverlapPolicy: "after-holiday", skipWeekdays: [0, 6] })。"after-holiday" 以外と組にすると invalid-option
|
|
136
|
-
*/
|
|
137
111
|
readonly weekday?: never;
|
|
138
112
|
readonly nth?: never;
|
|
139
113
|
readonly interval?: never;
|
|
@@ -163,7 +137,7 @@ export interface DayOfMonthPattern {
|
|
|
163
137
|
* 祝日の段階が先に決めてこの規則は当てはまらない(曜日の規則と同じ優先順位)。「第 1 営業日は祝日でも休業」は "over-holiday" で書く。
|
|
164
138
|
* holidayPolicy: "closed" では祝日が基準の営業日にならないので "over-holiday" は結果を変えない(診断が info で知らせる)。
|
|
165
139
|
*
|
|
166
|
-
* スケジュール(createSchedule の
|
|
140
|
+
* スケジュール(createSchedule の recurringRules)では、スケジュール自身に営業・休業の概念がないので、数える基準にする作成済みの
|
|
167
141
|
* カレンダーを calendar で指定する(必須。タイムゾーンはスケジュールと同じであること)。カレンダー(closedRecurringRules・openRecurringRules)
|
|
168
142
|
* では calendar は指定できない(invalid-option。基準は自分の設定で決まる)。
|
|
169
143
|
* @public
|
|
@@ -199,6 +173,7 @@ export interface BusinessDayOfMonthPattern {
|
|
|
199
173
|
* その週にない回は当てはまらない。数える基準・calendar・holidayOverlapPolicy の扱いは businessDayOfMonth と同じ
|
|
200
174
|
* (カレンダーでは自分の設定の「繰り返しの規則をすべて除いた判定」、スケジュールでは必須の calendar で数える)。
|
|
201
175
|
* 週の始まりは地域・業種で違うので、weekStart は省略できない。months は当てはまる日の月で絞る。
|
|
176
|
+
* 週の 7 日をすべて数えるので、週の一部が祝日の提供元の対応年の外にかかる日は、outOfRangePolicy: "throw" では out-of-range になる。
|
|
202
177
|
* @public
|
|
203
178
|
*/
|
|
204
179
|
export interface BusinessDayOfWeekPattern {
|
|
@@ -336,7 +311,7 @@ export interface CyclePattern {
|
|
|
336
311
|
}
|
|
337
312
|
/**
|
|
338
313
|
* 祝日(提供元の祝日である日)。kinds で祝日の種別を、keys で個別の祝日を絞れる(省略時はすべての祝日)。
|
|
339
|
-
* 「祝日の上」の段階(holidayPolicy
|
|
314
|
+
* 「祝日の上」の段階(holidayPolicy より先)で判定し、祝日の既定の扱いの例外を書く
|
|
340
315
|
* (例: 「2027 年 4 月から祝日も営業」「振替休日は診療」「5 月の祝日は特別営業時間」)。
|
|
341
316
|
* 当てはまる日は祝日なので、holidayOverlapPolicy は指定できない(指定すると invalid-option)。
|
|
342
317
|
* @public
|
|
@@ -380,7 +355,11 @@ export interface HolidayPattern<Kind extends string = string> {
|
|
|
380
355
|
export type RecurringPattern<Kind extends string = string> = (WeekdayPattern & ({
|
|
381
356
|
/** 祝日に当たったら、その日以降で最初の祝日でない日に振り替える */
|
|
382
357
|
readonly holidayOverlapPolicy: "after-holiday";
|
|
383
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* 振替先を探すときに、祝日に加えて飛ばす曜日(0 = 日曜日〜6 = 土曜日)。本来の日が祝日かこの曜日なら、その日以降で最初の、
|
|
360
|
+
* 祝日でもこの曜日でもない日に振り替える(例: 月曜定休で、月曜が祝日なら翌平日(土曜日には落とさない)は
|
|
361
|
+
* { weekday: 1, holidayOverlapPolicy: "after-holiday", skipWeekdays: [6] })。weekday 自身は含められない
|
|
362
|
+
*/
|
|
384
363
|
readonly skipWeekdays?: readonly Weekday[];
|
|
385
364
|
} | {
|
|
386
365
|
/** 祝日に当たったときの扱い(既定: "under-holiday") */
|
|
@@ -389,7 +368,11 @@ export type RecurringPattern<Kind extends string = string> = (WeekdayPattern & (
|
|
|
389
368
|
})) | (DayOfMonthPattern & ({
|
|
390
369
|
/** 祝日に当たったら、その日以降で最初の祝日でない日に振り替える */
|
|
391
370
|
readonly holidayOverlapPolicy: "after-holiday";
|
|
392
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* 振替先を探すときに、祝日に加えて飛ばす曜日(0 = 日曜日〜6 = 土曜日)。本来の日が祝日かこの曜日なら、その日以降で最初の、
|
|
373
|
+
* 祝日でもこの曜日でもない日に振り替える(例: 「6 月 15 日は創立記念日。土日祝なら翌営業日」は
|
|
374
|
+
* { dayOfMonth: 15, months: [6], holidayOverlapPolicy: "after-holiday", skipWeekdays: [0, 6] })
|
|
375
|
+
*/
|
|
393
376
|
readonly skipWeekdays?: readonly Weekday[];
|
|
394
377
|
} | {
|
|
395
378
|
/** 祝日に当たったときの扱い(既定: "under-holiday") */
|
|
@@ -674,6 +657,8 @@ export interface RecurringRuleCompiled<Value> extends CompiledPeriod {
|
|
|
674
657
|
readonly holiday: boolean;
|
|
675
658
|
/** 祝日・祝日の翌日・祝前日の規則で絞る種別(null はすべての祝日) */
|
|
676
659
|
readonly kinds: ReadonlySet<string> | null;
|
|
660
|
+
/** kinds の旧名 "national" を、日本の提供元が返した "regular" の祝日にも当てるか(docs/decisions.md の 54 番) */
|
|
661
|
+
readonly nationalOfJp: boolean;
|
|
677
662
|
/** 祝日・祝日の翌日・祝前日の規則で絞る識別子(null はすべての祝日) */
|
|
678
663
|
readonly keys: ReadonlySet<string> | null;
|
|
679
664
|
/** 祝日・祝日の翌日・祝前日の規則で絞る曜日(null はすべての曜日) */
|
|
@@ -692,18 +677,20 @@ export type BasisOfMonth = (year: number, month: number) => readonly number[];
|
|
|
692
677
|
/** @internal カレンダーの判定関数から、月ごとに結果をキャッシュする基準を作る */
|
|
693
678
|
export declare function basisFromPredicate(isOpen: (date: DateString) => boolean): BasisOfMonth;
|
|
694
679
|
/** @internal 繰り返しの規則を検証して取り込む */
|
|
695
|
-
export declare function compileRecurringRules<Value>(c: IssueCollector, path: string, entries: unknown, valueOf: (entry: Record<string, unknown>, path: string) => Value | undefined, keys: readonly string[], context: "calendar" | "schedule", writtenPath?: string, jp?:
|
|
680
|
+
export declare function compileRecurringRules<Value>(c: IssueCollector, path: string, entries: unknown, valueOf: (entry: Record<string, unknown>, path: string) => Value | undefined, keys: readonly string[], context: "calendar" | "schedule", writtenPath?: string, jp?: JpUsage): RecurringRuleCompiled<Value>[];
|
|
696
681
|
/** @internal その日の祝日を返す関数(祝日・祝日の翌日・祝前日の規則の判定に使う。提供元の対応年の外は祝日でないとみなすこと) */
|
|
697
682
|
export type HolidayOf = (date: DateString) => Holiday<string> | undefined;
|
|
683
|
+
/** @internal その日の祝日(HolidayOf が返したもの)が、ID が "JP" の提供元のものか */
|
|
684
|
+
export type FromJp = (date: DateString) => boolean;
|
|
698
685
|
/**
|
|
699
686
|
* @internal 繰り返しの規則の形(曜日・第 n 回目・周期・日・第 n 営業日・祝日・祝日の翌日・祝前日・月)がその日に当てはまるか。
|
|
700
687
|
* 有効期間は考えない(規則の診断で、形どうしの包含を調べるために分けている)。
|
|
701
688
|
* 祝日に従属する規則は holidayOf で判定し、holidayOf を渡さなければ当てはまらない。
|
|
702
689
|
* 第 n 営業日の規則は、規則自身の基準(スケジュールの calendar)か basis で数え、どちらもなければ当てはまらない
|
|
703
690
|
*/
|
|
704
|
-
export declare function matchPattern(rule: RecurringRuleCompiled<unknown>, date: DateString, holidayOf?: HolidayOf, basis?: BasisOfMonth): boolean;
|
|
691
|
+
export declare function matchPattern(rule: RecurringRuleCompiled<unknown>, date: DateString, holidayOf?: HolidayOf, basis?: BasisOfMonth, fromJp?: FromJp): boolean;
|
|
705
692
|
/** @internal 繰り返しの規則がその日に当てはまるか(有効期間を含む) */
|
|
706
|
-
export declare function matchRecurring(rule: RecurringRuleCompiled<unknown>, date: DateString, holidayOf: HolidayOf, basis?: BasisOfMonth): boolean;
|
|
693
|
+
export declare function matchRecurring(rule: RecurringRuleCompiled<unknown>, date: DateString, holidayOf: HolidayOf, basis?: BasisOfMonth, fromJp?: FromJp): boolean;
|
|
707
694
|
/**
|
|
708
695
|
* @internal 第 n 営業日の規則が自分の設定を基準にする場合の基準を作る(繰り返しの規則をすべて除いた判定で営業日か)。
|
|
709
696
|
* 基準が要らない設定(第 n 営業日の規則がない、またはすべて calendar を持つ)では undefined
|
|
@@ -716,13 +703,19 @@ export interface HolidaySource<Kind extends string> {
|
|
|
716
703
|
readonly outOfRangePolicy: "throw" | "ignore";
|
|
717
704
|
readonly unconfirmedHolidayPolicy: "accept" | "throw";
|
|
718
705
|
}
|
|
719
|
-
/**
|
|
720
|
-
|
|
706
|
+
/**
|
|
707
|
+
* @internal 日本の祝日の提供元(ID が "JP"。包んだものを含む)の使い方(kinds の旧名 "national" の扱いを決めるため)。
|
|
708
|
+
* "mixed" はほかの ID の提供元と合わせて使う設定
|
|
709
|
+
*/
|
|
710
|
+
export type JpUsage = "none" | "only" | "mixed";
|
|
711
|
+
/** @internal 設定の祝日の提供元の、日本の提供元の使い方 */
|
|
712
|
+
export declare function jpUsage(source: HolidaySource<string>): JpUsage;
|
|
721
713
|
/** @internal 祝日の提供元とタイムゾーンの設定を検証する */
|
|
722
714
|
export declare function compileHolidaySource<Kind extends string>(c: IssueCollector, options: Record<string, unknown>): HolidaySource<Kind>;
|
|
723
715
|
/** @internal 祝日を調べる機能を作る(設定は検証済みであること) */
|
|
724
716
|
export declare function createHolidayLookup<Kind extends string>(source: HolidaySource<Kind>): HolidayLookup<Kind> & {
|
|
725
717
|
holidayOfDate(date: DateString): Holiday<Kind> | undefined;
|
|
718
|
+
fromJp: FromJp;
|
|
726
719
|
};
|
|
727
720
|
/** @internal 検証済みのスケジュールの規則 */
|
|
728
721
|
export interface CompiledSchedule<Value, Kind extends string> {
|
package/dist/core/schedule.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addDays, lengthOfMonth, formatDate, fromDayNumber, isValidDate, parseDate, toDayNumber, weekdayOf, } from "./date.js";
|
|
2
2
|
import { checkUnknownKeys, IssueCollector, rangeError } from "./errors.js";
|
|
3
|
-
import { renameKeys, renameValue, writtenKey } from "./renamed.js";
|
|
3
|
+
import { RENAMED_VALUES, renameKeys, renameValue, writtenKey } from "./renamed.js";
|
|
4
4
|
import { instantToCivil, toCivil, toDateTimeParts, toInstant, validateTimeZone, } from "./input.js";
|
|
5
5
|
import { HOLIDAY_KEY_PATTERN } from "./types.js";
|
|
6
6
|
const MONTH_DAY_RE = /^(\d{2})-(\d{2})$/;
|
|
@@ -182,7 +182,7 @@ function checkSet(c, path, raw, valid, expected) {
|
|
|
182
182
|
}
|
|
183
183
|
return new Set(list);
|
|
184
184
|
}
|
|
185
|
-
export function compileRecurringRules(c, path, entries, valueOf, keys, context, writtenPath = path, jp =
|
|
185
|
+
export function compileRecurringRules(c, path, entries, valueOf, keys, context, writtenPath = path, jp = "none") {
|
|
186
186
|
if (entries === undefined)
|
|
187
187
|
return [];
|
|
188
188
|
if (!Array.isArray(entries)) {
|
|
@@ -198,8 +198,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
|
|
|
198
198
|
}
|
|
199
199
|
const written = `${writtenPath}[${i}]`;
|
|
200
200
|
const entry = renameKeys(c, ["rule"], written, rawEntry);
|
|
201
|
-
|
|
202
|
-
entry["kinds"] = renameValue(c, "rule", "kinds", `${written}.kinds`, entry["kinds"]);
|
|
201
|
+
const nationalOfJp = jp !== "none" && reportNational(c, `${written}.kinds`, entry["kinds"], jp === "mixed");
|
|
203
202
|
checkUnknownKeys(c, p, entry, keys);
|
|
204
203
|
const value = valueOf(entry, p);
|
|
205
204
|
const name = checkName(c, p, entry["name"]);
|
|
@@ -528,6 +527,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
|
|
|
528
527
|
dayBeforeHoliday: hasBefore,
|
|
529
528
|
holiday: hasHoliday,
|
|
530
529
|
kinds,
|
|
530
|
+
nationalOfJp,
|
|
531
531
|
keys: holidayKeys,
|
|
532
532
|
weekdays,
|
|
533
533
|
months,
|
|
@@ -540,7 +540,7 @@ export function compileRecurringRules(c, path, entries, valueOf, keys, context,
|
|
|
540
540
|
});
|
|
541
541
|
return rules;
|
|
542
542
|
}
|
|
543
|
-
export function matchPattern(rule, date, holidayOf, basis) {
|
|
543
|
+
export function matchPattern(rule, date, holidayOf, basis, fromJp) {
|
|
544
544
|
const { year, month, day } = parseDate(date);
|
|
545
545
|
if (rule.months && !rule.months.has(month))
|
|
546
546
|
return false;
|
|
@@ -573,7 +573,9 @@ export function matchPattern(rule, date, holidayOf, basis) {
|
|
|
573
573
|
return false;
|
|
574
574
|
if (rule.weekdays && !rule.weekdays.has(weekdayOf(date)))
|
|
575
575
|
return false;
|
|
576
|
-
const selected = (h) => (rule.kinds === null ||
|
|
576
|
+
const selected = (h) => (rule.kinds === null ||
|
|
577
|
+
rule.kinds.has(h.kind) ||
|
|
578
|
+
(rule.nationalOfJp && h.kind === "regular" && fromJp?.(h.date) === true)) &&
|
|
577
579
|
(rule.keys === null || (h.key !== undefined && rule.keys.has(h.key)));
|
|
578
580
|
if (rule.holiday) {
|
|
579
581
|
const h = holidayOf(date);
|
|
@@ -609,8 +611,8 @@ export function matchPattern(rule, date, holidayOf, basis) {
|
|
|
609
611
|
}
|
|
610
612
|
return rule.days.has(day) || (rule.days.has(-1) && day === dim);
|
|
611
613
|
}
|
|
612
|
-
export function matchRecurring(rule, date, holidayOf, basis) {
|
|
613
|
-
return inPeriod(rule, toDayNumber(date)) && matchPattern(rule, date, holidayOf, basis);
|
|
614
|
+
export function matchRecurring(rule, date, holidayOf, basis, fromJp) {
|
|
615
|
+
return inPeriod(rule, toDayNumber(date)) && matchPattern(rule, date, holidayOf, basis, fromJp);
|
|
614
616
|
}
|
|
615
617
|
export function createBasis(compiled, lookup) {
|
|
616
618
|
if (!compiled.recurring.some((r) => r.businessDays !== null && r.basis === null))
|
|
@@ -662,8 +664,28 @@ function validateProvider(c, path, p) {
|
|
|
662
664
|
return bad('"holidaysInYear" must be a function');
|
|
663
665
|
return true;
|
|
664
666
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
+
function reportNational(c, path, kinds, mixed) {
|
|
668
|
+
if (!Array.isArray(kinds))
|
|
669
|
+
return false;
|
|
670
|
+
const { from, to } = RENAMED_VALUES.find((r) => r.key === "kinds");
|
|
671
|
+
let found = false;
|
|
672
|
+
kinds.forEach((v, i) => {
|
|
673
|
+
if (v !== from)
|
|
674
|
+
return;
|
|
675
|
+
found = true;
|
|
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
|
+
});
|
|
683
|
+
});
|
|
684
|
+
return found;
|
|
685
|
+
}
|
|
686
|
+
export function jpUsage(source) {
|
|
687
|
+
const jp = source.providers.filter((p) => p.id === "JP").length;
|
|
688
|
+
return jp === 0 ? "none" : jp === source.providers.length ? "only" : "mixed";
|
|
667
689
|
}
|
|
668
690
|
export function compileHolidaySource(c, options) {
|
|
669
691
|
const raw = options["holidayProvider"];
|
|
@@ -776,10 +798,12 @@ function checkNames(names) {
|
|
|
776
798
|
export function createHolidayLookup(source) {
|
|
777
799
|
const { providers, timeZone, outOfRangePolicy, unconfirmedHolidayPolicy } = source;
|
|
778
800
|
const yearCache = new Map();
|
|
801
|
+
const jpCache = new Map();
|
|
779
802
|
function holidayMap(year) {
|
|
780
803
|
let map = yearCache.get(year);
|
|
781
804
|
if (!map) {
|
|
782
805
|
map = new Map();
|
|
806
|
+
const jpDates = new Set();
|
|
783
807
|
for (const provider of providers) {
|
|
784
808
|
const { from, to } = provider.supportedYears;
|
|
785
809
|
if (year < from || year > to) {
|
|
@@ -788,11 +812,15 @@ export function createHolidayLookup(source) {
|
|
|
788
812
|
throw rangeError("out-of-range", `Holidays for ${provider.id} are supported for ${from}-${to}; requested ${year}`);
|
|
789
813
|
}
|
|
790
814
|
for (const h of loadProviderYear(provider, year)) {
|
|
791
|
-
if (
|
|
792
|
-
|
|
815
|
+
if (map.has(h.date))
|
|
816
|
+
continue;
|
|
817
|
+
map.set(h.date, h);
|
|
818
|
+
if (provider.id === "JP")
|
|
819
|
+
jpDates.add(h.date);
|
|
793
820
|
}
|
|
794
821
|
}
|
|
795
822
|
yearCache.set(year, map);
|
|
823
|
+
jpCache.set(year, jpDates);
|
|
796
824
|
}
|
|
797
825
|
return map;
|
|
798
826
|
}
|
|
@@ -826,6 +854,7 @@ export function createHolidayLookup(source) {
|
|
|
826
854
|
outOfRange: outOfRangePolicy,
|
|
827
855
|
unconfirmedHolidays: unconfirmedHolidayPolicy,
|
|
828
856
|
holidayOfDate,
|
|
857
|
+
fromJp: (date) => jpCache.get(parseDate(date).year)?.has(date) === true,
|
|
829
858
|
dateOf,
|
|
830
859
|
civilOf: ((input) => toDateTimeParts(input, timeZone)),
|
|
831
860
|
instantOf: (date, time) => toInstant(date, time, timeZone),
|
|
@@ -921,7 +950,7 @@ export function compileScheduleOptions(c, options) {
|
|
|
921
950
|
}
|
|
922
951
|
const annual = compileAnnualRules(c, "annualDates", o["annualDates"], requiredValue(c), false);
|
|
923
952
|
const dates = compileDateRules(c, "dates", o["dates"], requiredValue(c), false);
|
|
924
|
-
const recurring = compileRecurringRules(c, "recurringRules", o["recurringRules"], requiredValue(c), [...RECURRING_RULE_KEYS, "value"], "schedule", writtenKey(["source", "schedule"], written, "recurringRules"),
|
|
953
|
+
const recurring = compileRecurringRules(c, "recurringRules", o["recurringRules"], requiredValue(c), [...RECURRING_RULE_KEYS, "value"], "schedule", writtenKey(["source", "schedule"], written, "recurringRules"), jpUsage(source));
|
|
925
954
|
for (const rule of recurring) {
|
|
926
955
|
if (rule.businessDays === null)
|
|
927
956
|
continue;
|
|
@@ -953,7 +982,7 @@ export function createResolver(compiled, lookup) {
|
|
|
953
982
|
const prev = addDays(date, -k);
|
|
954
983
|
if (!isHolidayOfNeighbour(prev) && !rule.skipWeekdays?.has(weekdayOf(prev)))
|
|
955
984
|
return undefined;
|
|
956
|
-
if (matchRecurring(rule, prev, holidayOfNeighbour))
|
|
985
|
+
if (matchRecurring(rule, prev, holidayOfNeighbour, undefined, lookup.fromJp))
|
|
957
986
|
return prev;
|
|
958
987
|
}
|
|
959
988
|
return undefined;
|
|
@@ -987,7 +1016,7 @@ export function createResolver(compiled, lookup) {
|
|
|
987
1016
|
return make(byAnnual.value, "annual", byAnnual, byAnnual.name);
|
|
988
1017
|
if (holiday) {
|
|
989
1018
|
const over = recurring.find((r) => r.holidayOverlapPolicy === "over-holiday" &&
|
|
990
|
-
matchRecurring(r, date, holidayOfNeighbour, basis));
|
|
1019
|
+
matchRecurring(r, date, holidayOfNeighbour, basis, lookup.fromJp));
|
|
991
1020
|
if (over)
|
|
992
1021
|
return make(over.value, "recurring", over, over.name);
|
|
993
1022
|
if (holidayRule !== "ignore") {
|
|
@@ -995,7 +1024,7 @@ export function createResolver(compiled, lookup) {
|
|
|
995
1024
|
return make(value, "holiday", null, holiday.name);
|
|
996
1025
|
}
|
|
997
1026
|
const under = recurring.find((r) => r.holidayOverlapPolicy === "under-holiday" &&
|
|
998
|
-
matchRecurring(r, date, holidayOfNeighbour, basis));
|
|
1027
|
+
matchRecurring(r, date, holidayOfNeighbour, basis, lookup.fromJp));
|
|
999
1028
|
if (under)
|
|
1000
1029
|
return make(under.value, "recurring", under, under.name);
|
|
1001
1030
|
return make(weekly[weekday], "weekday", null, undefined);
|
|
@@ -1003,7 +1032,7 @@ export function createResolver(compiled, lookup) {
|
|
|
1003
1032
|
for (const rule of recurring) {
|
|
1004
1033
|
if (rule.skipWeekdays?.has(weekday))
|
|
1005
1034
|
continue;
|
|
1006
|
-
if (matchRecurring(rule, date, holidayOfNeighbour, basis))
|
|
1035
|
+
if (matchRecurring(rule, date, holidayOfNeighbour, basis, lookup.fromJp))
|
|
1007
1036
|
return make(rule.value, "recurring", rule, rule.name);
|
|
1008
1037
|
if (hasShift && rule.holidayOverlapPolicy === "after-holiday") {
|
|
1009
1038
|
const origin = shiftedOrigin(rule, date);
|
package/dist/core/types.d.ts
CHANGED
|
@@ -45,7 +45,10 @@ export interface Holiday<Kind extends string = string> {
|
|
|
45
45
|
* @public
|
|
46
46
|
*/
|
|
47
47
|
export interface HolidayProvider<Kind extends string = string> {
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* ISO 3166-1 alpha-2(国)・ISO 3166-2(地域)のコード、または該当するコードがない地域ではその形に合わせた独自のコード
|
|
50
|
+
* (大文字で書く)。例: "JP", "US-CA", "FR-AM"
|
|
51
|
+
*/
|
|
49
52
|
readonly id: string;
|
|
50
53
|
/** 祝日を判定する基準のタイムゾーン(IANA 名)。例: "Asia/Tokyo" */
|
|
51
54
|
readonly timeZone: string;
|
package/dist/fr/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* @example
|
|
8
8
|
* import { createCalendar } from "bizdays-toolkit";
|
|
9
9
|
* import { metropole } from "bizdays-toolkit/fr";
|
|
10
|
-
* const paris = createCalendar({
|
|
10
|
+
* const paris = createCalendar({ holidayProvider: metropole, closedWeekdays: [0, 6] });
|
|
11
11
|
*
|
|
12
12
|
* @example Lundi de Pentecôte を「連帯の日」として出勤日にする企業(法律上は祝日のまま。既定の扱いの例外として書く)
|
|
13
|
-
* createCalendar({
|
|
13
|
+
* createCalendar({ holidayProvider: metropole, closedWeekdays: [0, 6],
|
|
14
14
|
* openRecurringRules: [{ holiday: true, keys: ["pentecost-monday"], name: "Journée de solidarité" }] });
|
|
15
15
|
*/
|
|
16
16
|
import type { Holiday, HolidayProvider } from "../core/types.ts";
|
package/dist/sg/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @example
|
|
5
5
|
* import { createCalendar } from "bizdays-toolkit";
|
|
6
6
|
* import { sg } from "bizdays-toolkit/sg";
|
|
7
|
-
* const calendar = createCalendar({
|
|
7
|
+
* const calendar = createCalendar({ holidayProvider: sg, closedWeekdays: [0, 6] });
|
|
8
8
|
*/
|
|
9
9
|
import type { Holiday, HolidayProvider } from "../core/types.ts";
|
|
10
10
|
import { type SgHolidayKind } from "./rules.ts";
|
package/dist/uk/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @example
|
|
8
8
|
* import { createCalendar } from "bizdays-toolkit";
|
|
9
9
|
* import { scotland } from "bizdays-toolkit/uk";
|
|
10
|
-
* const calendar = createCalendar({
|
|
10
|
+
* const calendar = createCalendar({ holidayProvider: scotland, closedWeekdays: [0, 6] });
|
|
11
11
|
*/
|
|
12
12
|
import type { Holiday, HolidayProvider } from "../core/types.ts";
|
|
13
13
|
import { type UkHolidayKind } from "./rules.ts";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.2",
|
|
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",
|