bizdays-toolkit 0.6.0 → 0.7.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 +12 -1
- package/README.md +20 -3
- package/dist/core/schedule.js +38 -1
- package/dist/core/types.d.ts +7 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.7.0] - 2026-10-16
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- 祝日(`Holiday`)に、ほかの言語の名称 `names`(省略可能。キーは BCP 47 の言語タグの正規の形。例: `{ "zh-Hant": "…", ko: "…" }`)を追加した。利用者が実装した提供元が付けた `names` を、提供元のデータの検証で確かめ(誤りは `invalid-provider-data`)、複製・凍結して返す。同梱の日本の祝日は `names` を持たない(公式の出典がある日本語・英語の名称だけを同梱する)
|
|
12
|
+
|
|
13
|
+
### 開発
|
|
14
|
+
|
|
15
|
+
- `size-limits.json` の値を上げるときの理由は、コミットメッセージではなく CHANGELOG の「開発」に書く取り決めにした。`pnpm check`(`scripts/check-size.ts`)が前の版のタグの `size-limits.json` と比べ、値が上がっているのに記載がなければ失敗する(0.6.0 で理由をコミットメッセージに書き漏らしたため)。CI とリリースのワークフローは履歴とタグを取得して(`fetch-depth: 0`)この確認を行い、リリースのワークフローではタグを付けたコミットを 1 つ前の版のタグと比べる
|
|
16
|
+
|
|
7
17
|
## [0.6.0] - 2026-10-16
|
|
8
18
|
|
|
9
19
|
### Added
|
|
@@ -148,7 +158,8 @@
|
|
|
148
158
|
|
|
149
159
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
150
160
|
|
|
151
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.
|
|
161
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.7.0...HEAD
|
|
162
|
+
[0.7.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.6.0...v0.7.0
|
|
152
163
|
[0.6.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.5.0...v0.6.0
|
|
153
164
|
[0.5.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.4.0...v0.5.0
|
|
154
165
|
[0.4.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.3.1...v0.4.0
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
- **月の期日**: 「20 日締め翌月 10 日払い(休業日なら翌営業日)」「月末の最終営業日」のような期日を、金融で使われる 4 つの調整方法(following・preceding・modified-following・modified-preceding)で計算します
|
|
24
24
|
- **営業日の計算**: 定休日の曜日・毎年の休業日(年末年始のような年をまたぐ期間も可)・臨時休業日・臨時営業日と祝日を組み合わせ、「N 営業日後」「締め時刻を過ぎたら翌営業日」などを計算します
|
|
25
25
|
- **タイムゾーンを間違えない**: `Date` などの瞬間は、カレンダーのタイムゾーン(日本は `Asia/Tokyo`)で暦日に変換してから判定します。UTC で動くサーバーでも、日本時間 0〜9 時が前日扱いになりません
|
|
26
|
-
- **軽量・依存ゼロ**: minify + gzip で約
|
|
26
|
+
- **軽量・依存ゼロ**: minify + gzip で約 7.4KB(日本の祝日込みで約 8.5KB)。ESM・型定義同梱・`sideEffects: false` で、Node.js・ブラウザー・Edge ランタイムで動作します
|
|
27
27
|
- **他の国・地域に拡張できる**: 祝日の提供元はインターフェース(`HolidayProvider`)で差し替えられます。現在は日本のみ同梱しています
|
|
28
28
|
|
|
29
29
|
[English](#english)
|
|
@@ -305,6 +305,23 @@ const myCountry: HolidayProvider = {
|
|
|
305
305
|
const calendar = createCalendar({ holidays: myCountry, closedWeekdays: [0, 6] });
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
+
祝日には、ほかの言語の名称を `names` で付けられます。キーは BCP 47 の言語タグの正規の形(`"zh-Hant"`・`"ko"` など)です。同梱の日本の祝日は `names` を持ちません(公式の出典がある日本語・英語だけを同梱しています)。必要な場合は、提供元を包んで付けます。
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import { jp } from "bizdays-toolkit/jp";
|
|
312
|
+
|
|
313
|
+
const zhHant: Record<string, string> = { "2026-01-01": "元日" /* … 利用者が用意した訳 */ };
|
|
314
|
+
const jpWithNames = {
|
|
315
|
+
...jp,
|
|
316
|
+
holidaysInYear: (year: number) =>
|
|
317
|
+
jp.holidaysInYear(year).map((h) => {
|
|
318
|
+
const name = zhHant[h.date];
|
|
319
|
+
return name === undefined ? h : { ...h, names: { "zh-Hant": name } };
|
|
320
|
+
}),
|
|
321
|
+
};
|
|
322
|
+
createCalendar({ holidays: jpWithNames }).getHoliday("2026-01-01")?.names; // { "zh-Hant": "元日" }
|
|
323
|
+
```
|
|
324
|
+
|
|
308
325
|
### 対応年の外
|
|
309
326
|
|
|
310
327
|
祝日の提供元の対応年(日本は 1955〜2099 年)を外れた日付を判定すると `RangeError` になります。祝日がない日として扱いたい場合は `outOfRange: "ignore"` を指定してください。
|
|
@@ -416,8 +433,8 @@ A business-day calendar that combines public holidays with company or store clos
|
|
|
416
433
|
- **Month-based due dates**: `adjust` with `following` / `preceding` / `modified-following` / `modified-preceding`, the nth / first / last business day of a month, `dueDate(month, { day, convention })`, and the calendar helpers `closingMonth` and `monthOf`
|
|
417
434
|
- **Business-day arithmetic**: closed weekdays, annual closures (including ranges across the new year), specific closed/open dates, holiday policy, `addBusinessDays`, cut-off times, and more
|
|
418
435
|
- **Time-zone safe**: instants (`Date`, ISO strings with offsets, Temporal) are converted to a civil date in the calendar's time zone before evaluation
|
|
419
|
-
- **Lightweight, zero dependencies**: about 7 KB min+gzip (about 8.
|
|
420
|
-
- **Extensible** through the `HolidayProvider` interface (only Japan is bundled for now)
|
|
436
|
+
- **Lightweight, zero dependencies**: about 7.4 KB min+gzip (about 8.5 KB with Japanese holidays), ESM, bundled types, `sideEffects: false`
|
|
437
|
+
- **Extensible** through the `HolidayProvider` interface (only Japan is bundled for now). Holidays can carry names in other languages via the optional `names` field (keys are canonical BCP 47 language tags); the bundled Japanese data includes only the officially sourced Japanese and English names
|
|
421
438
|
|
|
422
439
|
```ts
|
|
423
440
|
import { createCalendar } from "bizdays-toolkit";
|
package/dist/core/schedule.js
CHANGED
|
@@ -373,9 +373,46 @@ function loadProviderYear(provider, year) {
|
|
|
373
373
|
if (typeof confirmed !== "boolean") {
|
|
374
374
|
throw providerDataError(provider, year, `item ${i} (${date}) must have boolean confirmed`);
|
|
375
375
|
}
|
|
376
|
-
|
|
376
|
+
const holiday = {
|
|
377
|
+
date,
|
|
378
|
+
name,
|
|
379
|
+
nameEn,
|
|
380
|
+
kind: kind,
|
|
381
|
+
confirmed,
|
|
382
|
+
};
|
|
383
|
+
if (h["names"] !== undefined) {
|
|
384
|
+
const problem = checkNames(h["names"]);
|
|
385
|
+
if (problem)
|
|
386
|
+
throw providerDataError(provider, year, `item ${i} (${date}) names: ${problem}`);
|
|
387
|
+
holiday.names = Object.freeze(Object.fromEntries(Object.entries(h["names"])));
|
|
388
|
+
}
|
|
389
|
+
return Object.freeze(holiday);
|
|
377
390
|
});
|
|
378
391
|
}
|
|
392
|
+
/** 祝日のほかの言語の名称を検証する(誤りがあれば理由を返す) */
|
|
393
|
+
function checkNames(names) {
|
|
394
|
+
// 普通のオブジェクト(別の実行環境で作られたものも可)。継承した項目を持つものは受け付けない
|
|
395
|
+
const proto = isObject(names) ? Object.getPrototypeOf(names) : undefined;
|
|
396
|
+
if (!isObject(names) || (proto !== null && Object.getPrototypeOf(proto) !== null)) {
|
|
397
|
+
return "must be a plain object of { [language tag]: name }";
|
|
398
|
+
}
|
|
399
|
+
for (const [tag, value] of Object.entries(names)) {
|
|
400
|
+
let canonical;
|
|
401
|
+
try {
|
|
402
|
+
canonical = Intl.getCanonicalLocales(tag)[0];
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
return `${JSON.stringify(tag)} is not a BCP 47 language tag`;
|
|
406
|
+
}
|
|
407
|
+
if (canonical !== tag) {
|
|
408
|
+
return `${JSON.stringify(tag)} must be written in canonical form ${JSON.stringify(canonical)}`;
|
|
409
|
+
}
|
|
410
|
+
if (typeof value !== "string" || value === "") {
|
|
411
|
+
return `${JSON.stringify(tag)} must be a non-empty string`;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return undefined;
|
|
415
|
+
}
|
|
379
416
|
/** @internal 祝日を調べる機能を作る(設定は検証済みであること) */
|
|
380
417
|
export function createHolidayLookup(source) {
|
|
381
418
|
const { providers, timeZone, outOfRange } = source;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export interface Holiday<Kind extends string = string> {
|
|
|
10
10
|
readonly name: string;
|
|
11
11
|
/** 英語の名称 */
|
|
12
12
|
readonly nameEn: string;
|
|
13
|
+
/**
|
|
14
|
+
* ほかの言語の名称(省略可能)。キーは BCP 47 の言語タグの正規の形(例: "zh-Hant", "ko")。
|
|
15
|
+
* 同梱の提供元(日本)は持たない。利用者が実装した提供元が付けた場合に、検証して複製・凍結して返す
|
|
16
|
+
*/
|
|
17
|
+
readonly names?: Readonly<Record<string, string>>;
|
|
13
18
|
/** 種別(国ごとに定義。日本は JapaneseHolidayKind) */
|
|
14
19
|
readonly kind: Kind;
|
|
15
20
|
/**
|
|
@@ -23,7 +28,8 @@ export interface Holiday<Kind extends string = string> {
|
|
|
23
28
|
*
|
|
24
29
|
* 他の国・地域の祝日はこのインターフェースを実装して createCalendar・createSchedule に渡す。
|
|
25
30
|
* holidaysInYear が返すデータは、年ごとに初めて使うときに検証され、誤りがあれば
|
|
26
|
-
* code: "invalid-provider-data"
|
|
31
|
+
* code: "invalid-provider-data" の例外になる。返した祝日は、契約の項目(date・name・nameEn・names・
|
|
32
|
+
* kind・confirmed)だけを持つ変更できないオブジェクトに複製される。
|
|
27
33
|
*
|
|
28
34
|
* 互換性の約束: このインターフェースに項目を足すときは、メジャー版以外では省略可能な項目に限る。
|
|
29
35
|
* @public
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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. / 祝日と営業日のカレンダー(タイムゾーン対応・日本の祝日は内閣府データで全日照合)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bizdays",
|