bizdays-toolkit 0.31.2 → 0.31.3
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 +15 -1
- package/dist/core/calendar.d.ts +2 -1
- package/dist/core/calendar.js +39 -16
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/input.js +4 -1
- package/dist/core/names.d.ts +5 -0
- package/dist/core/names.js +24 -0
- package/dist/core/schedule.js +1 -22
- package/dist/provider/index.js +25 -10
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@ Entries from 0.31.0 are in English. Earlier entries remain in Japanese (their **
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.31.3] - 2026-11-09
|
|
10
|
+
|
|
11
|
+
This version fixes results that did not keep what the guide, the type descriptions and the design decisions promise. The results of valid calendars and schedules do not change, except that combined calendars no longer throw on days when none of their calendars throws.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Combined calendars (`combineCalendars`) threw on days when none of their calendars throws: the holidays were looked up in the union of the providers with one policy ("throw" if any calendar throws), so the policy of one calendar was applied to the providers of another. For example, a calendar with `unconfirmedHolidayPolicy: "throw"` and Japanese holidays combined with an English calendar threw `unconfirmed-holiday` in `dayInfoOn` for a predicted English holiday, while `isBusinessDay` returned a result. `dayInfoOn`, `isHoliday`, `holidayOn`, `holidaysInYear` and `holidaysBetween` now ask each calendar and throw only when one of them throws, as the guide says (the holiday shown is still the one of the earlier calendar). The rule is now written in the design decisions (17). Calls that threw now return values; other results are unchanged. When two calendars throw for different reasons on the same day, the code is now the one of the earlier calendar
|
|
16
|
+
- `adjust`, `closingMonth` and `closingPeriod` took an array, a function or a `Date` carrying a `convention` as their options; like `dueDate`, they now take only a plain object and throw `invalid-argument` otherwise (design decisions 8). If you passed such a value, pass a plain object
|
|
17
|
+
- `withSubstituteDays` (`bizdays-toolkit/provider`): `directions` with an explicit `undefined` weekday (such as `{ 0: "next", 6: undefined }`) threw; it is now the same as leaving the weekday out (design decisions 6). `directions` given as a `Map` or an array was taken as empty and added no substitute days; it now throws `invalid-argument`. `directions` with all seven weekdays searched until the end of the supported years and threw `out-of-range`; it now throws `invalid-argument` at once. The `names` of the returned holidays were the input objects; they are now frozen copies, as the type description says. `names` of the input holidays and the `name` and `nameEn` returned by `renameSubstitute` are now checked (`invalid-argument`) instead of being returned as they are
|
|
18
|
+
- A Temporal-like date (`{ year, month, day }`) with a year that is not an integer from 1000 to 9999 threw `out-of-range`, while the same date as a string, and a wrong month or day, threw `invalid-date`. It now throws `invalid-date`; `out-of-range` is left for dates computed from an instant or by date arithmetic outside the years 1000–9999 (design decisions 1). If you branch on `out-of-range` for such input, branch on `invalid-date`
|
|
19
|
+
- Error messages: the `month`, `weekday` and `n` of `bizdays-toolkit/provider`, the `dayOfMonth` of `dueDate` and the `date` of `toInstant` are shown in quotes when they are strings, like the other values (the codes are unchanged)
|
|
20
|
+
- Documentation: the guide said that the separator `t` in date-time strings is part of the `DateTimeInput` type; the type has only the upper-case `T`, and a lower-case `t` is accepted at run time (the `time` returned by `civilOf` is then typed `string | null`). The guide now also says that the policies of a combined calendar are a summary and that it throws only when one of its calendars throws
|
|
21
|
+
|
|
9
22
|
## [0.31.2] - 2026-11-09
|
|
10
23
|
|
|
11
24
|
This version fixes results that were not consistent between functions or did not match the type descriptions, and corrects the documentation. The results of valid calendars and schedules do not change.
|
|
@@ -872,7 +885,8 @@ This version rebuilds the `redundant` diagnostic so that the reported rules can
|
|
|
872
885
|
|
|
873
886
|
- 日本: 2026 年 2 月の官報(2027 年の春分・秋分の日)まで反映(`dataVersion: "2026-02"`、`confirmedThrough: 2027`)
|
|
874
887
|
|
|
875
|
-
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.
|
|
888
|
+
[Unreleased]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.3...HEAD
|
|
889
|
+
[0.31.3]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.2...v0.31.3
|
|
876
890
|
[0.31.2]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.1...v0.31.2
|
|
877
891
|
[0.31.1]: https://github.com/inohan77/bizdays-toolkit/compare/v0.31.0...v0.31.1
|
|
878
892
|
[0.31.0]: https://github.com/inohan77/bizdays-toolkit/compare/v0.30.9...v0.31.0
|
package/dist/core/calendar.d.ts
CHANGED
|
@@ -290,7 +290,8 @@ export declare function createCalendar<Kind extends string = string>(options?: C
|
|
|
290
290
|
*
|
|
291
291
|
* - dayInfoOn の reason・name・shiftedFrom・optionPath は、合成結果と同じ判定をした最初のカレンダーの結果で、
|
|
292
292
|
* その番号を decidedBy で返す。入れ子の合成では、内側の番号まで含めた列を decidedByPath で返す。
|
|
293
|
-
* holiday・isHoliday
|
|
293
|
+
* holiday・isHoliday・holidaysInYear などは、すべてのカレンダーの同じ参照を呼び、日付ごとに先のカレンダーの祝日を採る
|
|
294
|
+
* (同じ提供元は 1 回だけ数え、同じ日付なら先のカレンダーの提供元の祝日)。どれかのカレンダーが投げる日だけ投げる
|
|
294
295
|
* - タイムゾーンはすべてのカレンダーで同じでなければならない(time-zone-conflict)。
|
|
295
296
|
* 2 つ未満、同じカレンダーを 2 回渡した場合は invalid-argument
|
|
296
297
|
* - 合成したカレンダーをさらに合成することもできる。規則の診断(diagnoseCalendar)の対象にはならないので、
|
package/dist/core/calendar.js
CHANGED
|
@@ -290,13 +290,18 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
290
290
|
}
|
|
291
291
|
return Object.freeze(result);
|
|
292
292
|
},
|
|
293
|
-
adjust: (input, options) => adjustDate(dateOf(input), options),
|
|
293
|
+
adjust: (input, options) => adjustDate(dateOf(input), adjustOptions(options, "adjust options")),
|
|
294
294
|
nthBusinessDayOfMonth: nthOfMonth,
|
|
295
295
|
firstBusinessDayOfMonth: (month) => nthOfMonth(month, 1),
|
|
296
296
|
lastBusinessDayOfMonth: (month) => nthOfMonth(month, -1),
|
|
297
|
-
closingMonth
|
|
298
|
-
closingPeriod(input, closingDayOfMonth, options) {
|
|
297
|
+
closingMonth(input, closingDayOfMonth, rawOptions) {
|
|
299
298
|
checkClosingDay(closingDayOfMonth);
|
|
299
|
+
const options = adjustOptions(rawOptions, "closingMonth options");
|
|
300
|
+
return formatMonth(closingMonthOf(dateOf(input), closingDayOfMonth, options));
|
|
301
|
+
},
|
|
302
|
+
closingPeriod(input, closingDayOfMonth, rawOptions) {
|
|
303
|
+
checkClosingDay(closingDayOfMonth);
|
|
304
|
+
const options = adjustOptions(rawOptions, "closingPeriod options");
|
|
300
305
|
const isMonth = typeof input === "string" && /^\d{4}-\d{2}$/.test(input);
|
|
301
306
|
const month = isMonth
|
|
302
307
|
? parseMonth(input)
|
|
@@ -312,7 +317,7 @@ function buildCalendar(lookup, isOpen, info, searchDayLimit) {
|
|
|
312
317
|
const o = optionsObject(options, "dueDate options", (v) => renameKeys("throw", ["dueDate"], "", v), true);
|
|
313
318
|
const day = o["dayOfMonth"];
|
|
314
319
|
if (!isDayOfMonthValue(day)) {
|
|
315
|
-
throw rangeError("invalid-argument", `dayOfMonth must be an integer from 1 to 31, or -1 (last day): ${
|
|
320
|
+
throw rangeError("invalid-argument", `dayOfMonth must be an integer from 1 to 31, or -1 (last day): ${describeValue(day)}`);
|
|
316
321
|
}
|
|
317
322
|
return adjustDate(dayOfMonth(parseMonth(month), day), o);
|
|
318
323
|
},
|
|
@@ -329,6 +334,7 @@ function optionsObject(options, what, rename = (v) => v, required = false, code
|
|
|
329
334
|
}
|
|
330
335
|
return withoutUndefined(rename(options));
|
|
331
336
|
}
|
|
337
|
+
const adjustOptions = (options, what) => optionsObject(options, what, undefined, true);
|
|
332
338
|
const isCalendarLike = (v) => typeof v === "object" &&
|
|
333
339
|
v !== null &&
|
|
334
340
|
typeof v.dayInfoOn === "function" &&
|
|
@@ -364,7 +370,7 @@ export function combineCalendars(calendars, options) {
|
|
|
364
370
|
for (const p of c.providers)
|
|
365
371
|
if (!providers.includes(p))
|
|
366
372
|
providers.push(p);
|
|
367
|
-
const
|
|
373
|
+
const base = createHolidayLookup({
|
|
368
374
|
providers: Object.freeze(providers),
|
|
369
375
|
timeZone: zones[0],
|
|
370
376
|
outOfRangePolicy: calendars.every((c) => c.outOfRangePolicy === "ignore") ? "ignore" : "throw",
|
|
@@ -372,6 +378,23 @@ export function combineCalendars(calendars, options) {
|
|
|
372
378
|
? "throw"
|
|
373
379
|
: "accept",
|
|
374
380
|
});
|
|
381
|
+
const merge = (lists) => {
|
|
382
|
+
const byDate = new Map();
|
|
383
|
+
for (const list of lists)
|
|
384
|
+
for (const h of list)
|
|
385
|
+
if (!byDate.has(h.date))
|
|
386
|
+
byDate.set(h.date, h);
|
|
387
|
+
return Object.freeze([...byDate.values()].sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0)));
|
|
388
|
+
};
|
|
389
|
+
const holidayOn = (input) => calendars.map((c) => c.holidayOn(input)).find((h) => h !== undefined);
|
|
390
|
+
const lookup = {
|
|
391
|
+
...base,
|
|
392
|
+
isHoliday: (input) => holidayOn(input) !== undefined,
|
|
393
|
+
holidayOn,
|
|
394
|
+
getHoliday: holidayOn,
|
|
395
|
+
holidaysInYear: (year) => merge(calendars.map((c) => c.holidaysInYear(year))),
|
|
396
|
+
holidaysBetween: (from, to) => merge(calendars.map((c) => c.holidaysBetween(from, to))),
|
|
397
|
+
};
|
|
375
398
|
const isOpen = (date) => {
|
|
376
399
|
const results = calendars.map((c) => c.isBusinessDay(date));
|
|
377
400
|
return mode === "all" ? results.every(Boolean) : results.some(Boolean);
|
|
@@ -380,25 +403,25 @@ export function combineCalendars(calendars, options) {
|
|
|
380
403
|
const results = calendars.map((c) => c.dayInfoOn(date));
|
|
381
404
|
const open = mode === "all" ? results.every((r) => r.open) : results.some((r) => r.open);
|
|
382
405
|
const decidedBy = results.findIndex((r) => r.open === open);
|
|
383
|
-
const
|
|
406
|
+
const decided = results[decidedBy];
|
|
384
407
|
const result = {
|
|
385
408
|
date,
|
|
386
|
-
weekday:
|
|
409
|
+
weekday: decided.weekday,
|
|
387
410
|
open,
|
|
388
411
|
businessDay: open,
|
|
389
|
-
reason:
|
|
412
|
+
reason: decided.reason,
|
|
390
413
|
};
|
|
391
|
-
if (
|
|
392
|
-
result.name =
|
|
393
|
-
const holiday =
|
|
414
|
+
if (decided.name !== undefined)
|
|
415
|
+
result.name = decided.name;
|
|
416
|
+
const holiday = results.find((r) => r.holiday !== undefined)?.holiday;
|
|
394
417
|
if (holiday !== undefined)
|
|
395
418
|
result.holiday = holiday;
|
|
396
|
-
if (
|
|
397
|
-
result.shiftedFrom =
|
|
398
|
-
if (
|
|
399
|
-
result.optionPath = result.rulePath =
|
|
419
|
+
if (decided.shiftedFrom !== undefined)
|
|
420
|
+
result.shiftedFrom = decided.shiftedFrom;
|
|
421
|
+
if (decided.optionPath !== undefined)
|
|
422
|
+
result.optionPath = result.rulePath = decided.optionPath;
|
|
400
423
|
result.decidedBy = decidedBy;
|
|
401
|
-
result.decidedByPath = Object.freeze([decidedBy, ...(
|
|
424
|
+
result.decidedByPath = Object.freeze([decidedBy, ...(decided.decidedByPath ?? [])]);
|
|
402
425
|
return Object.freeze(result);
|
|
403
426
|
}
|
|
404
427
|
return buildCalendar(lookup, isOpen, info, searchDayLimit);
|
package/dist/core/errors.d.ts
CHANGED
package/dist/core/input.js
CHANGED
|
@@ -103,6 +103,9 @@ export function toCivil(input, timeZone) {
|
|
|
103
103
|
if (input.calendarId !== undefined && input.calendarId !== "iso8601") {
|
|
104
104
|
throw rangeError("invalid-input", `Unsupported calendar: ${input.calendarId} (only iso8601)`);
|
|
105
105
|
}
|
|
106
|
+
if (!Number.isInteger(input.year) || input.year < 1000 || input.year > 9999) {
|
|
107
|
+
throw rangeError("invalid-date", `Invalid date: year must be an integer from 1000 to 9999: ${describeValue(input.year)}`);
|
|
108
|
+
}
|
|
106
109
|
const date = formatDate(input.year, input.month, input.day);
|
|
107
110
|
if (typeof input.hour === "number") {
|
|
108
111
|
return { date, minutes: wallTime(input.hour, input.minute ?? 0) };
|
|
@@ -152,7 +155,7 @@ export function parseTimeOfDaySeconds(value) {
|
|
|
152
155
|
export function toInstant(date, time, timeZone) {
|
|
153
156
|
const zone = validateTimeZone(timeZone);
|
|
154
157
|
if (typeof date !== "string")
|
|
155
|
-
throw rangeError("invalid-date", `Invalid date: ${
|
|
158
|
+
throw rangeError("invalid-date", `Invalid date: ${describeValue(date)}`);
|
|
156
159
|
parseDate(date);
|
|
157
160
|
const seconds = parseTimeOfDaySeconds(time);
|
|
158
161
|
const ms = civilToInstant(date, Math.floor(seconds / 60), zone) + (seconds % 60) * 1000;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describeValue } from "./errors.js";
|
|
2
|
+
export function checkNames(names) {
|
|
3
|
+
const isObject = typeof names === "object" && names !== null && !Array.isArray(names);
|
|
4
|
+
const proto = isObject ? Object.getPrototypeOf(names) : undefined;
|
|
5
|
+
if (!isObject || (proto !== null && Object.getPrototypeOf(proto) !== null)) {
|
|
6
|
+
return "must be a plain object of { [language tag]: name }";
|
|
7
|
+
}
|
|
8
|
+
for (const [tag, value] of Object.entries(names)) {
|
|
9
|
+
let canonical;
|
|
10
|
+
try {
|
|
11
|
+
canonical = Intl.getCanonicalLocales(tag)[0];
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return `${describeValue(tag)} is not a BCP 47 language tag`;
|
|
15
|
+
}
|
|
16
|
+
if (canonical !== tag) {
|
|
17
|
+
return `${describeValue(tag)} must be written in canonical form ${describeValue(canonical)}`;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value !== "string" || value === "") {
|
|
20
|
+
return `${describeValue(tag)} must be a non-empty string`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
package/dist/core/schedule.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addDays, lengthOfMonth, formatDate, fromDayNumber, isValidDate, parseDate, toDayNumber, weekdayOf, } from "./date.js";
|
|
2
2
|
import { checkUnknownKeys, describeValue, IssueCollector, rangeError, withoutUndefined, } from "./errors.js";
|
|
3
3
|
import { isOptionsObject } from "./options.js";
|
|
4
|
+
import { checkNames } from "./names.js";
|
|
4
5
|
import { RENAMED_VALUES, renameKeys, renameValue, writtenKey } from "./renamed.js";
|
|
5
6
|
import { instantToCivil, isDate, toCivil, toDateTimeParts, toInstant, validateTimeZone, } from "./input.js";
|
|
6
7
|
import { HOLIDAY_KEY_PATTERN } from "./types.js";
|
|
@@ -788,28 +789,6 @@ function loadProviderYear(provider, year) {
|
|
|
788
789
|
return Object.freeze(holiday);
|
|
789
790
|
});
|
|
790
791
|
}
|
|
791
|
-
function checkNames(names) {
|
|
792
|
-
const proto = isObject(names) ? Object.getPrototypeOf(names) : undefined;
|
|
793
|
-
if (!isObject(names) || (proto !== null && Object.getPrototypeOf(proto) !== null)) {
|
|
794
|
-
return "must be a plain object of { [language tag]: name }";
|
|
795
|
-
}
|
|
796
|
-
for (const [tag, value] of Object.entries(names)) {
|
|
797
|
-
let canonical;
|
|
798
|
-
try {
|
|
799
|
-
canonical = Intl.getCanonicalLocales(tag)[0];
|
|
800
|
-
}
|
|
801
|
-
catch {
|
|
802
|
-
return `${describeValue(tag)} is not a BCP 47 language tag`;
|
|
803
|
-
}
|
|
804
|
-
if (canonical !== tag) {
|
|
805
|
-
return `${describeValue(tag)} must be written in canonical form ${describeValue(canonical)}`;
|
|
806
|
-
}
|
|
807
|
-
if (typeof value !== "string" || value === "") {
|
|
808
|
-
return `${describeValue(tag)} must be a non-empty string`;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return undefined;
|
|
812
|
-
}
|
|
813
792
|
export function createHolidayLookup(source) {
|
|
814
793
|
const { providers, timeZone, outOfRangePolicy, unconfirmedHolidayPolicy } = source;
|
|
815
794
|
const yearCache = new Map();
|
package/dist/provider/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addDays, lengthOfMonth as daysInMonthOf, easterSunday as easterSundayOf, formatDate, isLeapYear as isLeapYearOf, isValidDate, nthWeekdayOfMonth as nthWeekdayOfMonthIn, parseDate, weekdayOf, } from "../core/date.js";
|
|
2
2
|
import { renameKeys } from "../core/renamed.js";
|
|
3
3
|
import { describeValue, rangeError } from "../core/errors.js";
|
|
4
|
+
import { checkNames } from "../core/names.js";
|
|
4
5
|
import { isOptionsObject } from "../core/options.js";
|
|
5
6
|
import { HOLIDAY_KEY_PATTERN } from "../core/types.js";
|
|
6
7
|
function checkYear(year) {
|
|
@@ -10,7 +11,7 @@ function checkYear(year) {
|
|
|
10
11
|
}
|
|
11
12
|
function checkMonth(month) {
|
|
12
13
|
if (!Number.isInteger(month) || month < 1 || month > 12) {
|
|
13
|
-
throw rangeError("invalid-argument", `month must be an integer from 1 to 12: ${
|
|
14
|
+
throw rangeError("invalid-argument", `month must be an integer from 1 to 12: ${describeValue(month)}`);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
export function easterSunday(year) {
|
|
@@ -21,10 +22,10 @@ export function nthWeekdayOfMonth(year, month, weekday, n) {
|
|
|
21
22
|
checkYear(year);
|
|
22
23
|
checkMonth(month);
|
|
23
24
|
if (!Number.isInteger(weekday) || weekday < 0 || weekday > 6) {
|
|
24
|
-
throw rangeError("invalid-weekday", `weekday must be an integer from 0 (Sunday) to 6 (Saturday): ${
|
|
25
|
+
throw rangeError("invalid-weekday", `weekday must be an integer from 0 (Sunday) to 6 (Saturday): ${describeValue(weekday)}`);
|
|
25
26
|
}
|
|
26
27
|
if (!Number.isInteger(n) || n === 0 || n < -1 || n > 5) {
|
|
27
|
-
throw rangeError("invalid-argument", `n must be an integer from 1 to 5, or -1 (last): ${
|
|
28
|
+
throw rangeError("invalid-argument", `n must be an integer from 1 to 5, or -1 (last): ${describeValue(n)}`);
|
|
28
29
|
}
|
|
29
30
|
const days = daysInMonthOf(year, month);
|
|
30
31
|
if (n === -1) {
|
|
@@ -57,7 +58,7 @@ function checkHolidays(holidays) {
|
|
|
57
58
|
if (typeof h !== "object" || h === null) {
|
|
58
59
|
throw rangeError("invalid-argument", `holidays[${i}] is not an object`);
|
|
59
60
|
}
|
|
60
|
-
const { date, name, nameEn, kind, confirmed, key } = h;
|
|
61
|
+
const { date, name, nameEn, kind, confirmed, key, names } = h;
|
|
61
62
|
if (!isValidDate(date)) {
|
|
62
63
|
throw rangeError("invalid-date", `holidays[${i}] has an invalid date ${describeValue(date)}`);
|
|
63
64
|
}
|
|
@@ -79,6 +80,9 @@ function checkHolidays(holidays) {
|
|
|
79
80
|
if (key !== undefined && (typeof key !== "string" || !HOLIDAY_KEY_PATTERN.test(key))) {
|
|
80
81
|
throw rangeError("invalid-argument", `holidays[${i}] (${date}) key must match ${String(HOLIDAY_KEY_PATTERN)}: ${describeValue(key)}`);
|
|
81
82
|
}
|
|
83
|
+
const problem = names === undefined ? undefined : checkNames(names);
|
|
84
|
+
if (problem !== undefined)
|
|
85
|
+
throw rangeError("invalid-argument", `holidays[${i}] (${date}) names: ${problem}`);
|
|
82
86
|
});
|
|
83
87
|
return holidays;
|
|
84
88
|
}
|
|
@@ -88,10 +92,11 @@ function checkOptions(options) {
|
|
|
88
92
|
}
|
|
89
93
|
const o = renameKeys("throw", ["substitute"], "options", options);
|
|
90
94
|
const { directions: rules, kind, renameSubstitute: name, originalPolicy: original } = o;
|
|
91
|
-
if (
|
|
92
|
-
throw rangeError("invalid-argument",
|
|
95
|
+
if (!isOptionsObject(rules)) {
|
|
96
|
+
throw rangeError("invalid-argument", `options.directions must be an object of { [weekday]: "next" | "previous" }: ${describeValue(rules)}`);
|
|
93
97
|
}
|
|
94
|
-
|
|
98
|
+
const entries = Object.entries(rules).filter(([, direction]) => direction !== undefined);
|
|
99
|
+
for (const [weekday, direction] of entries) {
|
|
95
100
|
if (!/^[0-6]$/.test(weekday)) {
|
|
96
101
|
throw rangeError("invalid-weekday", `options.directions has a weekday that is not 0 (Sunday) to 6 (Saturday): ${describeValue(weekday)}`);
|
|
97
102
|
}
|
|
@@ -99,6 +104,9 @@ function checkOptions(options) {
|
|
|
99
104
|
throw rangeError("invalid-argument", `options.directions[${weekday}] must be "next" or "previous": ${describeValue(direction)}`);
|
|
100
105
|
}
|
|
101
106
|
}
|
|
107
|
+
if (entries.length === 7) {
|
|
108
|
+
throw rangeError("invalid-argument", "options.directions must leave at least one weekday without a direction (there would be no day to move a holiday to)");
|
|
109
|
+
}
|
|
102
110
|
if (typeof kind !== "string" || kind === "") {
|
|
103
111
|
throw rangeError("invalid-argument", "options.kind must be a non-empty string (Holiday.kind)");
|
|
104
112
|
}
|
|
@@ -108,12 +116,13 @@ function checkOptions(options) {
|
|
|
108
116
|
if (original !== undefined && original !== "keep" && original !== "drop") {
|
|
109
117
|
throw rangeError("invalid-argument", 'options.originalPolicy must be "keep" or "drop"');
|
|
110
118
|
}
|
|
111
|
-
return o;
|
|
119
|
+
return { ...o, directions: Object.fromEntries(entries) };
|
|
112
120
|
}
|
|
113
121
|
export function withSubstituteDays(holidays, options) {
|
|
114
122
|
const input = checkHolidays(holidays);
|
|
115
123
|
const { directions: rules, kind, renameSubstitute: name, originalPolicy: original, } = checkOptions(options);
|
|
116
124
|
const sorted = [...input].sort((a, b) => (a.date < b.date ? -1 : 1));
|
|
125
|
+
const namesOf = new Map(sorted.map((h) => [h, h.names === undefined ? undefined : Object.freeze({ ...h.names })]));
|
|
117
126
|
const taken = new Set(sorted.map((h) => h.date));
|
|
118
127
|
const result = sorted
|
|
119
128
|
.filter((h) => original !== "drop" || rules[weekdayOf(h.date)] === undefined)
|
|
@@ -121,7 +130,7 @@ export function withSubstituteDays(holidays, options) {
|
|
|
121
130
|
date: h.date,
|
|
122
131
|
name: h.name,
|
|
123
132
|
nameEn: h.nameEn,
|
|
124
|
-
...(h
|
|
133
|
+
...(namesOf.get(h) === undefined ? {} : { names: namesOf.get(h) }),
|
|
125
134
|
kind: h.kind,
|
|
126
135
|
confirmed: h.confirmed,
|
|
127
136
|
...(h.key === undefined ? {} : { key: h.key }),
|
|
@@ -136,11 +145,17 @@ export function withSubstituteDays(holidays, options) {
|
|
|
136
145
|
day = addDays(day, step);
|
|
137
146
|
taken.add(day);
|
|
138
147
|
const named = name === undefined ? { name: h.name, nameEn: h.nameEn } : name(h);
|
|
148
|
+
if (typeof named !== "object" ||
|
|
149
|
+
named === null ||
|
|
150
|
+
typeof named.name !== "string" ||
|
|
151
|
+
typeof named.nameEn !== "string") {
|
|
152
|
+
throw rangeError("invalid-argument", `options.renameSubstitute must return { name, nameEn } as strings (for ${h.date}): ${describeValue(named)}`);
|
|
153
|
+
}
|
|
139
154
|
result.push(Object.freeze({
|
|
140
155
|
date: day,
|
|
141
156
|
name: named.name,
|
|
142
157
|
nameEn: named.nameEn,
|
|
143
|
-
...(h
|
|
158
|
+
...(namesOf.get(h) === undefined ? {} : { names: namesOf.get(h) }),
|
|
144
159
|
kind,
|
|
145
160
|
confirmed: h.confirmed,
|
|
146
161
|
...(h.key === undefined ? {} : { key: h.key }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bizdays-toolkit",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.3",
|
|
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",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@types/node": "26.6.6",
|
|
92
|
-
"oxfmt": "0.
|
|
93
|
-
"oxlint": "1.
|
|
92
|
+
"oxfmt": "0.77.0",
|
|
93
|
+
"oxlint": "1.92.0",
|
|
94
94
|
"typescript": "6.0.3"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|