bizdays-toolkit 0.12.0 → 0.13.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,28 @@
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.13.0] - 2026-10-20
8
+
9
+ ### 移行
10
+
11
+ 動作は変わりません(スケジュールから営業日カレンダーを作る関数と、判定の理由の新しい値の追加。CI の改善)。版ごとの作業は [docs/migration.md](./docs/migration.md) にまとめた。
12
+
13
+ ### Added
14
+
15
+ - スケジュールから営業日カレンダーを作る `createCalendarFromSchedule(schedule, isOpen, { maxSearchDays? })` を追加した。`isOpen` が true を返す値の日を営業日とする通常のカレンダーを返し、営業時間表のようなスケジュールが唯一の設定になる。`isOpen` は値だけを受け取る純粋な関数(日付は渡さない。営業日の探索で繰り返し呼ぶため)。`dayInfo` の `reason` はスケジュールの `reason` と営業・休業の組み合わせで、`name`・`holiday`・`shiftedFrom`・`rulePath` はスケジュールの結果を引き継ぐ。祝日・タイムゾーン・`outOfRange` はスケジュールのもの。`createSchedule` が作ったスケジュール以外は `invalid-argument`
16
+ - 判定の理由(`DayReason`)に `"open-annual"`(スケジュールの `annual` の値で営業になる日)を追加した。`createCalendar` の結果には現れない(`closedAnnual` は休業だけ)
17
+
18
+ ### Changed
19
+
20
+ - README: 「スケジュールから営業日カレンダーを作る」の節を足した。型定義の確認の範囲を、CI で確かめる TypeScript の版(5.0・5.5・5.8・6.0・7.0)に改めた。サイズの値を測り直した(ルート約 9.0KB・日本の祝日込み約 10.8KB・英国の祝日込み約 10.7KB。0.13.0 で測定)
21
+ - `docs/decisions.md`: 38 番(スケジュールからのカレンダー・`"open-annual"`・利用者の TypeScript の版の確認)を追加した
22
+
23
+ ### 開発
24
+
25
+ - CI に `consumer-types` ジョブを追加した。公開する型定義を、利用者が使う TypeScript 5.0.4・5.5.4・5.8.3・7.0.2(ネイティブ版)のそれぞれで、`moduleResolution` の `node16`・`nodenext`・`bundler` で型チェックする。各版は依存にせず、版と SHA-256 を固定した tgz から一時ディレクトリに入れる(7.0 はランナー向けの実行形式 `@typescript/typescript-linux-x64` も固定)。`pnpm check` は従来どおり開発用の 6.0.3 で確かめる
26
+ - `scripts/check-consumer-types.ts` に `--tsc <path>` を足し、わざと型エラーを含む `test/consumer/consumer-error.mts` が各版で失敗として報告されること(検査が機能していること)も確かめるようにした。リポジトリの `@types` を読まないよう `--typeRoots` を空にした(古い TypeScript では `@types/node` の新しい構文を読めないため)。`--ignoreConfig` は 6.0 以降でだけ渡す
27
+ - `createCalendar` の `dayInfo` の変換を `createCalendarFromSchedule` と共用の内部関数に切り出した。結果は変わらない
28
+
7
29
  ## [0.12.0] - 2026-10-20
8
30
 
9
31
  ### 移行
@@ -330,7 +352,8 @@
330
352
 
331
353
  - 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
332
354
 
333
- [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.12.0...HEAD
355
+ [Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.13.0...HEAD
356
+ [0.13.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.12.0...v0.13.0
334
357
  [0.12.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.11.1...v0.12.0
335
358
  [0.11.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.11.0...v0.11.1
336
359
  [0.11.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.10.0...v0.11.0
package/README.md CHANGED
@@ -25,9 +25,10 @@ A business-day calendar that combines public holidays with company or store clos
25
25
  - **Option diagnostics**: `diagnoseCalendar` and `diagnoseSchedule` from `bizdays-toolkit/diagnose` list rules that can never apply, rules whose removal changes nothing, typos in option keys, calendars with no business day and more, without throwing. One line in your tests keeps a change of settings from silently killing a rule
26
26
  - **Month-based due dates**: due dates such as "closing on the 20th, paid on the 10th of the next month (next business day if closed)" or "the last business day of the month", with the four adjustment conventions used in finance (following, preceding, modified-following, modified-preceding)
27
27
  - **Business-day arithmetic**: closed weekdays, annual closures (including ranges across the new year), specific closed and open dates, and holidays combine to compute "N business days later", "next business day after the cut-off time" and more
28
+ - **A calendar from a schedule**: `createCalendarFromSchedule` turns a schedule such as store hours into a business-day calendar, so the hours are the only configuration and business-day arithmetic works on them
28
29
  - **Combining calendars**: `combineCalendars` builds a calendar of the days on which all of several calendars are open (your company and the bank, for a remittance date) or any of them is open (any of several stores), and business-day arithmetic works on the result
29
30
  - **Time-zone safe**: instants such as `Date` are converted to a civil date in the calendar's time zone (`Asia/Tokyo` for Japan, `Europe/London` for the UK) before evaluation. A server running in UTC does not treat 00:00–09:00 in Japan as the previous day
30
- - **Lightweight, zero dependencies**: about 8.8 KB min+gzip (about 10.6 KB with Japanese holidays, about 10.5 KB with UK bank holidays; measured for 0.12.0). ESM, bundled types and `sideEffects: false`. Written in standard JavaScript and `Intl` only (no Node.js APIs); CI tests it on Node.js, Chrome, Firefox, Edge, Safari and Cloudflare Workers
31
+ - **Lightweight, zero dependencies**: about 9.0 KB min+gzip (about 10.8 KB with Japanese holidays, about 10.7 KB with UK bank holidays; measured for 0.13.0). ESM, bundled types and `sideEffects: false`. Written in standard JavaScript and `Intl` only (no Node.js APIs); CI tests it on Node.js, Chrome, Firefox, Edge, Safari and Cloudflare Workers
31
32
  - **Extensible to other countries and regions**: holiday providers are pluggable through the `HolidayProvider` interface. Japan and the UK are bundled
32
33
 
33
34
  ## Installation
@@ -38,7 +39,7 @@ pnpm add bizdays-toolkit
38
39
 
39
40
  Node.js 22.12 or later. CI tests the package on Node.js 22.12, 22, 24 and 26, on Chrome, Firefox and Edge (Linux) and Safari (macOS), and on Cloudflare Workers (workerd, the open-source Workers runtime). The browsers are the latest stable versions on GitHub's runners, so their versions change as the runners are updated. The package is ESM only, but it can also be loaded from CommonJS with `require()` (tested in CI as well; on Node.js 22.12, `require()` prints an experimental-feature warning, which does not affect the result, and Node.js 26 prints none). Other runtimes (such as Deno, Bun or Vercel's Edge Runtime) are not tested.
40
41
 
41
- Types are bundled. CI type-checks a consumer project against the published type definitions with `moduleResolution` set to `node16`, `nodenext` and `bundler` (TypeScript 6); TypeScript 5.0, 5.5 and 5.8 were also checked by hand for 0.9.0.
42
+ Types are bundled. CI type-checks a consumer project against the published type definitions with TypeScript 5.0, 5.5, 5.8, 6.0 and 7.0 (the native compiler), each with `moduleResolution` set to `node16`, `nodenext` and `bundler`, and confirms that an intentional type error is reported by each.
42
43
 
43
44
  ## Usage
44
45
 
@@ -450,6 +451,33 @@ const isOpen = hours !== null && hours.open <= time && time < hours.close;
450
451
 
451
452
  For inputs that always carry a time (a `Date`, Temporal `Instant`, `ZonedDateTime` or `PlainDateTime`, or a `"YYYY-MM-DDTHH:mm"` string), `time` is typed as `string`, so no `null` check is needed. `civilOf` is also on business-day calendars, and the same conversion is available as `toDateTimeParts(input, timeZone)` in the root. (`toJapanDate` and `toJapanDateTime` in `bizdays-toolkit/jp` are deprecated since 0.10.0: use `toDateString(input, "Asia/Tokyo")`, `toDateTimeParts(input, "Asia/Tokyo")` or `dateOf`/`civilOf` on a calendar instead. They will be removed in 1.0.0.)
452
453
 
454
+ ### A business-day calendar from a schedule
455
+
456
+ When the schedule (store hours, say) is the real configuration, `createCalendarFromSchedule(schedule, isOpen)` makes a business-day calendar from it, so you do not write a second set of rules to keep in sync. `isOpen` decides from the value alone whether the day is a business day; the result is an ordinary calendar with business-day arithmetic, `adjust`, `dueDate` and the rest.
457
+
458
+ ```ts
459
+ import { createCalendarFromSchedule } from "bizdays-toolkit";
460
+
461
+ const hours = createSchedule<Hours>({
462
+ holidays: jp,
463
+ weekly: [null, weekday, weekday, weekday, weekday, weekday, { open: "10:00", close: "17:00" }],
464
+ holiday: { sameAs: 0 },
465
+ annual: [
466
+ { from: "12-31", to: "01-03", value: null, name: "New Year closure" },
467
+ { date: "01-04", value: { open: "11:00", close: "15:00" }, name: "First day of the year" },
468
+ ],
469
+ });
470
+ const calendar = createCalendarFromSchedule(hours, (v) => v !== null);
471
+ calendar.addBusinessDays("2026-12-29", 2); // "2027-01-04"
472
+ calendar.dayInfo("2027-01-04");
473
+ // { date: "2027-01-04", weekday: 1, businessDay: true, reason: "open-annual", name: "First day of the year", rulePath: "annual[1]" }
474
+ ```
475
+
476
+ - `isOpen` must be a pure function of the value: it receives only the value (not the date), and the calendar calls it repeatedly while searching for business days, so a function that looks at the date, the time or outside state would make the result change from call to call. Conditions that depend on the date belong in the schedule's rules (`dates`, `recurring`)
477
+ - `dayInfo` maps the schedule's `reason` to the calendar's: `date` → `"open-date"`/`"closed-date"`, `annual` → `"open-annual"`/`"closed-annual"`, `recurring` → `"open-recurring"`/`"closed-recurring"`, `holiday` → `"holiday"` (whether or not the holiday is open, as with `holidayPolicy: "open"`), `weekday` → `"regular"`/`"closed-weekday"`. `"open-annual"` exists only for calendars made this way, since `closedAnnual` of `createCalendar` only closes. `name`, `holiday`, `shiftedFrom` and `rulePath` are the schedule's
478
+ - Holidays, the time zone and `outOfRange` are the schedule's. Diagnose the schedule's options with `diagnoseSchedule`; the calendar itself is not diagnosed. `maxSearchDays` (default 3660) can be given in the options
479
+ - Use `createCalendar` when you only need open or closed; use this when you have a schedule anyway
480
+
453
481
  ### Date and date-time inputs
454
482
 
455
483
  Every method accepts the following inputs. Returned dates are always `"YYYY-MM-DD"` strings.
@@ -22,7 +22,7 @@ import { type DateString, type Weekday } from "./date.ts";
22
22
  import { IssueCollector } from "./errors.ts";
23
23
  import { type DateInput } from "./input.ts";
24
24
  import { type MonthString } from "./month.ts";
25
- import { type CompiledSchedule, type DayOfMonth, type EffectivePeriod, type RecurringRule, type HolidayLookup, type HolidaySourceOptions } from "./schedule.ts";
25
+ import { type CompiledSchedule, type DayOfMonth, type EffectivePeriod, type RecurringRule, type HolidayLookup, type HolidaySourceOptions, type Schedule } from "./schedule.ts";
26
26
  import type { Holiday } from "./types.ts";
27
27
  /**
28
28
  * 祝日の扱い。
@@ -93,7 +93,7 @@ export interface CalendarOptions<Kind extends string = string> extends HolidaySo
93
93
  * 営業・休業を決めた規則(既知の値)。
94
94
  * @public
95
95
  */
96
- export type KnownDayReason = "open-date" | "closed-date" | "closed-annual" | "open-recurring" | "closed-recurring" | "holiday" | "closed-weekday" | "regular";
96
+ export type KnownDayReason = "open-date" | "closed-date" | "open-annual" | "closed-annual" | "open-recurring" | "closed-recurring" | "holiday" | "closed-weekday" | "regular";
97
97
  /**
98
98
  * 営業・休業を決めた規則。将来の版で値が増えることがあるので、分岐では「その他」も扱うこと。
99
99
  * すべての値を網羅したことを型で確かめたい場合は KnownDayReason を使う。
@@ -255,4 +255,21 @@ export declare function createCalendar<Kind extends string = string>(options?: C
255
255
  * @public
256
256
  */
257
257
  export declare function combineCalendars<Kind extends string = string>(calendars: readonly Calendar<Kind>[], options: CombineOptions): Calendar<Kind>;
258
+ /**
259
+ * スケジュール(createSchedule)から営業日カレンダーを作る。isOpen が true を返す値の日を営業日とする。
260
+ * 営業時間表のような日ごとの値が設定の正本で、営業日の計算(加減算・調整・期日など)も同じ設定から行いたいときに使う
261
+ * (営業日カレンダーを別に書いて同期を取る必要がなくなる)。
262
+ *
263
+ * - isOpen は値だけで決まる純粋な関数であること(日付・時刻・外部の状態を見ない)。営業日の探索は isOpen を繰り返し呼ぶので、
264
+ * 結果が変わる関数を渡すと探索の結果が呼ぶたびに変わる。日付で変えたい条件は、スケジュールの規則(dates・recurring)に書く
265
+ * - dayInfo の reason は、スケジュールの reason と営業・休業の組み合わせ(date → "open-date"/"closed-date"、annual → "open-annual"/
266
+ * "closed-annual"、recurring → "open-recurring"/"closed-recurring"、holiday → "holiday"、weekday → "regular"/"closed-weekday")。
267
+ * name・holiday・shiftedFrom・rulePath はスケジュールの結果をそのまま引き継ぐ
268
+ * - 祝日の判定(holiday・isHoliday など)・タイムゾーン・outOfRange はスケジュールのもの。規則の診断(diagnoseSchedule)は
269
+ * スケジュールの設定に対して行う
270
+ * @public
271
+ */
272
+ export declare function createCalendarFromSchedule<T, Kind extends string = string>(schedule: Schedule<T, Kind>, isOpen: (value: T) => boolean, options?: {
273
+ readonly maxSearchDays?: number;
274
+ }): Calendar<Kind>;
258
275
  export {};
@@ -22,7 +22,7 @@ import { addDays, daysInMonth, formatDate, fromDayNumber, toDayNumber, } from ".
22
22
  import { checkUnknownKeys, IssueCollector, plainError, rangeError } from "./errors.js";
23
23
  import { parseTimeOfDay, toCivil } from "./input.js";
24
24
  import { dayOfMonth, isDayOfMonthValue, parseMonth } from "./month.js";
25
- import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, isWeekday, mapDays, RECURRING_RULE_KEYS, } from "./schedule.js";
25
+ import { buildSchedule, compileAnnualRules, compileDateRules, compileHolidaySource, compileRecurringRules, createHolidayLookup, infoOfSchedule, isWeekday, mapDays, RECURRING_RULE_KEYS, } from "./schedule.js";
26
26
  const CALENDAR_OPTION_KEYS = [
27
27
  "holidays",
28
28
  "timeZone",
@@ -100,54 +100,62 @@ export function createCalendar(options = {}) {
100
100
  c.throwFirstError();
101
101
  const { maxSearchDays } = compiled;
102
102
  const schedule = buildSchedule(compiled.schedule);
103
- function info(date) {
103
+ const info = (date) => {
104
104
  const day = schedule.dayInfo(date);
105
- let reason;
106
- // 内部では閉じた型(KnownScheduleReason)で分岐し、値が増えたときの対応漏れを型で検出する
107
- const known = day.reason;
108
- switch (known) {
109
- case "date":
110
- reason = day.value ? "open-date" : "closed-date";
111
- break;
112
- case "annual":
113
- reason = "closed-annual";
114
- break;
115
- case "recurring":
116
- reason = day.value ? "open-recurring" : "closed-recurring";
117
- break;
118
- case "holiday":
119
- reason = "holiday";
120
- break;
121
- case "weekday":
122
- reason = day.value ? "regular" : "closed-weekday";
123
- break;
124
- default: {
125
- const unreachable = known;
126
- throw plainError("invalid-option", `Unexpected schedule reason: ${String(unreachable)}`);
127
- }
105
+ return dayInfoFromScheduleDay(day, day.value);
106
+ };
107
+ return buildCalendar(schedule, (date) => schedule.valueOn(date), info, maxSearchDays);
108
+ }
109
+ /**
110
+ * @internal スケジュールの 1 日分の結果(値は営業日か)を、営業日カレンダーの結果に変換する。
111
+ * reason はスケジュールの reason と営業・休業の組み合わせで決まる。createCalendar の closedAnnual は休業だけなので
112
+ * "open-annual" にはならないが、createCalendarFromSchedule では annual の値で営業になる日がある
113
+ */
114
+ function dayInfoFromScheduleDay(day, open) {
115
+ let reason;
116
+ // 内部では閉じた型(KnownScheduleReason)で分岐し、値が増えたときの対応漏れを型で検出する
117
+ const known = day.reason;
118
+ switch (known) {
119
+ case "date":
120
+ reason = open ? "open-date" : "closed-date";
121
+ break;
122
+ case "annual":
123
+ reason = open ? "open-annual" : "closed-annual";
124
+ break;
125
+ case "recurring":
126
+ reason = open ? "open-recurring" : "closed-recurring";
127
+ break;
128
+ case "holiday":
129
+ reason = "holiday";
130
+ break;
131
+ case "weekday":
132
+ reason = open ? "regular" : "closed-weekday";
133
+ break;
134
+ default: {
135
+ const unreachable = known;
136
+ throw plainError("invalid-option", `Unexpected schedule reason: ${String(unreachable)}`);
128
137
  }
129
- const result = {
130
- date: day.date,
131
- weekday: day.weekday,
132
- businessDay: day.value,
133
- reason,
134
- };
135
- // 曜日で決まった日には名前を付けない(祝日名は holiday で分かる)
136
- if (day.name !== undefined && day.reason !== "weekday")
137
- result.name = day.name;
138
- if (day.holiday !== undefined)
139
- result.holiday = day.holiday;
140
- if (day.shiftedFrom !== undefined)
141
- result.shiftedFrom = day.shiftedFrom;
142
- if (day.rulePath !== undefined)
143
- result.rulePath = day.rulePath;
144
- return Object.freeze(result);
145
138
  }
146
- return buildCalendar(schedule, (date) => schedule.valueOn(date), info, maxSearchDays);
139
+ const result = {
140
+ date: day.date,
141
+ weekday: day.weekday,
142
+ businessDay: open,
143
+ reason,
144
+ };
145
+ // 曜日で決まった日には名前を付けない(祝日名は holiday で分かる)
146
+ if (day.name !== undefined && day.reason !== "weekday")
147
+ result.name = day.name;
148
+ if (day.holiday !== undefined)
149
+ result.holiday = day.holiday;
150
+ if (day.shiftedFrom !== undefined)
151
+ result.shiftedFrom = day.shiftedFrom;
152
+ if (day.rulePath !== undefined)
153
+ result.rulePath = day.rulePath;
154
+ return Object.freeze(result);
147
155
  }
148
156
  /**
149
157
  * @internal 祝日を調べる機能と 1 日分の判定から、営業日カレンダーの機能(探索・調整・月の営業日・期日)を組み立てる。
150
- * createCalendar と combineCalendars で共用する
158
+ * createCalendar・combineCalendars・createCalendarFromSchedule で共用する
151
159
  */
152
160
  function buildCalendar(lookup, isOpen, info, maxSearchDays) {
153
161
  const dateOf = lookup.dateOf;
@@ -386,3 +394,36 @@ export function combineCalendars(calendars, options) {
386
394
  }
387
395
  return buildCalendar(lookup, isOpen, info, maxSearchDays);
388
396
  }
397
+ /**
398
+ * スケジュール(createSchedule)から営業日カレンダーを作る。isOpen が true を返す値の日を営業日とする。
399
+ * 営業時間表のような日ごとの値が設定の正本で、営業日の計算(加減算・調整・期日など)も同じ設定から行いたいときに使う
400
+ * (営業日カレンダーを別に書いて同期を取る必要がなくなる)。
401
+ *
402
+ * - isOpen は値だけで決まる純粋な関数であること(日付・時刻・外部の状態を見ない)。営業日の探索は isOpen を繰り返し呼ぶので、
403
+ * 結果が変わる関数を渡すと探索の結果が呼ぶたびに変わる。日付で変えたい条件は、スケジュールの規則(dates・recurring)に書く
404
+ * - dayInfo の reason は、スケジュールの reason と営業・休業の組み合わせ(date → "open-date"/"closed-date"、annual → "open-annual"/
405
+ * "closed-annual"、recurring → "open-recurring"/"closed-recurring"、holiday → "holiday"、weekday → "regular"/"closed-weekday")。
406
+ * name・holiday・shiftedFrom・rulePath はスケジュールの結果をそのまま引き継ぐ
407
+ * - 祝日の判定(holiday・isHoliday など)・タイムゾーン・outOfRange はスケジュールのもの。規則の診断(diagnoseSchedule)は
408
+ * スケジュールの設定に対して行う
409
+ * @public
410
+ */
411
+ export function createCalendarFromSchedule(schedule, isOpen, options) {
412
+ const info = infoOfSchedule(schedule);
413
+ if (info === undefined) {
414
+ throw rangeError("invalid-argument", "schedule must be a schedule created by createSchedule");
415
+ }
416
+ if (typeof isOpen !== "function") {
417
+ throw rangeError("invalid-argument", "isOpen must be a function (value) => boolean");
418
+ }
419
+ const maxSearchDays = options?.maxSearchDays ?? 3660;
420
+ if (!Number.isInteger(maxSearchDays) || maxSearchDays < 1) {
421
+ throw rangeError("invalid-option", "maxSearchDays must be a positive integer");
422
+ }
423
+ const open = (date) => isOpen(info(date).value) === true;
424
+ return buildCalendar(schedule, open, (date) => {
425
+ const day = info(date);
426
+ // 変換は value を読まない(営業・休業は open で渡す)ので、boolean の値として扱ってよい
427
+ return dayInfoFromScheduleDay(day, isOpen(day.value) === true);
428
+ }, maxSearchDays);
429
+ }
@@ -429,7 +429,8 @@ type HolidayLookupInternal<Kind extends string> = ReturnType<typeof createHolida
429
429
  export declare function createResolver<T, Kind extends string>(compiled: CompiledSchedule<T, Kind>, lookup: HolidayLookupInternal<Kind>): (date: DateString) => Resolution<T, Kind>;
430
430
  /** @internal 期間(両端を含む)の日ごとに fn を呼んだ結果。from が to より後ならエラー */
431
431
  export declare function mapDays<R>(from: DateString, to: DateString, fn: (date: DateString) => R): readonly R[];
432
- /** @internal 検証済みの規則からスケジュールを作る */
432
+ /** @internal スケジュールの内部の判定を取り出す(createSchedule が作ったものでなければ undefined) */
433
+ export declare function infoOfSchedule<T, Kind extends string>(schedule: Schedule<T, Kind>): ((date: DateString) => ScheduleDay<T, Kind>) | undefined;
433
434
  export declare function buildSchedule<T, Kind extends string>(compiled: CompiledSchedule<T, Kind>): Schedule<T, Kind>;
434
435
  /**
435
436
  * 曜日・祝日・特定日の規則から、日ごとに値を返すスケジュールを作る。
@@ -774,6 +774,15 @@ export function mapDays(from, to, fn) {
774
774
  return Object.freeze(result);
775
775
  }
776
776
  /** @internal 検証済みの規則からスケジュールを作る */
777
+ /**
778
+ * @internal スケジュールの内部の判定(暦日の文字列を直接受け取る)。createCalendarFromSchedule が、公開メソッド
779
+ * (入力の解析を通る)を経由せずに 1 日分の結果を得るために使う。スケジュールごとに作成時に登録する
780
+ */
781
+ const internalInfo = new WeakMap();
782
+ /** @internal スケジュールの内部の判定を取り出す(createSchedule が作ったものでなければ undefined) */
783
+ export function infoOfSchedule(schedule) {
784
+ return internalInfo.get(schedule);
785
+ }
777
786
  export function buildSchedule(compiled) {
778
787
  const lookup = createHolidayLookup(compiled.source);
779
788
  const resolve = createResolver(compiled, lookup);
@@ -793,7 +802,9 @@ export function buildSchedule(compiled) {
793
802
  dayInfo: (input) => info(lookup.dateOf(input)),
794
803
  daysBetween: (from, to) => mapDays(lookup.dateOf(from), lookup.dateOf(to), info),
795
804
  };
796
- return Object.freeze(schedule);
805
+ Object.freeze(schedule);
806
+ internalInfo.set(schedule, info);
807
+ return schedule;
797
808
  }
798
809
  /**
799
810
  * 曜日・祝日・特定日の規則から、日ごとに値を返すスケジュールを作る。
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * 公開する API には TSDoc の @public(安定)または @beta(マイナー版で変わりうる)を付ける。
8
8
  * 公開する名前と型は etc/api.md に記録し、pnpm check で意図しない変化を検出する。
9
9
  */
10
- export { combineCalendars, createCalendar, type AdjustOptions, type AnnualDate, type AnnualRange, type BusinessDayConvention, type BusinessDayOptions, type Calendar, type CalendarOptions, type CombineOptions, type DateRange, type DayInfo, type DayReason, type DueDateOptions, type HolidayPolicy, type KnownDayReason, type SpecificDate, } from "./core/calendar.ts";
10
+ export { combineCalendars, createCalendar, createCalendarFromSchedule, type AdjustOptions, type AnnualDate, type AnnualRange, type BusinessDayConvention, type BusinessDayOptions, type Calendar, type CalendarOptions, type CombineOptions, type DateRange, type DayInfo, type DayReason, type DueDateOptions, type HolidayPolicy, type KnownDayReason, type SpecificDate, } from "./core/calendar.ts";
11
11
  export { createSchedule, type AnnualRangeValue, type AnnualValue, type CivilDateTimeParts, type DateRangeValue, type DateValue, type DayAfterHolidayPattern, type DayOfMonth, type DayOfMonthPattern, type EffectivePeriod, type HolidayLookup, type HolidayPattern, type HolidaySourceOptions, type HolidayValueRule, type KnownScheduleReason, type Month, type Nth, type OnHolidayRule, type RecurringPattern, type RecurringRule, type RecurringValue, type Schedule, type ScheduleDay, type ScheduleOptions, type ScheduleReason, type WeekdayPattern, } from "./core/schedule.ts";
12
12
  export { addDays, diffDays, isValidDate, weekdayOf, type DateString, type Weekday, } from "./core/date.ts";
13
13
  export { closingMonth, monthOf, type MonthString } from "./core/month.ts";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * 公開する API には TSDoc の @public(安定)または @beta(マイナー版で変わりうる)を付ける。
8
8
  * 公開する名前と型は etc/api.md に記録し、pnpm check で意図しない変化を検出する。
9
9
  */
10
- export { combineCalendars, createCalendar, } from "./core/calendar.js";
10
+ export { combineCalendars, createCalendar, createCalendarFromSchedule, } from "./core/calendar.js";
11
11
  export { createSchedule, } from "./core/schedule.js";
12
12
  export { addDays, diffDays, isValidDate, weekdayOf, } from "./core/date.js";
13
13
  export { closingMonth, monthOf } from "./core/month.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bizdays-toolkit",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
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. / 祝日と営業日のカレンダー(タイムゾーン対応・日本の祝日は内閣府、英国の bank holidays は GOV.UK のデータで全日照合)",
5
5
  "keywords": [
6
6
  "bank-holidays",