@dereekb/date 13.3.1 → 13.4.1

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.
@@ -30,24 +30,28 @@ export interface YearMonthDayCodePair {
30
30
  * Extracts the year component from a {@link YearMonthDayCode} by dividing out the month and day digits.
31
31
  *
32
32
  * @param yearMonthDayCode - Encoded YYYYMMDD value to extract the year from
33
+ * @returns the year component of the code
33
34
  */
34
35
  export declare function yearMonthDayCodeYear(yearMonthDayCode: YearMonthDayCode): YearNumber;
35
36
  /**
36
37
  * Extracts the month component (1-12) from a {@link YearMonthDayCode} by isolating the middle two digits.
37
38
  *
38
39
  * @param yearMonthDayCode - Encoded YYYYMMDD value to extract the month from
40
+ * @returns the month component (1-12) of the code
39
41
  */
40
42
  export declare function yearMonthDayCodeMonth(yearMonthDayCode: YearMonthDayCode): MonthOfYear;
41
43
  /**
42
44
  * Extracts the day-of-month component (1-31) from a {@link YearMonthDayCode} by isolating the last two digits.
43
45
  *
44
46
  * @param yearMonthDayCode - Encoded YYYYMMDD value to extract the day from
47
+ * @returns the day-of-month component (1-31) of the code
45
48
  */
46
49
  export declare function yearMonthDayCodeDay(yearMonthDayCode: YearMonthDayCode): DayOfMonth;
47
50
  /**
48
51
  * Decomposes a {@link YearMonthDayCode} into its individual year, month, and day components.
49
52
  *
50
53
  * @param yearMonthDayCode - Encoded YYYYMMDD value to decompose
54
+ * @returns a pair containing the individual year, month, and day components
51
55
  */
52
56
  export declare function yearMonthDayCodePair(yearMonthDayCode: YearMonthDayCode): YearMonthDayCodePair;
53
57
  /**
@@ -56,6 +60,7 @@ export declare function yearMonthDayCodePair(yearMonthDayCode: YearMonthDayCode)
56
60
  * that need timezone-aware conversion should use {@link yearMonthDayCodeFactory} instead.
57
61
  *
58
62
  * @param date - Date to extract components from using local timezone
63
+ * @returns a pair containing the year, month, and day from the date
59
64
  */
60
65
  export declare function yearMonthDayCodePairFromDate(date: Date): YearMonthDayCodePair;
61
66
  /**
@@ -63,6 +68,7 @@ export declare function yearMonthDayCodePairFromDate(date: Date): YearMonthDayCo
63
68
  * using the formula `year * 10000 + month * 100 + day`.
64
69
  *
65
70
  * @param pair - Decomposed date components to encode
71
+ * @returns the encoded YYYYMMDD integer
66
72
  */
67
73
  export declare function yearMonthDayCodeFromPair(pair: YearMonthDayCodePair): YearMonthDayCode;
68
74
  /**
@@ -70,6 +76,7 @@ export declare function yearMonthDayCodeFromPair(pair: YearMonthDayCodePair): Ye
70
76
  * using the system's local timezone. For timezone-aware conversion, use {@link yearMonthDayCodeFactory}.
71
77
  *
72
78
  * @param date - Date to encode using local timezone
79
+ * @returns the encoded YYYYMMDD integer for the given date
73
80
  */
74
81
  export declare function yearMonthDayCodeFromDate(date: Date): YearMonthDayCode;
75
82
  /**
@@ -94,13 +101,14 @@ export interface YearMonthDayCodeConfig {
94
101
  *
95
102
  * Configured to use the system timezone by default.
96
103
  */
97
- timezone?: YearMonthDayCodeDateTimezoneInput;
104
+ readonly timezone?: YearMonthDayCodeDateTimezoneInput;
98
105
  }
99
106
  /**
100
107
  * Resolves a {@link YearMonthDayCodeDateTimezoneInput} into a {@link DateTimezoneUtcNormalInstance},
101
108
  * falling back to the system timezone when no input is provided.
102
109
  *
103
110
  * @param input - Timezone configuration or existing instance to resolve
111
+ * @returns a DateTimezoneUtcNormalInstance, falling back to the system timezone
104
112
  */
105
113
  export declare function yearMonthDayCodeDateTimezoneInstance(input: YearMonthDayCodeDateTimezoneInput): DateTimezoneUtcNormalInstance;
106
114
  /**
@@ -116,6 +124,12 @@ export declare function yearMonthDayCodeDateTimezoneInstance(input: YearMonthDay
116
124
  * // From explicit components (year, month 1-12, day)
117
125
  * const code2 = yearMonthDayCode(2022, 1, 15); // 20220115
118
126
  * ```
127
+ *
128
+ * @param date - a Date to encode (first overload)
129
+ * @param dateOrYear - a Date to encode, or a year number when used with month and day
130
+ * @param month - the month (1-12), required when dateOrYear is a number
131
+ * @param day - the day of month (1-31), required when dateOrYear is a number
132
+ * @returns the encoded YYYYMMDD integer
119
133
  */
120
134
  export declare function yearMonthDayCode(date: Date): YearMonthDayCode;
121
135
  export declare function yearMonthDayCode(year: number, month: MonthOfYear, day: DayOfMonth): YearMonthDayCode;
@@ -135,6 +149,7 @@ export declare function yearMonthDayCode(year: number, month: MonthOfYear, day:
135
149
  * ```
136
150
  *
137
151
  * @param config - Optional timezone configuration; defaults to system timezone
152
+ * @returns a reusable factory function that converts dates to YearMonthDayCode values
138
153
  */
139
154
  export declare function yearMonthDayCodeFactory(config?: YearMonthDayCodeConfig): YearMonthDayCodeFactory;
140
155
  /**
@@ -158,6 +173,7 @@ export type YearMonthDayCodesForDateRangeFactory = (dateOrDateRange: DateOrDateR
158
173
  * ```
159
174
  *
160
175
  * @param dateOrDateRange - A single Date (expanded to its calendar month) or an explicit date range
176
+ * @returns an array of YearMonthDayCode values, one per day in the range
161
177
  */
162
178
  export declare function yearMonthDayCodesForDateRange(dateOrDateRange: DateOrDateRange): YearMonthDayCode[];
163
179
  /**
@@ -166,6 +182,7 @@ export declare function yearMonthDayCodesForDateRange(dateOrDateRange: DateOrDat
166
182
  * Shares timezone normalization with the provided factory for consistent day boundaries.
167
183
  *
168
184
  * @param factory - YearMonthDayCodeFactory to use for encoding; defaults to system timezone
185
+ * @returns a factory that produces arrays of YearMonthDayCode values for date ranges
169
186
  */
170
187
  export declare function yearMonthDayCodesForDateRangeFactory(factory?: YearMonthDayCodeFactory): YearMonthDayCodesForDateRangeFactory;
171
188
  /**
@@ -191,6 +208,7 @@ export type YearMonthDayCodeDateConfig = Pick<YearMonthDayCodeConfig, 'timezone'
191
208
  * ```
192
209
  *
193
210
  * @param config - Optional timezone configuration; defaults to system timezone
211
+ * @returns a factory that decodes YearMonthDayCode values back into Dates
194
212
  */
195
213
  export declare function yearMonthDayCodeDateFactory(config?: YearMonthDayCodeDateConfig): YearMonthDayCodeDateFactory;
196
214
  /**
@@ -221,11 +239,11 @@ export interface YearMonthDayCodeGroupFactoryConfig<B> {
221
239
  * Factory or config used to convert dates to day codes. Accepts either a pre-built
222
240
  * {@link YearMonthDayCodeFactory} or raw {@link YearMonthDayCodeConfig} to create one.
223
241
  */
224
- yearMonthDayCodeFactory?: YearMonthDayCodeFactory | YearMonthDayCodeConfig;
242
+ readonly yearMonthDayCodeFactory?: YearMonthDayCodeFactory | YearMonthDayCodeConfig;
225
243
  /**
226
244
  * Function that extracts the relevant Date from each item for day-code grouping.
227
245
  */
228
- dateReader: YearMonthDayCodeDateReader<B>;
246
+ readonly dateReader: YearMonthDayCodeDateReader<B>;
229
247
  }
230
248
  /**
231
249
  * Creates a {@link YearMonthDayCodeGroupFactory} that partitions items into day-based groups.
@@ -246,5 +264,6 @@ export interface YearMonthDayCodeGroupFactoryConfig<B> {
246
264
  * ```
247
265
  *
248
266
  * @param config - Grouping configuration including the date reader and optional timezone
267
+ * @returns a factory that partitions items into day-based groups
249
268
  */
250
269
  export declare function yearMonthDayCodeGroupFactory<B>(config: YearMonthDayCodeGroupFactoryConfig<B>): YearMonthDayCodeGroupFactory<B>;
@@ -22,21 +22,21 @@ export interface FormatDateRangeFunctionConfig {
22
22
  /**
23
23
  * Function used to format each individual date in the range.
24
24
  */
25
- format: FormatDateFunction;
25
+ readonly format: FormatDateFunction;
26
26
  /**
27
27
  * Whether to normalize dates to UTC before formatting.
28
28
  */
29
- normalizeToUTC?: boolean;
29
+ readonly normalizeToUTC?: boolean;
30
30
  /**
31
31
  * Separator string placed between the formatted start and end dates. Defaults to `'-'`.
32
32
  */
33
- separator?: string;
33
+ readonly separator?: string;
34
34
  /**
35
35
  * Whether to output a single formatted date when both dates fall on the same day.
36
36
  *
37
37
  * False by default.
38
38
  */
39
- simplifySameDate?: boolean;
39
+ readonly simplifySameDate?: boolean;
40
40
  }
41
41
  export type FormatDateRangeFunctionConfigInput = FormatDateFunction | FormatDateRangeFunctionConfig;
42
42
  /**
@@ -45,6 +45,7 @@ export type FormatDateRangeFunctionConfigInput = FormatDateFunction | FormatDate
45
45
  * Useful when the same range formatting logic needs to be applied repeatedly with consistent settings.
46
46
  *
47
47
  * @param inputConfig - format function or full configuration
48
+ * @returns a reusable function that formats date ranges into strings
48
49
  *
49
50
  * @example
50
51
  * ```ts
@@ -67,6 +68,7 @@ export declare function formatDateRangeFunction(inputConfig: FormatDateRangeFunc
67
68
  * @param range - date range to format
68
69
  * @param inputConfig - format function or full configuration
69
70
  * @param separator - optional separator override when inputConfig is a function
71
+ * @returns the formatted date range string
70
72
  *
71
73
  * @example
72
74
  * ```ts
@@ -113,6 +115,7 @@ export type FormatDateRangeDistanceFunctionConfig = {
113
115
  * (e.g., "3 hours", "about 2 days"). Delegates to date-fns `formatDistance` or `formatDistanceStrict`.
114
116
  *
115
117
  * @param inputConfig - controls distance formatting, optional transforms, and same-day handling
118
+ * @returns a reusable function that computes and formats date range distances
116
119
  *
117
120
  * @example
118
121
  * ```ts
@@ -137,6 +140,7 @@ export declare const formatDateDistance: FormatDateRangeFunction;
137
140
  *
138
141
  * @param range - date range to compute distance for
139
142
  * @param inputConfig - optional distance formatting configuration
143
+ * @returns the human-readable distance string
140
144
  *
141
145
  * @example
142
146
  * ```ts
@@ -169,6 +173,11 @@ export declare function formatDateRangeDistance(range: DateRange, inputConfig?:
169
173
  * formatToTimeRangeString({ start: new Date('2024-01-15T09:00:00'), end: new Date('2024-01-16T17:00:00') });
170
174
  * // "01/15/2024 9:00 AM - 01/16/2024 5:00 PM"
171
175
  * ```
176
+ *
177
+ * @param startOrDateRange - date range object or start date
178
+ * @param end - optional end date when a start date is provided
179
+ * @param onlyTimeRange - whether to force time-only formatting regardless of date span
180
+ * @returns the formatted time or date+time range string
172
181
  */
173
182
  export declare function formatToTimeRangeString(startOrDateRange: DateRange): string;
174
183
  export declare function formatToTimeRangeString(start: Date, end?: Maybe<Date>): string;
@@ -186,6 +195,10 @@ export declare function formatToTimeRangeString(startOrDateRange: DateRange | Da
186
195
  * formatToDayTimeRangeString({ start: new Date('2024-01-15T09:00:00'), end: new Date('2024-01-16T17:00:00') });
187
196
  * // "01/15/2024 9:00 AM - 01/16/2024 5:00 PM"
188
197
  * ```
198
+ *
199
+ * @param startOrDateRange - date range object or start date
200
+ * @param end - optional end date when a start date is provided
201
+ * @returns the formatted date+time range string
189
202
  */
190
203
  export declare function formatToDayTimeRangeString(startOrDateRange: DateRange): string;
191
204
  export declare function formatToDayTimeRangeString(start: Date, end?: Maybe<Date>): string;
@@ -205,6 +218,12 @@ export declare function formatToDayTimeRangeString(start: Date, end?: Maybe<Date
205
218
  * formatToDayRangeString({ start: new Date('2024-01-15'), end: new Date('2024-01-15') });
206
219
  * // "01/15/2024"
207
220
  * ```
221
+ *
222
+ * @param startOrDateRange - date range object or start date
223
+ * @param format - optional custom format function (when called with a DateRange)
224
+ * @param endOrFormat - optional end date or custom format function
225
+ * @param inputFormat - optional custom format function when end date is provided separately
226
+ * @returns the formatted day range string
208
227
  */
209
228
  export declare function formatToDayRangeString(startOrDateRange: DateRange, format?: FormatDateFunction): string;
210
229
  export declare function formatToDayRangeString(start: Date, end?: Maybe<Date>, format?: FormatDateFunction): string;
@@ -213,6 +232,7 @@ export declare function formatToDayRangeString(start: Date, end?: Maybe<Date>, f
213
232
  * instead of throwing.
214
233
  *
215
234
  * @param input - date, date string, or nullish value
235
+ * @returns the ISO 8601 date string, or `undefined` if the input is invalid or nullish
216
236
  *
217
237
  * @example
218
238
  * ```ts
@@ -233,6 +253,7 @@ export declare function safeFormatToISO8601DateString(input: Maybe<DateOrDateStr
233
253
  * Formats a Date to a full ISO 8601 date-time string via `Date.toISOString()`. Defaults to the current date/time.
234
254
  *
235
255
  * @param date - date to format; defaults to `new Date()`
256
+ * @returns the full ISO 8601 date-time string
236
257
  *
237
258
  * @example
238
259
  * ```ts
@@ -250,6 +271,7 @@ export declare function formatToISO8601DateString(date?: Date): ISO8601DayString
250
271
  * Use {@link toISO8601DayStringForUTC} when the UTC date is needed instead.
251
272
  *
252
273
  * @param dateOrString - date or existing day string
274
+ * @returns the ISO 8601 day string in system timezone
253
275
  *
254
276
  * @example
255
277
  * ```ts
@@ -268,6 +290,7 @@ export declare function toISO8601DayStringForSystem(dateOrString: DateOrDayStrin
268
290
  * Defaults to the current date.
269
291
  *
270
292
  * @param date - date to format; defaults to `new Date()`
293
+ * @returns the ISO 8601 day string in system timezone
271
294
  *
272
295
  * @example
273
296
  * ```ts
@@ -285,6 +308,7 @@ export declare function formatToISO8601DayStringForSystem(date?: Date): ISO8601D
285
308
  * Use {@link toISO8601DayStringForSystem} when the system-local date is needed instead.
286
309
  *
287
310
  * @param dateOrString - date or existing day string
311
+ * @returns the ISO 8601 day string in UTC
288
312
  *
289
313
  * @example
290
314
  * ```ts
@@ -304,6 +328,7 @@ export declare function toISO8601DayStringForUTC(dateOrString: DateOrDayString):
304
328
  * Defaults to the current date.
305
329
  *
306
330
  * @param date - date to format; defaults to `new Date()`
331
+ * @returns the ISO 8601 day string using UTC date components
307
332
  *
308
333
  * @example
309
334
  * ```ts
@@ -314,12 +339,19 @@ export declare function toISO8601DayStringForUTC(dateOrString: DateOrDayString):
314
339
  * ```
315
340
  */
316
341
  export declare function formatToISO8601DayStringForUTC(date?: Date): ISO8601DayString;
317
- /** date-fns format string for `MM/dd/yyyy` (e.g., `"01/15/2024"`). */
342
+ /**
343
+ * date-fns format string for `MM/dd/yyyy` (e.g., `"01/15/2024"`).
344
+ */
345
+ export declare const MONTH_DAY_SLASH_DATE_STRING_FORMAT = "MM/dd/yyyy";
346
+ /**
347
+ * @deprecated Use MONTH_DAY_SLASH_DATE_STRING_FORMAT instead.
348
+ */
318
349
  export declare const monthDaySlashDateStringFormat = "MM/dd/yyyy";
319
350
  /**
320
351
  * Formats a Date as a month/day/year slash-separated string (`MM/dd/yyyy`). Defaults to the current date.
321
352
  *
322
353
  * @param date - date to format; defaults to `new Date()`
354
+ * @returns the formatted `MM/dd/yyyy` string
323
355
  *
324
356
  * @example
325
357
  * ```ts
@@ -334,12 +366,19 @@ export declare function formatToMonthDaySlashDate(date?: Date): MonthDaySlashDat
334
366
  * @deprecated use formatToMonthDaySlashDate instead.
335
367
  */
336
368
  export declare const formatToShortDateString: typeof formatToMonthDaySlashDate;
337
- /** date-fns format string for `MM/dd` (e.g., `"01/15"`). */
369
+ /**
370
+ * date-fns format string for `MM/dd` (e.g., `"01/15"`).
371
+ */
372
+ export declare const DATE_MONTH_DAY_STRING_FORMAT = "MM/dd";
373
+ /**
374
+ * @deprecated Use DATE_MONTH_DAY_STRING_FORMAT instead.
375
+ */
338
376
  export declare const dateMonthDayStringFormat = "MM/dd";
339
377
  /**
340
378
  * Formats a Date as a month/day string (`MM/dd`) without the year. Defaults to the current date.
341
379
  *
342
380
  * @param date - date to format; defaults to `new Date()`
381
+ * @returns the formatted `MM/dd` string
343
382
  *
344
383
  * @example
345
384
  * ```ts
@@ -354,6 +393,7 @@ export declare function formatToMonthDayString(date?: Date): ISO8601DayString;
354
393
  * Formats a Date as a human-friendly weekday and month/day string (e.g., `"Mon, Jan 15th"`).
355
394
  *
356
395
  * @param date - date to format
396
+ * @returns the formatted weekday and month/day string
357
397
  *
358
398
  * @example
359
399
  * ```ts
@@ -364,12 +404,19 @@ export declare function formatToMonthDayString(date?: Date): ISO8601DayString;
364
404
  * ```
365
405
  */
366
406
  export declare function formatToDateString(date: Date): string;
367
- /** date-fns format string for 12-hour time with AM/PM (e.g., `"9:00 AM"`). */
407
+ /**
408
+ * date-fns format string for 12-hour time with AM/PM (e.g., `"9:00 AM"`).
409
+ */
410
+ export declare const DATE_TIME_STRING_FORMAT = "h:mm a";
411
+ /**
412
+ * @deprecated Use DATE_TIME_STRING_FORMAT instead.
413
+ */
368
414
  export declare const dateTimeStringFormat = "h:mm a";
369
415
  /**
370
416
  * Formats a Date as a 12-hour time string with AM/PM (e.g., `"9:00 AM"`).
371
417
  *
372
418
  * @param date - date to format
419
+ * @returns the formatted 12-hour time string with AM/PM
373
420
  *
374
421
  * @example
375
422
  * ```ts
@@ -380,12 +427,19 @@ export declare const dateTimeStringFormat = "h:mm a";
380
427
  * ```
381
428
  */
382
429
  export declare function formatToTimeString(date: Date): string;
383
- /** Combined date-fns format string for `MM/dd/yyyy h:mm a` (e.g., `"01/15/2024 9:00 AM"`). */
430
+ /**
431
+ * Combined date-fns format string for `MM/dd/yyyy h:mm a` (e.g., `"01/15/2024 9:00 AM"`).
432
+ */
433
+ export declare const DATE_SHORT_DATE_AND_TIME_STRING_FORMAT = "MM/dd/yyyy h:mm a";
434
+ /**
435
+ * @deprecated Use DATE_SHORT_DATE_AND_TIME_STRING_FORMAT instead.
436
+ */
384
437
  export declare const dateShortDateAndTimeStringFormat = "MM/dd/yyyy h:mm a";
385
438
  /**
386
439
  * Formats a Date as a short date and time string (e.g., `"01/15/2024 9:00 AM"`).
387
440
  *
388
441
  * @param date - date to format
442
+ * @returns the formatted short date and time string
389
443
  *
390
444
  * @example
391
445
  * ```ts
@@ -402,6 +456,7 @@ export declare function formatToShortDateAndTimeString(date: Date): string;
402
456
  *
403
457
  * @param start - start date/time
404
458
  * @param end - end date/time
459
+ * @returns the formatted time string with an appended duration indicator
405
460
  *
406
461
  * @example
407
462
  * ```ts
@@ -436,6 +491,11 @@ export declare function formatToTimeAndDurationString(start: Date, end: Date): s
436
491
  * formatStartedEndedDistanceString(activeRange);
437
492
  * // "started about 1 hour ago"
438
493
  * ```
494
+ *
495
+ * @param dateRange - date range with start and end dates
496
+ * @param dateRange.start - the start date of the range
497
+ * @param dateRange.end - the end date of the range
498
+ * @returns the relative-time label describing the date range state
439
499
  */
440
500
  export declare function formatStartedEndedDistanceString({ start, end }: DateRange): string;
441
501
  /**
@@ -443,6 +503,7 @@ export declare function formatStartedEndedDistanceString({ start, end }: DateRan
443
503
  * Useful for converting heterogeneous date inputs into a consistent midnight-aligned Date.
444
504
  *
445
505
  * @param input - date or day string to normalize
506
+ * @returns a Date set to midnight of the corresponding day in the system timezone
446
507
  *
447
508
  * @example
448
509
  * ```ts
@@ -461,6 +522,7 @@ export declare function toJsDayDate(input: DateOrDayString): Date;
461
522
  * in the system timezone. Supports year formats with more than 4 digits but does not support negative years.
462
523
  *
463
524
  * @param dayString - ISO 8601 day or date string to parse
525
+ * @returns a Date at the start of the parsed day in the system timezone
464
526
  *
465
527
  * @example
466
528
  * ```ts