tiny-ja-date 0.8.0 → 1.0.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
 
@@ -16,6 +17,11 @@ Tiny TypeScript date utilities for Japanese UI.
16
17
  npm install tiny-ja-date
17
18
  ```
18
19
 
20
+ The package provides an ES module and TypeScript declarations.
21
+ Version 1.0.0 was verified on Windows x64 with Node.js 26.13.1, npm 11.20.0,
22
+ and TypeScript 5.9.3. Time zone calculations use the runtime's
23
+ `Intl.DateTimeFormat` and its time zone data.
24
+
19
25
  ## Usage
20
26
 
21
27
  ```ts
@@ -27,6 +33,7 @@ import {
27
33
  formatRelativeJaDate,
28
34
  isBusinessDay,
29
35
  isWeekendJP,
36
+ listBusinessDays,
30
37
  nextBusinessDay,
31
38
  } from "tiny-ja-date"
32
39
 
@@ -51,6 +58,9 @@ addBusinessDays("2026-05-15", 2)
51
58
  countBusinessDays("2026-05-15", "2026-05-19")
52
59
  // 2
53
60
 
61
+ listBusinessDays("2026-05-15", "2026-05-19")
62
+ // Dates for 2026-05-15, 2026-05-18, and 2026-05-19
63
+
54
64
  const calendar = createBusinessCalendar({ timeZone: "Asia/Tokyo", weekendDays: [0] })
55
65
  calendar.isBusinessDay("2026-11-21")
56
66
  // true
@@ -121,6 +131,7 @@ isBusinessDay("2026-11-24", options)
121
131
  Returns a `Date` for the start of the next business day in the selected time
122
132
  zone. If midnight is skipped, the result is the first valid time on that date.
123
133
  If a time zone skipped an entire date, the search continues to the following date.
134
+ Calling `toISOString()` on the result displays the instant in UTC.
124
135
 
125
136
  The search starts the day after the input and skips weekly closures and dates
126
137
  in `options.holidays`. Each holiday accepts the same `DateInput` type as the
@@ -178,10 +189,38 @@ countBusinessDays("2026-11-20", "2026-11-22", options) // 0
178
189
  countBusinessDays("2026-11-22", "2026-11-20", options) // -1
179
190
  ```
180
191
 
192
+ ### `listBusinessDays(from: DateInput, to: DateInput, options?: BusinessDayOptions): Date[]`
193
+
194
+ Lists business days from `from` through `to`, including either endpoint when it
195
+ is a business day. The dates appear in the requested direction. Equal endpoints
196
+ return one date if it is a business day, or an empty array otherwise.
197
+
198
+ Weekly closures, individual holidays, and dates skipped entirely by the time zone
199
+ are excluded. Each `Date` represents the day's first valid time in the selected
200
+ time zone. Each call returns a fresh array with fresh `Date` objects.
201
+
202
+ ```ts
203
+ const options = {
204
+ timeZone: "Asia/Tokyo",
205
+ weekendDays: [0],
206
+ holidays: ["2026-11-23"],
207
+ }
208
+
209
+ listBusinessDays("2026-11-20", "2026-11-24", options)
210
+ // Starts of November 20, 21, and 24 in Tokyo
211
+
212
+ listBusinessDays("2026-11-24", "2026-11-20", options)
213
+ // Starts of November 24, 21, and 20 in Tokyo
214
+
215
+ countBusinessDays("2026-11-20", "2026-11-24", options)
216
+ // 2, starting the count after November 20
217
+ ```
218
+
181
219
  ### `createBusinessCalendar(options?: BusinessDayOptions): BusinessCalendar`
182
220
 
183
221
  Creates a reusable calendar with `isBusinessDay(date)`, `nextBusinessDay(date)`,
184
- `addBusinessDays(date, amount)`, and `countBusinessDays(from, to)` methods.
222
+ `addBusinessDays(date, amount)`, `countBusinessDays(from, to)`, and
223
+ `listBusinessDays(from, to)` methods.
185
224
  Each method follows the same rules as the standalone function. The factory
186
225
  validates the time zone, weekend days, and holidays when creating the calendar.
187
226
  Method arguments are validated on each call.
@@ -200,12 +239,14 @@ const calendar = createBusinessCalendar({
200
239
 
201
240
  calendar.isBusinessDay("2026-11-21") // true
202
241
  calendar.countBusinessDays("2026-11-20", "2026-11-24") // 2
242
+ calendar.listBusinessDays("2026-11-20", "2026-11-24")
243
+ // Starts of November 20, 21, and 24 in Tokyo
203
244
  ```
204
245
 
205
246
  ## Weekly closures
206
247
 
207
- `isBusinessDay`, `nextBusinessDay`, `addBusinessDays`, and `countBusinessDays`
208
- accept `weekendDays?: readonly number[]` in `BusinessDayOptions`. Use integers
248
+ `isBusinessDay`, `nextBusinessDay`, `addBusinessDays`, `countBusinessDays`, and
249
+ `listBusinessDays` accept `weekendDays?: readonly number[]` in `BusinessDayOptions`. Use integers
209
250
  from `0` (Sunday) through `6` (Saturday).
210
251
 
211
252
  - Omitting `weekendDays` closes Saturday and Sunday, equivalent to `[0, 6]`.
@@ -215,7 +256,8 @@ from `0` (Sunday) through `6` (Saturday).
215
256
  `RangeError`. A non-array value throws a `TypeError`. Validation also applies
216
257
  to zero-day moves and same-date counts.
217
258
  - Closing all seven days makes `isBusinessDay` return `false` and
218
- `countBusinessDays` return `0`. `nextBusinessDay` and nonzero
259
+ `countBusinessDays` return `0`. `listBusinessDays` returns an empty array.
260
+ `nextBusinessDay` and nonzero
219
261
  `addBusinessDays` calls throw a `TypeError`. A zero-day move still returns the
220
262
  start of the input date.
221
263
 
@@ -234,9 +276,9 @@ countBusinessDays("2026-11-20", "2026-11-24", options) // 2 (Saturday and Tuesda
234
276
  ## Time zones
235
277
 
236
278
  All public functions accept an optional `timeZone` such as `"Asia/Tokyo"`.
237
- When omitted, they keep the runtime-local behavior of 0.2. The runtime's
238
- `Intl.DateTimeFormat` supplies the time zone rules. Unrecognized IANA names
239
- throw a `RangeError`.
279
+ The selected zone applies to input dates, base dates, range endpoints, and
280
+ holidays. Omitting it uses the runtime's local time zone. Unrecognized IANA
281
+ names throw a `RangeError`.
240
282
 
241
283
  ```ts
242
284
  const tokyo = { timeZone: "Asia/Tokyo" }
@@ -253,15 +295,14 @@ nextBusinessDay("2026-11-20", { ...tokyo, holidays: ["2026-11-23"] }).toISOStrin
253
295
 
254
296
  ## Date inputs
255
297
 
256
- - `YYYY-MM-DD` strings represent calendar dates as written in the selected time
257
- zone. The runtime-local zone is used when no zone is specified.
258
- Invalid dates such as `2026-02-30` throw a `TypeError`.
259
- - `Date` objects and Unix timestamps in milliseconds represent instants. The
260
- functions use the instant's date in the selected time zone.
261
- - For strings with a time, use ISO 8601 with an explicit offset such as
262
- `2026-05-12T09:00:00+09:00` to identify an instant. With an explicit
263
- `timeZone`, date-time strings without an offset and other string formats
264
- throw a `TypeError`. Without `timeZone`, they follow JavaScript's `Date` parsing.
298
+ | Input | Interpretation |
299
+ | --- | --- |
300
+ | `"2026-11-24"` | The calendar date as written in the selected zone. |
301
+ | A `Date`, a Unix timestamp in milliseconds, or `"2026-11-23T15:30:00Z"` | An instant. The functions use its calendar date in the selected zone. |
302
+ | `"2026-11-24T00:30:00"` or other string formats | Follows JavaScript's `Date` parsing when `timeZone` is omitted. With an explicit `timeZone`, these inputs throw a `TypeError`. |
303
+
304
+ An invalid calendar date such as `2026-02-30` throws a `TypeError`.
305
+ When time matters, use ISO 8601 with `Z` or a numeric offset such as `+09:00`.
265
306
 
266
307
  ### Upgrading from 0.1
267
308
 
@@ -271,14 +312,8 @@ as `2026-05-12T00:00:00Z` to retain the 0.1 interpretation.
271
312
 
272
313
  ## Design policy
273
314
 
274
- `tiny-ja-date` is intentionally small.
275
-
276
- It does not:
277
-
278
- - include Japanese holiday data
279
- - format wareki
280
- - generate calendars
281
- - replace date-fns or dayjs
315
+ `tiny-ja-date` focuses on Japanese date labels and business-day calculations.
316
+ Supply organization-specific holidays through `holidays`.
282
317
 
283
318
  ---
284
319
 
@@ -292,6 +327,33 @@ Run `npm run build:demo` after changing the library source to refresh
292
327
  - GitHub → `https://github.com/fusaihanabi/tiny-ja-date`
293
328
  - Official → `https://dl.fusai-hanabi.com`
294
329
 
330
+ ## Release checks
331
+
332
+ With the development dependencies installed, run the tests. In PowerShell,
333
+ the following checks both runtime-local behavior and explicit time zones
334
+ using each of the three runtime defaults.
335
+
336
+ ```powershell
337
+ foreach ($zone in @('Asia/Tokyo', 'America/Los_Angeles', 'Pacific/Apia')) {
338
+ $env:TZ = $zone
339
+ npm test -- --run
340
+ if ($LASTEXITCODE -ne 0) { throw "Tests failed in $zone" }
341
+ }
342
+ ```
343
+
344
+ Then rebuild the demo and verify the package.
345
+
346
+ ```bash
347
+ npm run build:demo
348
+ npm run check:package
349
+ ```
350
+
351
+ `check:package` builds the library, creates a tarball with `npm pack`, and
352
+ installs it offline in a temporary consumer project. It type-checks the
353
+ consumer using Node-style ESM resolution, then runs the emitted JavaScript
354
+ against the installed package. The check covers imports, exported types,
355
+ and representative date and business-day examples.
356
+
295
357
  ---
296
358
 
297
359
  ## License
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": "1.0.0",
4
4
  "description": "Tiny TypeScript date utilities for Japanese UI.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,6 +17,7 @@
17
17
  "scripts": {
18
18
  "build": "tsc",
19
19
  "build:demo": "tsc --declaration false --outDir docs",
20
+ "check:package": "npm run build && node scripts/check-package.mjs",
20
21
  "test": "vitest",
21
22
  "prepublishOnly": "npm test -- --run && npm run build"
22
23
  },