bizdays-toolkit 0.30.5 → 0.30.6
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 +35 -1
- package/dist/core/calendar.js +1 -1
- package/dist/core/diagnose.js +77 -9
- package/dist/core/schedule.d.ts +24 -2
- package/dist/core/schedule.js +17 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,39 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.30.6] - 2026-11-02
|
|
8
|
+
|
|
9
|
+
テスト拡充案の第 2 段です。失敗を注入した祝日の提供元と API どうしの整合の検査で見つけた不具合を 3 つ(判定 1・診断 2)直したので、公開物の `.js` は 0.30.5 から変わります(Fixed)。合成したカレンダーの既知の不具合(0.31.0 で直す)を文書に書きました。
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `holidayPolicy: "ignore"` で、祝日に従属する規則(`holiday`・`dayAfterHoliday`・`dayBeforeHoliday`・`"after-holiday"`)も祝日の上で先に判定する規則(`"over-holiday"`)もない設定で、`unconfirmedHolidayPolicy: "throw"` のとき、営業日の判定・第 n 営業日の数え方・探索(`isBusinessDay`・`valueOn`・`addBusinessDays` など。スケジュールから作ったカレンダーも)が未確定の祝日で `unconfirmed-holiday` を投げていた。そのような設定の結果は祝日に依存せず、ガイドは「結果は変わらない」、設定の診断もその `unconfirmedHolidayPolicy` を `redundant`(効き目がない)と言っているので、文書と診断に合わせてコードを直す。複数のマイナー版を経た挙動だが、投げていた判定が投げなくなる向きの修正で、結果の値は変わらない。`dayInfoOn`・`daysBetween` は `holiday` を付けるために祝日を引くので、今までどおり投げる。対応年の外(`out-of-range`)と提供元のデータの誤り(`invalid-provider-data`)は、今までどおり投げる(失敗を注入した祝日の提供元のテストで見つけた。種類は例外の経路の未検証)
|
|
14
|
+
- 診断: `holidayPolicy: "ignore"` で祝日の上で先に判定する規則(`"over-holiday"`)がある設定でも、`unconfirmedHolidayPolicy: "throw"` を `redundant`(結果に影響しない)と出していた。祝日の日だけ `"over-holiday"` の規則が先に判定されるので、そのような設定の結果は祝日に依存し、`"throw"` は判定を投げさせる。「結果が祝日に依存しない設定」の判定を 1 つの関数にまとめ、判定(未確定の祝日で投げるか)と診断(`redundant` か)の両方がそれを使うようにした。誤った診断を直す修正で、判定の結果は変わらない(上の修正の条件を決めるときに見つけた。診断が `redundant` と出した設定で `"throw"` を `"accept"` に変えても全日の判定が変わらないことを、目録の設定で確かめるテストを足した。種類は正解と突き合わせる仕組みの不足)
|
|
15
|
+
- 診断: スケジュールの第 n 営業日の規則の数える基準のカレンダー(`calendar`)が投げる月(対応年の外、`unconfirmedHolidayPolicy: "throw"` の未確定の祝日)を、診断が誤って `error`・`never-matches` にしていた。`createSchedule` は成功し、基準のカレンダーが投げない月の判定も投げないのに、対応年が診断の走査の範囲(提供元のないスケジュールの 2001 年からの周期や、規則の形を調べる代表の 28 年間)を覆わない基準(同梱のシンガポール(2020 年〜)など)では `error` の `out-of-range`(`path` は `holidayProvider`)を、未確定の祝日で投げる基準では `error` の `invalid-provider-data` を出していた。診断は、基準のカレンダーを評価して投げた月だけを「判定できない月」として扱い(その月は規則が当てはまらないとみなす)、有効期間に判定できない月がある項目には `never-matches`・`redundant` を出さないようにした(分からないことは言わない)。`shadowed` は規則の形だけで決まり、基準のカレンダーを評価しないので、今までどおり出す。範囲を前もって計算しないので、合成したカレンダーなどの基準でも、基準のカレンダーが判定できる月は今までどおり診断する。誤った診断をなくす修正で、判定の結果は変わらない(result-compare の意図した差分 `schedule-counting-basis-narrower-than-scan` に登録した)。提供元のないスケジュールに提供元のある基準のカレンダーを使う設定の判定が、基準のカレンダーの対応年の外の月で投げることをガイドの「対応年の外」に書いた(診断で知らせるかは 0.31.0 以降で判断する)(API どうしの整合の検査で見つけた。取り込みで見つかった、合成した基準での誤った never-matches の退行もあわせて直した。種類は API どうしの食い違い)
|
|
16
|
+
|
|
17
|
+
### 既知の不具合
|
|
18
|
+
|
|
19
|
+
- 合成したカレンダーの営業日の判定(`isBusinessDay` や探索)は、`open: "all"` では先のカレンダーが休業日、`open: "any"` では先のカレンダーが営業日と決めた時点で後のカレンダーを判定しないので、後のカレンダーが投げる日(未確定の祝日・提供元の誤りなど)でも投げないことがある(並び順で変わる)。ガイドの「合成したカレンダーは、どれかのカレンダーが投げるなら投げます」から外れる。直すと新たに投げる判定ができるので、0.31.0(マイナー版)で直す。ガイドの該当の箇条に注を足し、確かめるテストは `todo` にした
|
|
20
|
+
|
|
21
|
+
### 開発
|
|
22
|
+
|
|
23
|
+
- サイズの上限: 上限を 25,800 から 26,500 に上げた `./diagnose`(測定 26,158)。理由: Fixed の 3 件目(基準のカレンダーが投げる月を判定できない月として扱い、確かでない診断を出さない)の修正で増えたため。0.31.0 の P1 の分は見込まず、そのときにあらためて測って上げる
|
|
24
|
+
- 診断のオラクル: カナリア(完全性の報告に必ず出る設定)が取り除ける理由を確かめた。開く規則「5・7 月の月曜」が開きうる祝日(自作の提供元の 5・7 月の月曜の祝日)を、`holidayOverlapPolicy` の既定(`"under-holiday"`)では開かないため。`"over-holiday"` にすると取り除けなくなることを確かめるテストを足し、コメントの理由を直した(コメントの主張を確かめていなかった穴。種類 C)
|
|
25
|
+
- 診断のオラクル: `ORACLE_FULL` なしの `ORACLE_SHARD` を例外にした(`pnpm check` の抜き出しの間隔 111 と分ける数の公約数で、分が 0 件になっていた)。どのテストも、試した設定が 0 件なら失敗にする。失敗のメッセージを 1 つの関数にまとめ、設定を作り直せる情報(項目・休業日の扱いの方針・定休日・取り除いた項目)を入れた(黙って空振りする穴。種類 C)
|
|
26
|
+
- 生成範囲: 危険の分かっている組み合わせ(第 n 営業日(月・週)× 個別の日付、第 n 営業日(月)× 毎年の月日、祝日の規則 × 臨時営業日、祝日の翌日・前日 × `skipWeekdays` × 個別の日付、和集合の提供元 × `kinds`)の一覧(`test/support/combinations.ts`)を作り、呼び出し側ごとに 1 回以上作ることを確かめる(作れない組み合わせは事実の理由を付けて除く)。個々の特徴の包含だけでは組み合わせを守れなかった(生成器の偏りの穴。種類 A)
|
|
27
|
+
- 生成範囲: `test/properties.test.ts` の性質は、設定を作る乱数(性質の名前から決まる種の列)と、日付などを引く乱数を分けた。性質と設定の作り方の対応は `test/support/sites.ts` の `PROPERTY_CONFIGS` に書き、性質が実際に使った作り方と同じかを確かめる。これで生成範囲の包含のテストが properties の設定を並びまで再現し、テストとスクリプトの特徴が一致する(どちらも 414 件。0.30.5 は近似でテスト 408 件・スクリプト 413 件)(種類 A)
|
|
28
|
+
- API どうしの整合の検査(`test/consistency.test.ts`)を入れた。目録の生成器の設定(カレンダー・スケジュール、対応年の短い自作の提供元・提供元なし)で、同じことを別の API で問うたときの答えが一致することを確かめる: 各日の判定(`isBusinessDay`・`dayInfoOn`・`daysBetween`、スケジュールは `valueOn`)、次・前の営業日、営業日の加算と差、第 n 営業日の規則と基準のカレンダーの第 n 営業日、診断の `error` と作成の成否・エラーコード、移行(`migrate…` した設定に `deprecated-option` が残らない・2 回かけても変わらない・前後で結果が同じ)。各日の判定と移行は、既定の `"throw"` を隣の年を引かない内側の範囲で、`"ignore"` を対応年の全範囲で試す。関係ごとに試した設定の数を出し、0 件なら失敗にする。`pnpm check` は決まった抜き出し、全件は `CONSISTENCY_API_FULL=1` で CI の `diagnose-consistency` ジョブ(API どうしの食い違いの穴。種類 A)
|
|
29
|
+
- 検査のスクリプトの検査の直し: 取り込み中の変更を `git status -z` で読む(日本語・スペースを含むパスを写せなかった)。写したファイルを出力に出す。result-compare・check-readme-examples の失敗の期待を、検査が誤りの理由として出す文(「**失敗**(意図した変更なら…」「expected "…"」)にした(別の理由で失敗しても合格になっていた)。写し・ビルドの途中の例外でも、表と後始末の問題を出してから失敗で終わる。対照の実行で SKIP の行が出たら失敗にする。飛ばしの決まり: `skipWhen` は skip と todo の取り違えを、`todoFor` は一覧にない理由を、CI でなくても飛ばす条件にかかわらず投げる。省略記法の grep の限界(複数行のオブジェクトの `skip,` は拾わない)を書き、`test/support/skip.ts` の冒頭の「CI」の意味を実装に合わせた(黙って外れる穴。種類 C)
|
|
30
|
+
- 検査のスクリプトそのものの検査(`scripts/tool-selftest.ts`。CI の `tool-selftest` ジョブ)を入れた。リポジトリの写し(`git worktree add` の作業ツリーに取り込み中の変更を写し、`node_modules` はリンクでつなぐ。前の版のタグも読める)を一時ディレクトリ(`TOOL_SELFTEST_DIR`)に作り、誤りを入れずに 8 つの検査(`check-package`・`check-size`・`check-readme-examples`・`check-names`・`api-report`・`bench-compare`・`result-compare`・`data-compare`)が合格することを確かめてから、誤りを 1 つずつ(計 12)入れて、どれも失敗し入れた誤りを指す文を出すことを確かめる。後始末は、リンクを先に外し、外せなければ(まだ作っていない場合のほかは)リンクの先まで消えないよう何も消さずに残して失敗にし、最後にリポジトリの `node_modules` が残っていることを確かめる。検査のスクリプトは変えていない(検査の検査がない穴。種類 B)
|
|
31
|
+
- `catch` 節の到達の検査: 除外の一覧の名前が 2 つ以上の節で重なるときと、節の文が `try` と同じ行にあるとき(行で数える lcov では判定できない)を失敗にした。`--lcov` は検査そのものを試すための引数で CI は使わないことを書いた。飛ばしの決まり: `skipWhen` は飛ばす条件にかかわらず理由が一覧にあるかを確かめ、grep の対象に `test/support/*.ts` と省略記法(`{ skip }`)を加えた。`RELEASING.md` に、grep で止められる範囲の限界(早い `return`・`continue` は個別の仕組みで守る)と、「CI」の意味(環境変数 `CI` が空でも `"false"` でもないとき)を書いた(種類 C)
|
|
32
|
+
- `catch` 節の到達の検査(`scripts/check-catch-coverage.ts`。CI の `catch-coverage` ジョブ)を入れた。Node.js の組み込みのカバレッジでテストを動かし、TypeScript のコンパイラーの API で見つけた `src/core` の `catch` 節(13 か所)の中の行が通ったかを lcov と突き合わせ、通らない節は理由付きの除外の一覧(「ファイル・関数・節の中の最初の文」で引く。今は空)に載せない限り失敗にする。通っていなかった診断の 6 か所(提供元の例外を受け止める経路)には、途中から例外を投げる提供元(`throwingAfter`。提供元の約束の外)で届くテスト(`test/catch-paths.test.ts`)を足した(例外の経路の穴。種類 C)
|
|
33
|
+
- 飛ばしの決まり: 前提がそろわないときに飛ばす箇所を補助の関数(`test/support/skip.ts` の `skipWhen`・`todoFor`)に集め、理由を意図した飛ばしの一覧から引くようにした(タイムゾーンを変えた実行、`ORACLE_JOINT`、Temporal のない実行環境、手元で前の版のタグが読めないとき、合成の既知の不具合の `todo`)。CI では、一覧にない理由と CI では飛ばさない理由を失敗にする。補助の関数を通さない飛ばしは grep の検査(`test/skip-policy.test.ts`)が止める(黙って飛ばす穴。種類 C)
|
|
34
|
+
- 診断と判定の一致のテストの全件(150 件)を、`CONSISTENCY_FULL=1` で CI の `diagnose-consistency` ジョブで動かす(`pnpm check` は 12 件)。スケジュールから作ったカレンダーのテストで、`daysBetween` も未確定の祝日で投げることを確かめ、スケジュールの第 n 営業日の規則が基準のカレンダーを必須とする理由をコメントに書いた
|
|
35
|
+
- 失敗を注入する祝日の提供元(`test/support/faulty.ts`。特定の年で例外を投げる・ある年だけ不正なデータ(日付の書式・重複・型の違う項目)を返す・途中の年を未確定にする)を作り、判定・診断・合成の結果が文書のとおりかを確かめるテスト(`test/faulty-provider.test.ts`)を足した。文書が何も言っていなかった組み合わせ(例外を投げる提供元の判定・合成・診断、不正なデータの提供元の合成、未確定の祝日の診断)は、今の挙動を約束として `docs/providers.ja.md`・`docs/providers.md` の「提供元の約束と誤りの扱い」に書き、テストで確かめる。提供元の約束に「`holidaysInYear` は同じ年に同じ結果を返す」を足し、途中から例外を投げる提供元は約束の外とした(例外の経路の穴。種類 C)
|
|
36
|
+
- 診断のオラクル: カナリアの理由のテストで、`"over-holiday"` の開く規則を実際に取り除くと全日の結果が変わることまで確かめる。`test/properties.test.ts`: `PROPERTY_CONFIGS` に古い名前が残っていないこと、性質が 1 回の試行で 1 回だけ設定を作ることも確かめる。`scripts/record-generator-features.ts`: 作業ツリーの指定を真偽値で持ち、`"worktree"` という名前の参照と取り違えない。`RELEASING.md`・オラクルの冒頭のコメント: タイムゾーンを変えた実行で飛ばすのはオラクルの総当たりで、カナリアの 2 件は動かすと直した
|
|
37
|
+
- `scripts/record-generator-features.ts`: 作業ツリーは `--worktree` で指すようにした。`--ref HEAD`(git ではコミットを指す名前)は、`--worktree` を案内する使い方の誤りにした。CI の `generator-features` ジョブも `--worktree --check` にした
|
|
38
|
+
- `RELEASING.md`: オラクルと生成範囲の行を実装と 1 文ずつ突き合わせ、消えていた「タイムゾーンを変えた実行では、オラクルと日本の全範囲の走査を飛ばす」を戻し、組み合わせの一覧の検査・カナリアの理由の確認・0 件の検査・`ORACLE_SHARD` の条件・CI の実測の時間を書いた
|
|
39
|
+
|
|
7
40
|
## [0.30.5] - 2026-11-01
|
|
8
41
|
|
|
9
42
|
0.30.4 の品質基盤の補修です。公開物の `.js` は 0.30.4 と同じです。0.30.4 で、品質基盤が「動いているように見えて、実は見ていない」箇所と、乱数のテストの生成範囲が縮んだ箇所が見つかったので、それだけを直しました。テスト拡充案の段の番号を 1 つずつずらし、第 2 段は 0.30.6、第 3 段は 0.30.7 で出します。
|
|
@@ -826,7 +859,8 @@
|
|
|
826
859
|
|
|
827
860
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
828
861
|
|
|
829
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.
|
|
862
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.6...HEAD
|
|
863
|
+
[0.30.6]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.5...v0.30.6
|
|
830
864
|
[0.30.5]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.4...v0.30.5
|
|
831
865
|
[0.30.4]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.3...v0.30.4
|
|
832
866
|
[0.30.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.2...v0.30.3
|
package/dist/core/calendar.js
CHANGED
|
@@ -405,7 +405,7 @@ export function createCalendarFromSchedule(schedule, isOpen, options) {
|
|
|
405
405
|
if (!Number.isInteger(searchDayLimit) || searchDayLimit < 1) {
|
|
406
406
|
throw rangeError("invalid-option", "searchDayLimit must be a positive integer");
|
|
407
407
|
}
|
|
408
|
-
const open = (date) => isOpen(
|
|
408
|
+
const open = (date) => isOpen(schedule.valueOn(date)) === true;
|
|
409
409
|
return buildCalendar(schedule, open, (date) => {
|
|
410
410
|
const day = info(date);
|
|
411
411
|
return dayInfoFromScheduleDay(day, isOpen(day.value) === true, true);
|
package/dist/core/diagnose.js
CHANGED
|
@@ -2,7 +2,7 @@ import { lengthOfMonth, fromDayNumber, isValidDate, parseDate, toDayNumber, week
|
|
|
2
2
|
import { compileCalendarOptions } from "./calendar.js";
|
|
3
3
|
import { IssueCollector, rangeError } from "./errors.js";
|
|
4
4
|
import { RENAMED_KEYS, RENAMED_VALUES } from "./renamed.js";
|
|
5
|
-
import { compileScheduleOptions, createBasis, createHolidayLookup, createResolver, inPeriod, jpUsage, matchMonthDay, matchPattern, } from "./schedule.js";
|
|
5
|
+
import { compileScheduleOptions, createBasis, createHolidayLookup, createResolver, inPeriod, jpUsage, matchMonthDay, matchPattern, isHolidayBasedRule, resultIgnoresHolidays, } 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++) {
|
|
@@ -240,7 +240,79 @@ function checkProviderData(c, source) {
|
|
|
240
240
|
});
|
|
241
241
|
return ok;
|
|
242
242
|
}
|
|
243
|
-
|
|
243
|
+
const UNJUDGEABLE = new Set(["out-of-range", "unconfirmed-holiday"]);
|
|
244
|
+
function guardBases(compiled, unknownMonths) {
|
|
245
|
+
if (!compiled.recurring.some((r) => r.basis !== null && r.calendar !== null))
|
|
246
|
+
return compiled;
|
|
247
|
+
return {
|
|
248
|
+
...compiled,
|
|
249
|
+
recurring: compiled.recurring.map((r) => {
|
|
250
|
+
const basis = r.basis;
|
|
251
|
+
if (basis === null || r.calendar === null)
|
|
252
|
+
return r;
|
|
253
|
+
return {
|
|
254
|
+
...r,
|
|
255
|
+
basis: (year, month) => {
|
|
256
|
+
try {
|
|
257
|
+
return basis(year, month);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
if (!UNJUDGEABLE.has(String(error.code)))
|
|
261
|
+
throw error;
|
|
262
|
+
unknownMonths.add(year * 12 + month - 1);
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const UNSURE_CODES = new Set(["never-matches", "redundant"]);
|
|
271
|
+
function dropUnsure(c, from, compiled, unknownMonths) {
|
|
272
|
+
const monthOf = (day) => {
|
|
273
|
+
const { year, month } = parseDate(fromDayNumber(day));
|
|
274
|
+
return year * 12 + month - 1;
|
|
275
|
+
};
|
|
276
|
+
const overlaps = (start, end) => {
|
|
277
|
+
const a = start === null ? -Infinity : monthOf(start);
|
|
278
|
+
const b = end === null ? Infinity : monthOf(end);
|
|
279
|
+
for (const m of unknownMonths)
|
|
280
|
+
if (m >= a && m <= b)
|
|
281
|
+
return true;
|
|
282
|
+
return false;
|
|
283
|
+
};
|
|
284
|
+
const indexed = (path, name) => {
|
|
285
|
+
const m = new RegExp(`^${name}\\[(\\d+)\\]$`).exec(path);
|
|
286
|
+
return m ? Number(m[1]) : undefined;
|
|
287
|
+
};
|
|
288
|
+
const unsure = (path) => {
|
|
289
|
+
const r = indexed(path, "recurringRules");
|
|
290
|
+
const rule = r === undefined ? undefined : compiled.recurring[r];
|
|
291
|
+
if (rule !== undefined)
|
|
292
|
+
return overlaps(rule.effectiveFrom, rule.effectiveTo);
|
|
293
|
+
const a = indexed(path, "annualDates");
|
|
294
|
+
const annual = a === undefined ? undefined : compiled.annual[a];
|
|
295
|
+
if (annual !== undefined)
|
|
296
|
+
return overlaps(annual.effectiveFrom, annual.effectiveTo);
|
|
297
|
+
const d = indexed(path, "dates");
|
|
298
|
+
const date = d === undefined ? undefined : compiled.dates[d];
|
|
299
|
+
if (date !== undefined)
|
|
300
|
+
return overlaps(date.from, date.to);
|
|
301
|
+
return true;
|
|
302
|
+
};
|
|
303
|
+
const kept = c.issues.slice(from).filter((d) => !(UNSURE_CODES.has(d.code) && unsure(d.path)));
|
|
304
|
+
c.issues.length = from;
|
|
305
|
+
c.issues.push(...kept);
|
|
306
|
+
}
|
|
307
|
+
function analyze(c, original, isCalendar) {
|
|
308
|
+
const unknownMonths = new Set();
|
|
309
|
+
const compiled = guardBases(original, unknownMonths);
|
|
310
|
+
const from = c.issues.length;
|
|
311
|
+
analyzeRules(c, compiled, isCalendar);
|
|
312
|
+
if (unknownMonths.size > 0)
|
|
313
|
+
dropUnsure(c, from, compiled, unknownMonths);
|
|
314
|
+
}
|
|
315
|
+
function analyzeRules(c, compiled, isCalendar) {
|
|
244
316
|
const { source, dates, annual, recurring } = compiled;
|
|
245
317
|
if (!checkProviderData(c, source))
|
|
246
318
|
return;
|
|
@@ -358,7 +430,7 @@ function analyze(c, compiled, isCalendar) {
|
|
|
358
430
|
[...a.skipWeekdays].every((w) => b.skipWeekdays.has(w));
|
|
359
431
|
recurring.forEach((rule, j) => {
|
|
360
432
|
const bits = recurringBits[j];
|
|
361
|
-
const holidayBased = rule
|
|
433
|
+
const holidayBased = isHolidayBasedRule(rule);
|
|
362
434
|
const businessDayBased = rule.businessDays !== null;
|
|
363
435
|
const matches = holidayBased
|
|
364
436
|
? holidayRuleMatches(rule)
|
|
@@ -617,16 +689,12 @@ function checkUnconfirmedOption(c, compiled) {
|
|
|
617
689
|
if (compiled.source.unconfirmedHolidayPolicy !== "throw")
|
|
618
690
|
return;
|
|
619
691
|
const noProvider = compiled.source.providers.length === 0;
|
|
620
|
-
const holidayUnused = compiled
|
|
621
|
-
!compiled.recurring.some((r) => r.holiday ||
|
|
622
|
-
r.dayAfterHoliday ||
|
|
623
|
-
r.dayBeforeHoliday ||
|
|
624
|
-
r.holidayOverlapPolicy === "after-holiday");
|
|
692
|
+
const holidayUnused = resultIgnoresHolidays(compiled);
|
|
625
693
|
if (!noProvider && !holidayUnused)
|
|
626
694
|
return;
|
|
627
695
|
c.info("redundant", "unconfirmedHolidayPolicy", noProvider
|
|
628
696
|
? 'unconfirmedHolidayPolicy: "throw" has no effect: there is no holiday provider'
|
|
629
|
-
: `unconfirmedHolidayPolicy: "throw" has no effect on results: holidays are not used (holidayPolicy: "ignore" and no holiday-based rule); dayInfoOn still throws when it looks up the holiday to report`);
|
|
697
|
+
: `unconfirmedHolidayPolicy: "throw" has no effect on results: holidays are not used (holidayPolicy: "ignore" and no holiday-based, "after-holiday" or "over-holiday" rule); dayInfoOn still throws when it looks up the holiday to report`);
|
|
630
698
|
}
|
|
631
699
|
function run(c, compiled, isCalendar, asOf) {
|
|
632
700
|
if (compiled && !c.hasErrors) {
|
package/dist/core/schedule.d.ts
CHANGED
|
@@ -714,7 +714,8 @@ export declare function jpUsage(source: HolidaySource<string>): JpUsage;
|
|
|
714
714
|
export declare function compileHolidaySource<Kind extends string>(c: IssueCollector, options: Record<string, unknown>): HolidaySource<Kind>;
|
|
715
715
|
/** @internal 祝日を調べる機能を作る(設定は検証済みであること) */
|
|
716
716
|
export declare function createHolidayLookup<Kind extends string>(source: HolidaySource<Kind>): HolidayLookup<Kind> & {
|
|
717
|
-
|
|
717
|
+
/** allowUnconfirmed なら、未確定の祝日でも unconfirmedHolidayPolicy: "throw" で投げない(結果が祝日に依存しない判定) */
|
|
718
|
+
holidayOfDate(date: DateString, allowUnconfirmed?: boolean): Holiday<Kind> | undefined;
|
|
718
719
|
fromJp: FromJp;
|
|
719
720
|
};
|
|
720
721
|
/** @internal 検証済みのスケジュールの規則 */
|
|
@@ -744,11 +745,32 @@ export interface Resolution<Value, Kind extends string> {
|
|
|
744
745
|
readonly rule: DecidingRule<Value> | null;
|
|
745
746
|
}
|
|
746
747
|
type HolidayLookupInternal<Kind extends string> = ReturnType<typeof createHolidayLookup<Kind>>;
|
|
748
|
+
/** @internal 祝日に従属する規則か(祝日・祝日の翌日・祝前日。祝日を見て当てはまるかが決まる) */
|
|
749
|
+
export declare const isHolidayBasedRule: (rule: {
|
|
750
|
+
readonly holiday?: boolean;
|
|
751
|
+
readonly dayAfterHoliday?: boolean;
|
|
752
|
+
readonly dayBeforeHoliday?: boolean;
|
|
753
|
+
}) => boolean;
|
|
754
|
+
/**
|
|
755
|
+
* @internal 結果が祝日に依存しない設定か。祝日の扱いが "ignore" で、祝日に従属する規則(isHolidayBasedRule)も、
|
|
756
|
+
* 祝日に当たると振り替える規則("after-holiday")も、祝日の日だけ先に判定する規則("over-holiday")もないとき、
|
|
757
|
+
* 祝日の日と祝日でない日の判定は同じになる。判定(未確定の祝日で投げるか。createResolver)と、設定の診断
|
|
758
|
+
* (unconfirmedHolidayPolicy: "throw" が redundant か)の両方がこの関数を使う
|
|
759
|
+
*/
|
|
760
|
+
export declare function resultIgnoresHolidays(compiled: {
|
|
761
|
+
readonly holiday: unknown;
|
|
762
|
+
readonly recurring: readonly {
|
|
763
|
+
readonly holiday?: boolean;
|
|
764
|
+
readonly dayAfterHoliday?: boolean;
|
|
765
|
+
readonly dayBeforeHoliday?: boolean;
|
|
766
|
+
readonly holidayOverlapPolicy?: string;
|
|
767
|
+
}[];
|
|
768
|
+
}): boolean;
|
|
747
769
|
/**
|
|
748
770
|
* @internal 検証済みの規則から、1 日分の値と値を決めた規則を返す関数を作る。
|
|
749
771
|
* 規則の診断では、規則を取り除いた版と結果を比べるために、祝日を調べる機能(lookup)を共有して作る
|
|
750
772
|
*/
|
|
751
|
-
export declare function createResolver<Value, Kind extends string>(compiled: CompiledSchedule<Value, Kind>, lookup: HolidayLookupInternal<Kind>): (date: DateString) => Resolution<Value, Kind>;
|
|
773
|
+
export declare function createResolver<Value, Kind extends string>(compiled: CompiledSchedule<Value, Kind>, lookup: HolidayLookupInternal<Kind>): (date: DateString, withHoliday?: boolean) => Resolution<Value, Kind>;
|
|
752
774
|
/** @internal 期間(両端を含む)の日ごとに fn を呼んだ結果。from が to より後ならエラー */
|
|
753
775
|
export declare function mapDays<R>(from: DateString, to: DateString, fn: (date: DateString) => R): readonly R[];
|
|
754
776
|
/** @internal スケジュールの内部の判定を取り出す(createSchedule が作ったものでなければ undefined) */
|
package/dist/core/schedule.js
CHANGED
|
@@ -618,7 +618,7 @@ export function createBasis(compiled, lookup) {
|
|
|
618
618
|
if (!compiled.recurring.some((r) => r.businessDays !== null && r.basis === null))
|
|
619
619
|
return undefined;
|
|
620
620
|
const resolve = createResolver({ ...compiled, recurring: [] }, lookup);
|
|
621
|
-
return basisFromPredicate((date) => resolve(date).day.value === true);
|
|
621
|
+
return basisFromPredicate((date) => resolve(date, false).day.value === true);
|
|
622
622
|
}
|
|
623
623
|
function requiredValue(c) {
|
|
624
624
|
return (entry, path) => {
|
|
@@ -824,11 +824,14 @@ export function createHolidayLookup(source) {
|
|
|
824
824
|
}
|
|
825
825
|
return map;
|
|
826
826
|
}
|
|
827
|
-
function holidayOfDate(date) {
|
|
827
|
+
function holidayOfDate(date, allowUnconfirmed = false) {
|
|
828
828
|
if (providers.length === 0)
|
|
829
829
|
return undefined;
|
|
830
830
|
const h = holidayMap(parseDate(date).year).get(date);
|
|
831
|
-
if (h !== undefined &&
|
|
831
|
+
if (h !== undefined &&
|
|
832
|
+
!allowUnconfirmed &&
|
|
833
|
+
unconfirmedHolidayPolicy === "throw" &&
|
|
834
|
+
!h.confirmed) {
|
|
832
835
|
const year = parseDate(date).year;
|
|
833
836
|
const provider = providers.find((p) => year >= p.supportedYears.from &&
|
|
834
837
|
year <= p.supportedYears.to &&
|
|
@@ -971,9 +974,17 @@ export function matchMonthDay(rule, monthDay) {
|
|
|
971
974
|
export function matchAnnual(rule, date) {
|
|
972
975
|
return inPeriod(rule, toDayNumber(date)) && matchMonthDay(rule, date.slice(5));
|
|
973
976
|
}
|
|
977
|
+
export const isHolidayBasedRule = (rule) => rule.holiday === true || rule.dayAfterHoliday === true || rule.dayBeforeHoliday === true;
|
|
978
|
+
export function resultIgnoresHolidays(compiled) {
|
|
979
|
+
return (compiled.holiday === "ignore" &&
|
|
980
|
+
!compiled.recurring.some((r) => isHolidayBasedRule(r) ||
|
|
981
|
+
r.holidayOverlapPolicy === "after-holiday" ||
|
|
982
|
+
r.holidayOverlapPolicy === "over-holiday"));
|
|
983
|
+
}
|
|
974
984
|
export function createResolver(compiled, lookup) {
|
|
975
985
|
const { weekly, holiday: holidayRule, annual, dates, recurring } = compiled;
|
|
976
986
|
const hasShift = recurring.some((r) => r.holidayOverlapPolicy === "after-holiday");
|
|
987
|
+
const holidayUnused = resultIgnoresHolidays(compiled);
|
|
977
988
|
const basis = createBasis(compiled, lookup);
|
|
978
989
|
const holidayOfNeighbour = (date) => lookup.holidayOfDate(date);
|
|
979
990
|
const isHolidayOfNeighbour = (date) => holidayOfNeighbour(date) !== undefined;
|
|
@@ -987,10 +998,10 @@ export function createResolver(compiled, lookup) {
|
|
|
987
998
|
}
|
|
988
999
|
return undefined;
|
|
989
1000
|
}
|
|
990
|
-
return function resolve(date) {
|
|
1001
|
+
return function resolve(date, withHoliday = true) {
|
|
991
1002
|
const dayNumber = toDayNumber(date);
|
|
992
1003
|
const weekday = weekdayOf(date);
|
|
993
|
-
const holiday = lookup.holidayOfDate(date);
|
|
1004
|
+
const holiday = lookup.holidayOfDate(date, holidayUnused && !withHoliday);
|
|
994
1005
|
const make = (value, reason, rule, name, shiftedFrom) => {
|
|
995
1006
|
const result = {
|
|
996
1007
|
date,
|
|
@@ -1077,7 +1088,7 @@ export function buildSchedule(compiled) {
|
|
|
1077
1088
|
getHoliday: lookup.holidayOn,
|
|
1078
1089
|
holidaysInYear: lookup.holidaysInYear,
|
|
1079
1090
|
holidaysBetween: lookup.holidaysBetween,
|
|
1080
|
-
valueOn: (input) =>
|
|
1091
|
+
valueOn: (input) => resolve(lookup.dateOf(input), false).day.value,
|
|
1081
1092
|
dayInfoOn: (input) => info(lookup.dateOf(input)),
|
|
1082
1093
|
dayInfo: (input) => info(lookup.dateOf(input)),
|
|
1083
1094
|
daysBetween: (from, to) => mapDays(lookup.dateOf(from), lookup.dateOf(to), info),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.6",
|
|
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",
|