tiny-ja-date 0.8.0 → 0.9.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/README.md CHANGED
@@ -9,6 +9,7 @@ Tiny TypeScript date utilities for Japanese UI.
9
9
  - 次の営業日計算
10
10
  - 営業日数の加算・減算
11
11
  - 2つの日付間の営業日数
12
+ - 期間内の営業日一覧
12
13
 
13
14
  ## Install
14
15
 
@@ -178,10 +179,35 @@ countBusinessDays("2026-11-20", "2026-11-22", options) // 0
178
179
  countBusinessDays("2026-11-22", "2026-11-20", options) // -1
179
180
  ```
180
181
 
182
+ ### `listBusinessDays(from: DateInput, to: DateInput, options?: BusinessDayOptions): Date[]`
183
+
184
+ Lists business days from `from` through `to`, including either endpoint when it
185
+ is a business day. The dates appear in the requested direction. Equal endpoints
186
+ return one date if it is a business day, or an empty array otherwise.
187
+
188
+ Weekly closures, individual holidays, and dates skipped entirely by the time zone
189
+ are excluded. Each `Date` represents the day's first valid time in the selected
190
+ time zone. Each call returns a fresh array with fresh `Date` objects.
191
+
192
+ ```ts
193
+ const options = {
194
+ timeZone: "Asia/Tokyo",
195
+ weekendDays: [0],
196
+ holidays: ["2026-11-23"],
197
+ }
198
+
199
+ listBusinessDays("2026-11-20", "2026-11-24", options)
200
+ // Starts of November 20, 21, and 24 in Tokyo
201
+
202
+ listBusinessDays("2026-11-24", "2026-11-20", options)
203
+ // Starts of November 24, 21, and 20 in Tokyo
204
+ ```
205
+
181
206
  ### `createBusinessCalendar(options?: BusinessDayOptions): BusinessCalendar`
182
207
 
183
208
  Creates a reusable calendar with `isBusinessDay(date)`, `nextBusinessDay(date)`,
184
- `addBusinessDays(date, amount)`, and `countBusinessDays(from, to)` methods.
209
+ `addBusinessDays(date, amount)`, `countBusinessDays(from, to)`, and
210
+ `listBusinessDays(from, to)` methods.
185
211
  Each method follows the same rules as the standalone function. The factory
186
212
  validates the time zone, weekend days, and holidays when creating the calendar.
187
213
  Method arguments are validated on each call.
@@ -200,12 +226,14 @@ const calendar = createBusinessCalendar({
200
226
 
201
227
  calendar.isBusinessDay("2026-11-21") // true
202
228
  calendar.countBusinessDays("2026-11-20", "2026-11-24") // 2
229
+ calendar.listBusinessDays("2026-11-20", "2026-11-24")
230
+ // Starts of November 20, 21, and 24 in Tokyo
203
231
  ```
204
232
 
205
233
  ## Weekly closures
206
234
 
207
- `isBusinessDay`, `nextBusinessDay`, `addBusinessDays`, and `countBusinessDays`
208
- accept `weekendDays?: readonly number[]` in `BusinessDayOptions`. Use integers
235
+ `isBusinessDay`, `nextBusinessDay`, `addBusinessDays`, `countBusinessDays`, and
236
+ `listBusinessDays` accept `weekendDays?: readonly number[]` in `BusinessDayOptions`. Use integers
209
237
  from `0` (Sunday) through `6` (Saturday).
210
238
 
211
239
  - Omitting `weekendDays` closes Saturday and Sunday, equivalent to `[0, 6]`.
@@ -215,7 +243,8 @@ from `0` (Sunday) through `6` (Saturday).
215
243
  `RangeError`. A non-array value throws a `TypeError`. Validation also applies
216
244
  to zero-day moves and same-date counts.
217
245
  - Closing all seven days makes `isBusinessDay` return `false` and
218
- `countBusinessDays` return `0`. `nextBusinessDay` and nonzero
246
+ `countBusinessDays` return `0`. `listBusinessDays` returns an empty array.
247
+ `nextBusinessDay` and nonzero
219
248
  `addBusinessDays` calls throw a `TypeError`. A zero-day move still returns the
220
249
  start of the input date.
221
250
 
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export interface BusinessCalendar {
11
11
  nextBusinessDay(input: DateInput): Date;
12
12
  addBusinessDays(input: DateInput, amount: number): Date;
13
13
  countBusinessDays(from: DateInput, to: DateInput): number;
14
+ listBusinessDays(from: DateInput, to: DateInput): Date[];
14
15
  }
15
16
  export declare function formatJaDate(input: DateInput, options?: DateOptions): string;
16
17
  export declare function formatRelativeJaDate(input: DateInput, baseInput?: DateInput, options?: DateOptions): string;
@@ -19,4 +20,5 @@ export declare function isBusinessDay(input: DateInput, options?: BusinessDayOpt
19
20
  export declare function addBusinessDays(input: DateInput, amount: number, options?: BusinessDayOptions): Date;
20
21
  export declare function nextBusinessDay(input: DateInput, options?: BusinessDayOptions): Date;
21
22
  export declare function countBusinessDays(from: DateInput, to: DateInput, options?: BusinessDayOptions): number;
23
+ export declare function listBusinessDays(from: DateInput, to: DateInput, options?: BusinessDayOptions): Date[];
22
24
  export declare function createBusinessCalendar(options?: BusinessDayOptions): BusinessCalendar;
package/dist/index.js CHANGED
@@ -264,6 +264,25 @@ export function countBusinessDays(from, to, options = {}) {
264
264
  const end = dateOnlyDay(to) ?? calendarDay(to, formatter);
265
265
  return countBusinessDaysBetween(start, end, businessDayRules(options, formatter), formatter);
266
266
  }
267
+ function listBusinessDaysBetween(from, to, rules, formatter) {
268
+ const start = dateOnlyDay(from) ?? calendarDay(from, formatter);
269
+ const end = dateOnlyDay(to) ?? calendarDay(to, formatter);
270
+ if (rules.weekendDays.size === WEEKDAYS_JA.length)
271
+ return [];
272
+ const days = [];
273
+ const step = start <= end ? ONE_DAY_MS : -ONE_DAY_MS;
274
+ for (let day = start;; day += step) {
275
+ const businessDay = businessDayStart(day, rules, formatter);
276
+ if (businessDay)
277
+ days.push(businessDay);
278
+ if (day === end)
279
+ return days;
280
+ }
281
+ }
282
+ export function listBusinessDays(from, to, options = {}) {
283
+ const formatter = createFormatter(options.timeZone);
284
+ return listBusinessDaysBetween(from, to, businessDayRules(options, formatter), formatter);
285
+ }
267
286
  export function createBusinessCalendar(options = {}) {
268
287
  const formatter = createFormatter(options.timeZone);
269
288
  const rules = businessDayRules(options, formatter);
@@ -284,5 +303,8 @@ export function createBusinessCalendar(options = {}) {
284
303
  const end = dateOnlyDay(to) ?? calendarDay(to, formatter);
285
304
  return countBusinessDaysBetween(start, end, rules, formatter);
286
305
  },
306
+ listBusinessDays(from, to) {
307
+ return listBusinessDaysBetween(from, to, rules, formatter);
308
+ },
287
309
  };
288
310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-ja-date",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Tiny TypeScript date utilities for Japanese UI.",
5
5
  "type": "module",
6
6
  "exports": {