bizdays-toolkit 0.22.2 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,50 @@
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.30.0] - 2026-10-27
8
+
9
+ 公開する名前を 1 つの規則に合わせて改めた版です(`docs/decisions.md` の 54 番)。名前の整理の版を区切るため、版の番号を 0.30.0 にしました(0.23.0〜0.29.0 は欠番)。旧名は 1.0.0 まで受け付けます。作業は「移行」と `docs/migration.md` の 0.30.0 の節にあります。
10
+
11
+ ### Added
12
+
13
+ - 週の第 n 営業日の規則 `{ businessDayOfWeek, weekStart }`(繰り返しの規則。数え方・`calendar`・`holidayOverlapPolicy` は `businessDayOfMonth` と同じ)と、型 `BusinessDayOfWeek`・`BusinessDayOfWeekPattern`
14
+ - `migrateCalendarOptions`・`migrateScheduleOptions`(`bizdays-toolkit/diagnose`): 保存した設定の旧名のキーと値を新しい名前に書き換え、書き換えたもの(`OptionChange`)を元の位置で返す。型 `OptionsMigration`・`OptionChange`
15
+ - 診断コード `deprecated-option`(0.30.0 で改名した旧名を、書いた位置で知らせる warning。1.0.0 で削除する)
16
+ - `CalendarFromScheduleOptions`(`createCalendarFromSchedule` の第 3 引数の型に名前を付けた)
17
+
18
+ ### Changed
19
+
20
+ - 公開する名前を、規則 N1〜N9(`etc/naming.md`)に合わせて改めた。設定のキー 18 個・値 2 つ、関数・メソッド 6 つ、型 17 個、返す項目 4 つ、型引数(`T` → `Value`)、引数(`addDays` の `n`、`isValidDate` の `input`、`closingMonth`・`closingPeriod` の `closingDayOfMonth`)。一覧は `docs/migration.md` の 0.30.0 の節。旧名は `@deprecated` の別名として残り、設定の旧名は読み替える(両方を書くと `invalid-option`)
21
+ - 返す値: 営業日カレンダーの理由 `"regular"` → `"default"`(`createCalendarFromSchedule` は `"open-weekday"`)、エラーコード `"invalid-month-day"` → `"invalid-annual-date"`、設定の中の位置を表す文字列は新しいキー名(日本の祝日の `kind` は Data)
22
+ - 規則の形ごとに受ける項目を型で分けた(`holidayOverlapPolicy`・`skipWeekdays`・`calendar`)。実行時に `invalid-option` になる書き方が型でも通らない(`docs/decisions.md` の 33 番の見直し)
23
+ - `outOfRangePolicy: "throw"` のとき、隣の日を見る規則(祝日の翌日・祝前日・`skipWeekdays`・`"after-holiday"` の振替元)が対応年の外の日を見ると `out-of-range` を投げる(これまでは外を黙って祝日でないとみなしていた)。診断は外を祝日なしとして扱う
24
+ - 打ち間違いの候補(`unknown-option` の `message`)は、旧名に近いキーなら新しい名前を挙げる
25
+
26
+ ### Deprecated
27
+
28
+ - 0.30.0 で改名した旧名のすべて(`docs/migration.md` の「1.0.0 で削除する予定の API」)。1.0.0 で削除し、設定の旧名は `invalid-option` にする
29
+
30
+ ### Data
31
+
32
+ - 日本の祝日の `kind` の `"national"` を `"regular"` にした(日付・名称・`key` は変わらない)
33
+
34
+ ### 移行
35
+
36
+ - 実行時は旧名のままでも動くが、返す値の変更・対応年の端の挙動・TypeScript で必須のキーの旧名・`dayInfoOn` の結果を丸ごと比べるテストは 0.30.0 に上げた時点で対応が要る(下の箇条)。それ以外は TypeScript の取り消し線と診断の `deprecated-option` を手がかりに新しい名前に書き換える。保存した設定は `migrateCalendarOptions`・`migrateScheduleOptions` で書き換えられる
37
+ - 型が旧名を持つのは省略可能なキーだけなので、スケジュールの `weekly`・合成の `businessDay`・期日の `day`・振替の `rules`・規則の `day` は、TypeScript では新しい名前に書き換える
38
+ - 返す値(`reason` の `"regular"`、日本の `kind` の `"national"`、エラーコード `"invalid-month-day"`、設定の中の位置の文字列)と比べているコードを改める
39
+ - `dayInfoOn` の結果を `deepEqual` で比べているテストは、期待値に `open` と、`rulePath` があれば `optionPath` を足し、`reason` が `"regular"` なら `"default"`(`createCalendarFromSchedule` では `"open-weekday"`)に直す
40
+ - 対応年の最後の日付の近くで祝前日・祝日の翌日・振替の規則を使っていて例外になったら、`outOfRangePolicy: "ignore"` にするか、対応年の中で使う
41
+
42
+ ### 開発
43
+
44
+ - 名前の規則の検査 `scripts/check-names.ts` を `pnpm check` に足した(`etc/naming.md` の用語集・外部の名前の出典と、移行ガイドの削除予定の表に照らす。名前を許す一覧は持たない)。名前が約束する意味は `test/naming.test.ts` の性質のテストで確かめる
45
+ - 改名の表を `src/core/renamed.ts` の 1 か所に置き、読み替え・診断・`migrate…` がこの表だけを使う
46
+ - `scripts/bench.ts` は、前の版が新しい名前を知らないときは設定を旧名に戻して渡す(CI の bench が同じ場面を比べるため)
47
+ - `scripts/check-readme-examples.ts` は、0.30.x の間だけ返す旧名の項目(削除予定の表から決める)を比べない
48
+ - サイズの上限を上げた(ルート 17,500 → 18,500、`./jp` 19,500 → 21,000、`./diagnose` 23,000 → 25,000、`./provider` 3,500 → 4,500 バイト)。改名の表・旧名の読み替え・旧名の別名・週の第 n 営業日・`migrate…` のため。gzip でルート 16,074 → 17,639、`./jp` 18,293 → 19,883、`./diagnose` 21,445 → 23,913、`./provider` 3,111 → 4,041 バイト
49
+ - README のサイズの値を 0.30.0 で測り直した
50
+
7
51
  ## [0.22.2] - 2026-10-27
8
52
 
9
53
  ### Changed
@@ -660,7 +704,8 @@
660
704
 
661
705
  - 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
662
706
 
663
- [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.2...HEAD
707
+ [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.0...HEAD
708
+ [0.30.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.2...v0.30.0
664
709
  [0.22.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.1...v0.22.2
665
710
  [0.22.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.22.0...v0.22.1
666
711
  [0.22.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.21.4...v0.22.0
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 11.5 KB min+gzip (about 13.2 KB with Japanese holidays, about 13.6 KB with UK bank holidays, about 12.4 KB with French holidays, about 12.4 KB with Singapore holidays; measured for 0.22.0). Standard JavaScript and `Intl` only, ESM with bundled types; tested on Node.js, Chrome, Firefox, Edge, Safari, Cloudflare Workers, Bun and Deno. Instants such as `Date` are converted to a civil date in the calendar's time zone before evaluation
27
+ - **Lightweight, zero dependencies, time-zone safe**: about 12.7 KB min+gzip (about 14.4 KB with Japanese holidays, about 14.8 KB with UK bank holidays, about 13.6 KB with French holidays, about 13.6 KB with Singapore holidays; measured for 0.30.0). 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
@@ -46,14 +46,14 @@ import { isHoliday, jp } from "bizdays-toolkit/jp";
46
46
  isHoliday("2026-11-23"); // true (Labor Thanksgiving Day)
47
47
 
48
48
  const calendar = createCalendar({
49
- holidays: jp,
49
+ holidayProvider: jp,
50
50
  closedWeekdays: [0, 6],
51
- closedAnnual: [{ from: "12-29", to: "01-03", name: "New Year closure" }],
51
+ closedAnnualDates: [{ from: "12-29", to: "01-03", name: "New Year closure" }],
52
52
  });
53
53
  calendar.isBusinessDay("2026-12-30"); // false
54
54
  calendar.addBusinessDays("2026-12-28", 1); // "2027-01-04"
55
55
  calendar.businessDayOnOrAfter("2026-12-28T15:30", { cutoff: "14:00" }); // "2027-01-04" (after the cutoff, so the next business day)
56
- calendar.dueDate("2026-11", { day: 23, convention: "following" }); // "2026-11-24" (the 23rd is a holiday)
56
+ calendar.dueDate("2026-11", { dayOfMonth: 23, convention: "following" }); // "2026-11-24" (the 23rd is a holiday)
57
57
  ```
58
58
 
59
59
  The [guide](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md) explains everything below in full, with examples that are run in CI. This README is the short version.
@@ -69,30 +69,31 @@ 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` (national, substitute, citizens' holiday, bank holiday and so on, 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 `outOfRange: "ignore"` is set, and `unconfirmedHolidays: "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).
72
+ Each holiday carries its date, name (and English name), `kind` (national, substitute, citizens' holiday, bank holiday and so on, 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
 
76
- A calendar is built from the holiday provider and your closures: `closedWeekdays`, `closedAnnual` (month-day ranges, across the new year too), `closedDates` and `openDates`, and recurring rules in `closedRecurring` / `openRecurring`:
76
+ A calendar is built from the holiday provider and your closures: `closedWeekdays`, `closedAnnualDates` (month-day ranges, across the new year too), `closedDates` and `openDates`, and recurring rules in `closedRecurringRules` / `openRecurringRules`:
77
77
 
78
78
  | Rule | Meaning |
79
79
  | --------------------------------------------------------- | -------------------------------------------------------------------------------- |
80
80
  | `{ weekday: 3, nth: 3 }` | The 3rd Wednesday (`nth` is 1–5 or -1 for the last; an array for several) |
81
81
  | `{ weekday: 3, interval: 2, anchor: "2026-01-07" }` | Every other Wednesday, counted from the anchor |
82
82
  | `{ cycle: 6, anchor: "2026-01-05", positions: [5, 6] }` | Days 5 and 6 of every 6 days from the anchor (four days on, two days off) |
83
- | `{ day: 20 }`, `{ day: -1 }` | The 20th, the last day of the month |
83
+ | `{ dayOfMonth: 20 }`, `{ dayOfMonth: -1 }` | The 20th, the last day of the month |
84
84
  | `{ businessDayOfMonth: -1 }`, `{ businessDayOfMonth: 5 }` | The last business day of the month, the 5th business day |
85
+ | `{ businessDayOfWeek: -1, weekStart: 1 }` | The last business day of the week starting on Monday |
85
86
  | `{ holiday: true, kinds: ["substitute"] }` | Holidays, optionally narrowed by kind or by key (`keys: ["vernal-equinox"]`) |
86
87
  | `{ dayAfterHoliday: true }`, `{ dayBeforeHoliday: true }` | The day after (or before) a holiday or a run of holidays |
87
- | `onHolidayRule: "after-holiday"` | "Closed on Mondays, or the next non-holiday if a holiday" (can be a Saturday) |
88
+ | `holidayOverlapPolicy: "after-holiday"` | "Closed on Mondays, or the next non-holiday if a holiday" (can be a Saturday) |
88
89
  | `skipWeekdays: [0, 6]` | With `"after-holiday"`: also skip weekends ("June 15, or the next business day") |
89
90
  | `effectiveFrom`, `effectiveTo` | The period the rule is in effect |
90
91
 
91
- `dayInfo` tells you why a day is open or closed (`reason`, `name`, `rulePath`). Every bundled holiday that recurs each year has a stable `key` (`vernal-equinox`, `good-friday`, `hari-raya-puasa`, …), so a rule can select individual holidays that no date pattern can express. Details: [Business-day calendars](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#business-day-calendars), [Recurring rules](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#recurring-rules), [Holiday keys](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#holiday-keys), [Common recipes](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#common-recipes).
92
+ `dayInfoOn` tells you why a day is open or closed (`reason`, `name`, `optionPath`). Every bundled holiday that recurs each year has a stable `key` (`vernal-equinox`, `good-friday`, `hari-raya-puasa`, …), so a rule can select individual holidays that no date pattern can express. Details: [Business-day calendars](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#business-day-calendars), [Recurring rules](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#recurring-rules), [Holiday keys](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#holiday-keys), [Common recipes](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#common-recipes).
92
93
 
93
94
  ### Due dates, schedules and combined calendars
94
95
 
95
- - `dueDate("2026-11", { day: 23, convention: "following" })`, `adjust`, `closingMonth` and `closingPeriod` compute month-based due dates and closing periods with the `following`, `preceding`, `modified-following` and `modified-preceding` conventions ([Month-based due dates](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#month-based-due-dates-and-date-adjustment))
96
+ - `dueDate("2026-11", { dayOfMonth: 23, convention: "following" })`, `adjust`, `closingMonth` and `closingPeriod` compute month-based due dates and closing periods with the `following`, `preceding`, `modified-following` and `modified-preceding` conventions ([Month-based due dates](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#month-based-due-dates-and-date-adjustment))
96
97
  - `createSchedule` gives a value per day (store hours, a shipping cutoff, a price band) from the same kinds of rules, and `createCalendarFromSchedule` turns such a schedule into a calendar so the hours are the only configuration ([Day-by-day values](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#day-by-day-values-eg-store-hours), [A calendar from a schedule](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#a-business-day-calendar-from-a-schedule))
97
98
  - `combineCalendars` builds the days on which all (or any) of several calendars are open, such as your company and the bank for a remittance date ([Combining calendars](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#combining-calendars))
98
99
  - Dates can be given as `"YYYY-MM-DD"`, `"YYYY-MM-DDTHH:mm"`, `Date` or Temporal objects; instants are converted in the calendar's time zone ([Date and date-time inputs](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#date-and-date-time-inputs))
@@ -104,12 +105,12 @@ import { diagnoseCalendar } from "bizdays-toolkit/diagnose";
104
105
  import { jp } from "bizdays-toolkit/jp";
105
106
 
106
107
  diagnoseCalendar({
107
- holidays: jp,
108
+ holidayProvider: jp,
108
109
  closedWeekdays: [0],
109
- closedRecurring: [{ weekday: 0 }],
110
+ closedRecurringRules: [{ weekday: 0 }],
110
111
  closeAnnual: ["12-31"],
111
112
  }).map((d) => [d.severity, d.code, d.path]);
112
- // [["warning", "unknown-option", "closeAnnual"], ["info", "redundant", "closedRecurring[0]"]]
113
+ // [["warning", "unknown-option", "closeAnnual"], ["info", "redundant", "closedRecurringRules[0]"]]
113
114
  ```
114
115
 
115
116
  `diagnoseCalendar` and `diagnoseSchedule` return every problem in the options without throwing: typos (with a suggestion), rules that never match, rules shadowed by earlier ones, rules whose removal changes nothing, options with no business day, and, with `{ asOf }`, rules that have ended. `assert.deepEqual(diagnoseCalendar(options), [])` in a test keeps options honest. Details: [Option diagnostics](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#option-diagnostics), [Errors](https://github.com/inohan77/bizdays-toolkit/blob/main/docs/guide.md#errors).
@@ -4,14 +4,14 @@
4
4
  * 1 日の判定は次の優先順位で行う(上が優先):
5
5
  * 1. openDates … 臨時営業日(個別の日付・期間)
6
6
  * 2. closedDates … 臨時休業日(個別の日付・期間)
7
- * 3. closedAnnual … 毎年の休業日(月日・月日の期間。年をまたぐ期間も可)
8
- * 4. openRecurring・closedRecurring(onHolidayRule: "over-holiday")… 祝日でも当てはめる繰り返しの規則
7
+ * 3. closedAnnualDates … 毎年の休業日(月日・月日の期間。年をまたぐ期間も可)
8
+ * 4. openRecurringRules・closedRecurringRules(holidayOverlapPolicy: "over-holiday")… 祝日でも当てはめる繰り返しの規則
9
9
  * 5. 祝日 … holidayPolicy に従う(closed: 休業 / open: 営業 / ignore: 判定に使わない)
10
- * 6. openRecurring・closedRecurring("under-holiday"・"after-holiday" の振替先)… 繰り返しの規則
10
+ * 6. openRecurringRules・closedRecurringRules("under-holiday"・"after-holiday" の振替先)… 繰り返しの規則
11
11
  * 7. closedWeekdays … 定休日の曜日
12
12
  * 8. それ以外は営業日
13
13
  *
14
- * 繰り返しの規則は openRecurring が closedRecurring より優先。"after-holiday" の規則は、
14
+ * 繰り返しの規則は openRecurringRules が closedRecurringRules より優先。"after-holiday" の規則は、
15
15
  * 祝日には当てはめず、その日以降で最初の祝日でない日に当てはめる(振替)
16
16
  *
17
17
  * 内部では、営業日かどうか(真偽値)を返すスケジュール(createSchedule)として作っている。
@@ -71,29 +71,41 @@ export interface CalendarOptions<Kind extends string = string> extends HolidaySo
71
71
  /** 定休日の曜日(0 = 日曜日) */
72
72
  readonly closedWeekdays?: readonly Weekday[];
73
73
  /** 毎年の休業日(有効期間 effectiveFrom・effectiveTo を付けられる) */
74
- readonly closedAnnual?: readonly (AnnualDate | AnnualRange)[];
74
+ readonly closedAnnualDates?: readonly (AnnualDate | AnnualRange)[];
75
75
  /** 臨時休業日 */
76
76
  readonly closedDates?: readonly (SpecificDate | DateRange)[];
77
77
  /** 臨時営業日(ほかのすべての規則より優先) */
78
78
  readonly openDates?: readonly (SpecificDate | DateRange)[];
79
79
  /**
80
80
  * 繰り返しの休業日(毎週・隔週などの周期・毎月の第 n 曜日・毎月の日)。
81
- * 祝日に当たったときの扱いは規則ごとに onHolidayRule で指定する(既定: "under-holiday")。
81
+ * 祝日に当たったときの扱いは規則ごとに holidayOverlapPolicy で指定する(既定: "under-holiday")。
82
82
  * 有効期間(effectiveFrom・effectiveTo)を付けると、期間の外では書かれていないのと同じに扱う
83
83
  */
84
- readonly closedRecurring?: readonly RecurringRule<Kind>[];
85
- /** 繰り返しの営業日。closedRecurring と同じ日に当たる場合はこちらが優先 */
86
- readonly openRecurring?: readonly RecurringRule<Kind>[];
84
+ readonly closedRecurringRules?: readonly RecurringRule<Kind>[];
85
+ /** 繰り返しの営業日。closedRecurringRules と同じ日に当たる場合はこちらが優先 */
86
+ readonly openRecurringRules?: readonly RecurringRule<Kind>[];
87
87
  /** 祝日の扱い(既定: "closed") */
88
88
  readonly holidayPolicy?: HolidayPolicy;
89
89
  /** 営業日を探すときに調べる最大日数(既定: 3660)。超えたら Error */
90
+ readonly searchDayLimit?: number;
91
+ /** @deprecated 0.30.0 で closedAnnualDates に改名した。1.0.0 で削除する */
92
+ readonly closedAnnual?: readonly (AnnualDate | AnnualRange)[];
93
+ /** @deprecated 0.30.0 で closedRecurringRules に改名した。1.0.0 で削除する */
94
+ readonly closedRecurring?: readonly RecurringRule<Kind>[];
95
+ /** @deprecated 0.30.0 で openRecurringRules に改名した。1.0.0 で削除する */
96
+ readonly openRecurring?: readonly RecurringRule<Kind>[];
97
+ /** @deprecated 0.30.0 で searchDayLimit に改名した。1.0.0 で削除する */
90
98
  readonly maxSearchDays?: number;
91
99
  }
92
100
  /**
93
101
  * 営業・休業を決めた規則(既知の値)。
94
102
  * @public
95
103
  */
96
- export type KnownDayReason = "open-date" | "closed-date" | "open-annual" | "closed-annual" | "open-recurring" | "closed-recurring" | "holiday" | "closed-weekday" | "regular";
104
+ export type KnownDayReason = "open-date" | "closed-date" | "open-annual" | "closed-annual" | "open-recurring" | "closed-recurring" | "holiday" | "closed-weekday"
105
+ /** どの設定にも当たらなかった営業日 */
106
+ | "default"
107
+ /** スケジュールから作ったカレンダーで、曜日の値で営業日になった日 */
108
+ | "open-weekday";
97
109
  /**
98
110
  * 営業・休業を決めた規則。将来の版で値が増えることがあるので、分岐では「その他」も扱うこと。
99
111
  * すべての値を網羅したことを型で確かめたい場合は KnownDayReason を使う。
@@ -107,6 +119,9 @@ export type DayReason = KnownDayReason | (string & {});
107
119
  export interface DayInfo<Kind extends string = string> {
108
120
  readonly date: DateString;
109
121
  readonly weekday: Weekday;
122
+ /** 営業日か */
123
+ readonly open: boolean;
124
+ /** @deprecated 0.30.0 で open に改名した(同じ値)。1.0.0 で削除する */
110
125
  readonly businessDay: boolean;
111
126
  /** 判定を決めた規則 */
112
127
  readonly reason: DayReason;
@@ -114,21 +129,23 @@ export interface DayInfo<Kind extends string = string> {
114
129
  readonly name?: string;
115
130
  /** その日が祝日なら祝日(holidayPolicy に関係なく付く) */
116
131
  readonly holiday?: Holiday<Kind>;
117
- /** 祝日から振り替えられた繰り返しの規則で決まった場合、振替の元の日付(onHolidayRule: "after-holiday") */
132
+ /** 祝日から振り替えられた繰り返しの規則で決まった場合、振替の元の日付(holidayOverlapPolicy: "after-holiday") */
118
133
  readonly shiftedFrom?: DateString;
119
134
  /**
120
- * 判定を決めた規則の設定の中の位置(規則の診断の path と同じ形。例: "closedRecurring[0]")。
135
+ * 判定を決めた規則の設定の中の位置(規則の診断の path と同じ形。例: "closedRecurringRules[0]")。
121
136
  * 個別の日付・毎年の休業日・繰り返しの規則(振替先を含む)で決まった日にだけ付き、祝日・定休日の曜日で決まった日には付かない
122
137
  */
138
+ readonly optionPath?: string;
139
+ /** @deprecated 0.30.0 で optionPath に改名した(同じ値)。1.0.0 で削除する */
123
140
  readonly rulePath?: string;
124
141
  /**
125
142
  * 合成したカレンダー(combineCalendars)で、判定を決めたカレンダーの番号(渡した配列の位置)。
126
- * reason・name・shiftedFrom・rulePath はそのカレンダーの結果。合成していないカレンダーでは付かない
143
+ * reason・name・shiftedFrom・optionPath はそのカレンダーの結果。合成していないカレンダーでは付かない
127
144
  */
128
145
  readonly decidedBy?: number;
129
146
  /**
130
147
  * 合成したカレンダーで、判定を決めたカレンダーまでの番号の列(外側から順)。入れ子でない合成では長さ 1 で、
131
- * 先頭は decidedBy と同じ。合成したカレンダーをさらに合成したとき、rulePath がどのカレンダーの設定の位置かを
148
+ * 先頭は decidedBy と同じ。合成したカレンダーをさらに合成したとき、optionPath がどのカレンダーの設定の位置かを
132
149
  * 結果だけから辿れる(例: [0, 1] は 0 番のカレンダーの中の 1 番)。合成していないカレンダーでは付かない
133
150
  */
134
151
  readonly decidedByPath?: readonly number[];
@@ -137,20 +154,22 @@ export interface DayInfo<Kind extends string = string> {
137
154
  * カレンダーの合成のオプション。
138
155
  * @public
139
156
  */
140
- export interface CombineOptions {
157
+ export interface CombineCalendarsOptions {
141
158
  /**
142
159
  * 営業日とする条件。"all": すべてのカレンダーが営業日(例: 自社と銀行の両方が営業している日)/
143
160
  * "any": いずれかのカレンダーが営業日(例: 複数の店舗のどこかが開いている日)
144
161
  */
145
- readonly businessDay: "all" | "any";
162
+ readonly open: "all" | "any";
146
163
  /** 営業日を探すときに調べる最大日数(既定: 3660)。超えたら Error */
164
+ readonly searchDayLimit?: number;
165
+ /** @deprecated 0.30.0 で searchDayLimit に改名した。1.0.0 で削除する */
147
166
  readonly maxSearchDays?: number;
148
167
  }
149
168
  /**
150
169
  * 営業日を探すときのオプション。
151
170
  * @public
152
171
  */
153
- export interface BusinessDayOptions {
172
+ export interface BusinessDayOnOrAfterOptions {
154
173
  /**
155
174
  * 締め時刻 "HH:mm"(カレンダーのタイムゾーン)。
156
175
  * 入力の時刻がこの時刻以降なら、その日は対象にしない。時刻を持たない入力(暦日の文字列・Temporal の PlainDate など)
@@ -166,6 +185,7 @@ export interface BusinessDayOptions {
166
185
  * - "modified-preceding": 前営業日。ただし月が変わるなら翌営業日
167
186
  *
168
187
  * 月が変わるかは、調整する前の日付の月と比べる。
188
+ * @namingSource isda
169
189
  * @public
170
190
  */
171
191
  export type BusinessDayConvention = "following" | "preceding" | "modified-following" | "modified-preceding";
@@ -183,7 +203,7 @@ export interface AdjustOptions {
183
203
  */
184
204
  export interface DueDateOptions {
185
205
  /** 期日の日(1〜31、-1 は末日)。その月にない日(2 月 30 日など)は末日に読み替える */
186
- readonly day: DayOfMonth;
206
+ readonly dayOfMonth: DayOfMonth;
187
207
  /** 期日が休業日のときの調整の方法 */
188
208
  readonly convention: BusinessDayConvention;
189
209
  }
@@ -193,6 +213,8 @@ export interface DueDateOptions {
193
213
  */
194
214
  export interface Calendar<Kind extends string = string> extends HolidayLookup<Kind> {
195
215
  /** 1 日分の判定結果(営業日か・理由・祝日) */
216
+ dayInfoOn(input: DateInput): DayInfo<Kind>;
217
+ /** @deprecated 0.30.0 で dayInfoOn に改名した。1.0.0 で削除する */
196
218
  dayInfo(input: DateInput): DayInfo<Kind>;
197
219
  /** 期間内の日ごとの判定結果(両端を含む。from が to より後ならエラー) */
198
220
  daysBetween(from: DateInput, to: DateInput): readonly DayInfo<Kind>[];
@@ -206,7 +228,7 @@ export interface Calendar<Kind extends string = string> extends HolidayLookup<Ki
206
228
  * 入力日が営業日ならその日、そうでなければ翌営業日。cutoff で締め時刻を指定できる
207
229
  * (cutoff を指定するときの入力は、時刻を持つもの。時刻のない入力と組み合わせると invalid-argument)
208
230
  */
209
- businessDayOnOrAfter(input: DateInput, options?: BusinessDayOptions): DateString;
231
+ businessDayOnOrAfter(input: DateInput, options?: BusinessDayOnOrAfterOptions): DateString;
210
232
  /** 入力日が営業日ならその日、そうでなければ前営業日 */
211
233
  businessDayOnOrBefore(input: DateInput): DateString;
212
234
  /**
@@ -215,8 +237,12 @@ export interface Calendar<Kind extends string = string> extends HolidayLookup<Ki
215
237
  */
216
238
  addBusinessDays(input: DateInput, n: number): DateString;
217
239
  /** from 以上 to 未満の営業日の数(to が前なら負) */
218
- businessDaysBetween(from: DateInput, to: DateInput): number;
240
+ diffBusinessDays(from: DateInput, to: DateInput): number;
219
241
  /** 期間内の営業日(両端を含む) */
242
+ businessDatesBetween(from: DateInput, to: DateInput): readonly DateString[];
243
+ /** @deprecated 0.30.0 で diffBusinessDays に改名した。1.0.0 で削除する */
244
+ businessDaysBetween(from: DateInput, to: DateInput): number;
245
+ /** @deprecated 0.30.0 で businessDatesBetween に改名した。1.0.0 で削除する */
220
246
  listBusinessDays(from: DateInput, to: DateInput): readonly DateString[];
221
247
  /**
222
248
  * 営業日ならその日、休業日なら convention に従って調整した営業日。
@@ -233,7 +259,7 @@ export interface Calendar<Kind extends string = string> extends HolidayLookup<Ki
233
259
  /** 月 "YYYY-MM" の最後の営業日(nthBusinessDayOfMonth(month, -1)) */
234
260
  lastBusinessDayOfMonth(month: MonthString): DateString;
235
261
  /**
236
- * 月 "YYYY-MM" の day 日を期日とし、休業日なら convention で調整した日。
262
+ * 月 "YYYY-MM" の dayOfMonth 日を期日とし、休業日なら convention で調整した日。
237
263
  * その月にない日は末日に読み替えてから調整する(例: 2 月の 30 日払いは 2 月末日)
238
264
  */
239
265
  dueDate(month: MonthString, options: DueDateOptions): DateString;
@@ -243,21 +269,21 @@ export interface Calendar<Kind extends string = string> extends HolidayLookup<Ki
243
269
  * 日付が D(m) 以下となる最小の m を返す。前月の締め日から当月の締め日までに営業日がない月(長期休業)は
244
270
  * 固有の期間を持たず、その日は次の月に属する
245
271
  */
246
- closingMonth(input: DateInput, closingDay: number, options: AdjustOptions): MonthString;
272
+ closingMonth(input: DateInput, closingDayOfMonth: number, options: AdjustOptions): MonthString;
247
273
  /**
248
274
  * 営業日を考慮した締め日で区切ったときの、その月分の期間(両端を含む暦日。前月の調整後の締め日の翌日から
249
275
  * 当月の調整後の締め日まで)。暦日を渡すと、その日が属する期間(closingMonth で求めた月の期間)。
250
276
  * 月を渡して、その月に固有の期間がない(前月の締め日から当月の締め日までに営業日がない)ときは
251
277
  * code: "no-business-day" の Error。返す値は変更できず、name は付かない
252
278
  */
253
- closingPeriod(input: DateInput | MonthString, closingDay: number, options: AdjustOptions): {
279
+ closingPeriod(input: DateInput | MonthString, closingDayOfMonth: number, options: AdjustOptions): {
254
280
  readonly from: DateString;
255
281
  readonly to: DateString;
256
282
  };
257
283
  }
258
284
  interface CompiledCalendar<Kind extends string> {
259
285
  readonly schedule: CompiledSchedule<boolean, Kind>;
260
- readonly maxSearchDays: number;
286
+ readonly searchDayLimit: number;
261
287
  }
262
288
  /** @internal 営業日カレンダーの設定を検証して取り込む(誤りは c に集める) */
263
289
  export declare function compileCalendarOptions<Kind extends string>(c: IssueCollector, options: unknown): CompiledCalendar<Kind> | undefined;
@@ -273,7 +299,7 @@ export declare function createCalendar<Kind extends string = string>(options?: C
273
299
  * 作成済みの営業日カレンダーを合成する。"all" はすべてのカレンダーが営業している日、"any" はいずれかが
274
300
  * 営業している日を営業日とする。返すのは通常の営業日カレンダーで、営業日の加減算・調整・期日などが合成結果で動く。
275
301
  *
276
- * - dayInfo の reason・name・shiftedFrom・rulePath は、合成結果と同じ判定をした最初のカレンダーの結果で、
302
+ * - dayInfoOn の reason・name・shiftedFrom・optionPath は、合成結果と同じ判定をした最初のカレンダーの結果で、
277
303
  * その番号を decidedBy で返す。入れ子の合成では、内側の番号まで含めた列を decidedByPath で返す。
278
304
  * holiday・isHoliday などは、すべてのカレンダーの祝日の提供元の和集合で判定する
279
305
  * - タイムゾーンはすべてのカレンダーで同じでなければならない(time-zone-conflict)。
@@ -282,7 +308,17 @@ export declare function createCalendar<Kind extends string = string>(options?: C
282
308
  * 元のカレンダーの設定をそれぞれ診断する
283
309
  * @public
284
310
  */
285
- export declare function combineCalendars<Kind extends string = string>(calendars: readonly Calendar<Kind>[], options: CombineOptions): Calendar<Kind>;
311
+ export declare function combineCalendars<Kind extends string = string>(calendars: readonly Calendar<Kind>[], options: CombineCalendarsOptions): Calendar<Kind>;
312
+ /**
313
+ * スケジュールから作る営業日カレンダーのオプション。
314
+ * @public
315
+ */
316
+ export interface CalendarFromScheduleOptions {
317
+ /** 営業日を探すときに調べる最大日数(既定: 3660)。超えたら Error */
318
+ readonly searchDayLimit?: number;
319
+ /** @deprecated 0.30.0 で searchDayLimit に改名した。1.0.0 で削除する */
320
+ readonly maxSearchDays?: number;
321
+ }
286
322
  /**
287
323
  * スケジュール(createSchedule)から営業日カレンダーを作る。isOpen が true を返す値の日を営業日とする。
288
324
  * 営業時間表のような日ごとの値が設定の正本で、営業日の計算(加減算・調整・期日など)も同じ設定から行いたいときに使う
@@ -290,14 +326,22 @@ export declare function combineCalendars<Kind extends string = string>(calendars
290
326
  *
291
327
  * - isOpen は値だけで決まる純粋な関数であること(日付・時刻・外部の状態を見ない)。営業日の探索は isOpen を繰り返し呼ぶので、
292
328
  * 結果が変わる関数を渡すと探索の結果が呼ぶたびに変わる。日付で変えたい条件は、スケジュールの規則(dates・recurring)に書く
293
- * - dayInfo の reason は、スケジュールの reason と営業・休業の組み合わせ(date → "open-date"/"closed-date"、annual → "open-annual"/
294
- * "closed-annual"、recurring → "open-recurring"/"closed-recurring"、holiday → "holiday"、weekday → "regular"/"closed-weekday")。
295
- * name・holiday・shiftedFrom・rulePath はスケジュールの結果をそのまま引き継ぐ
296
- * - 祝日の判定(holiday・isHoliday など)・タイムゾーン・outOfRange はスケジュールのもの。規則の診断(diagnoseSchedule)は
329
+ * - dayInfoOn の reason は、スケジュールの reason と営業・休業の組み合わせ(date → "open-date"/"closed-date"、annual → "open-annual"/
330
+ * "closed-annual"、recurring → "open-recurring"/"closed-recurring"、holiday → "holiday"、weekday → "open-weekday"/"closed-weekday")。
331
+ * name・holiday・shiftedFrom・optionPath はスケジュールの結果をそのまま引き継ぐ
332
+ * - 祝日の判定(holiday・isHoliday など)・タイムゾーン・outOfRangePolicy はスケジュールのもの。規則の診断(diagnoseSchedule)は
297
333
  * スケジュールの設定に対して行う
298
334
  * @public
299
335
  */
300
- export declare function createCalendarFromSchedule<T, Kind extends string = string>(schedule: Schedule<T, Kind>, isOpen: (value: T) => boolean, options?: {
301
- readonly maxSearchDays?: number;
302
- }): Calendar<Kind>;
336
+ export declare function createCalendarFromSchedule<Value, Kind extends string = string>(schedule: Schedule<Value, Kind>, isOpen: (value: Value) => boolean, options?: CalendarFromScheduleOptions): Calendar<Kind>;
337
+ /**
338
+ * @deprecated 0.30.0 で CombineCalendarsOptions に改名した。1.0.0 で削除する
339
+ * @public
340
+ */
341
+ export type CombineOptions = CombineCalendarsOptions;
342
+ /**
343
+ * @deprecated 0.30.0 で BusinessDayOnOrAfterOptions に改名した。1.0.0 で削除する
344
+ * @public
345
+ */
346
+ export type BusinessDayOptions = BusinessDayOnOrAfterOptions;
303
347
  export {};