@dereekb/date 13.0.7 → 13.2.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.
Files changed (40) hide show
  1. package/index.cjs.js +3526 -993
  2. package/index.esm.js +3515 -983
  3. package/package.json +5 -6
  4. package/src/lib/date/date.calendar.d.ts +63 -9
  5. package/src/lib/date/date.cell.d.ts +203 -104
  6. package/src/lib/date/date.cell.factory.d.ts +319 -86
  7. package/src/lib/date/date.cell.filter.d.ts +104 -2
  8. package/src/lib/date/date.cell.index.d.ts +202 -92
  9. package/src/lib/date/date.cell.schedule.d.ts +285 -102
  10. package/src/lib/date/date.cell.schedule.day.d.ts +13 -3
  11. package/src/lib/date/date.cell.validator.d.ts +17 -8
  12. package/src/lib/date/date.cell.week.d.ts +24 -3
  13. package/src/lib/date/date.d.ts +481 -54
  14. package/src/lib/date/date.day.d.ts +139 -49
  15. package/src/lib/date/date.duration.d.ts +49 -11
  16. package/src/lib/date/date.format.d.ts +355 -36
  17. package/src/lib/date/date.hashset.d.ts +11 -0
  18. package/src/lib/date/date.logical.d.ts +61 -3
  19. package/src/lib/date/date.range.d.ts +355 -77
  20. package/src/lib/date/date.range.string.d.ts +39 -0
  21. package/src/lib/date/date.range.timezone.d.ts +18 -6
  22. package/src/lib/date/date.round.d.ts +46 -1
  23. package/src/lib/date/date.rxjs.d.ts +29 -7
  24. package/src/lib/date/date.sort.d.ts +36 -9
  25. package/src/lib/date/date.time.d.ts +197 -26
  26. package/src/lib/date/date.time.limit.d.ts +67 -4
  27. package/src/lib/date/date.time.minute.d.ts +269 -30
  28. package/src/lib/date/date.timezone.d.ts +286 -70
  29. package/src/lib/date/date.unix.d.ts +3 -0
  30. package/src/lib/date/date.week.d.ts +115 -51
  31. package/src/lib/query/query.builder.d.ts +91 -0
  32. package/src/lib/query/query.builder.mongo.d.ts +50 -0
  33. package/src/lib/query/query.filter.d.ts +29 -2
  34. package/src/lib/query/query.request.d.ts +16 -0
  35. package/src/lib/rrule/date.recurrence.d.ts +66 -22
  36. package/src/lib/rrule/date.rrule.d.ts +131 -8
  37. package/src/lib/rrule/date.rrule.extension.d.ts +50 -9
  38. package/src/lib/rrule/date.rrule.parse.d.ts +85 -2
  39. package/src/lib/timezone/timezone.d.ts +102 -2
  40. package/src/lib/timezone/timezone.validator.d.ts +9 -4
@@ -1,62 +1,143 @@
1
1
  import { type DateOrDateString, type DateRelativeState, type FactoryWithRequiredInput, type MapFunction, type Maybe, type ISO8601DayString, type DayOfWeek } from '@dereekb/util';
2
2
  /**
3
- * Represents a start date.
3
+ * Anchors a value to a specific start date, useful as a base for ranges and scheduling.
4
4
  */
5
5
  export interface DateRangeStart {
6
6
  start: Date;
7
7
  }
8
8
  /**
9
- * Returns true if the input is a DateRangeStart.
9
+ * Type guard to check if a value conforms to the {@link DateRangeStart} interface.
10
10
  *
11
- * @param value
12
- * @returns
11
+ * @example
12
+ * ```ts
13
+ * isDateRangeStart({ start: new Date() }); // true
14
+ * isDateRangeStart({ start: 'not-a-date' }); // false
15
+ * ```
13
16
  */
14
17
  export declare function isDateRangeStart(value: unknown): value is DateRangeStart;
15
18
  /**
16
- * Sorts the input DateRangeStart values in ascending order by start Date.
19
+ * Compare function for sorting {@link DateRangeStart} values in ascending chronological order by their start date.
20
+ * Suitable for use with `Array.prototype.sort()`.
17
21
  *
18
- * @param a
19
- * @param b
20
- * @returns
22
+ * @example
23
+ * ```ts
24
+ * const items: DateRangeStart[] = [
25
+ * { start: new Date('2024-03-01') },
26
+ * { start: new Date('2024-01-01') }
27
+ * ];
28
+ * items.sort(sortDateRangeStartAscendingCompareFunction);
29
+ * // [{ start: 2024-01-01 }, { start: 2024-03-01 }]
30
+ * ```
21
31
  */
22
32
  export declare const sortDateRangeStartAscendingCompareFunction: <T extends DateRangeStart>(a: T, b: T) => number;
23
33
  /**
24
- * Represents a start and end date.
34
+ * Defines a bounded time period with a start and end date, used throughout the date module
35
+ * for filtering, iteration, and comparison operations.
25
36
  */
26
37
  export interface DateRange extends DateRangeStart {
27
38
  end: Date;
28
39
  }
29
- export declare class DateRange {
40
+ /**
41
+ * ArkType schema for {@link DateRange}.
42
+ */
43
+ export declare const dateRangeType: import("arktype/internal/variants/object.ts").ObjectType<{
30
44
  start: Date;
31
45
  end: Date;
32
- constructor(template: DateRange);
33
- }
46
+ }, {}>;
34
47
  /**
35
- * Total number of days in the range. Minimum of 1 day.
48
+ * Counts the total number of calendar days spanned by the range, inclusive of both endpoints.
49
+ * Always returns at least 1, even for same-day ranges.
36
50
  *
37
- * @param dateRange
38
- * @returns
51
+ * @example
52
+ * ```ts
53
+ * const range = { start: new Date('2024-01-01'), end: new Date('2024-01-03') };
54
+ * dateRangeDaysCount(range); // 3
55
+ * ```
39
56
  */
40
57
  export declare function dateRangeDaysCount(dateRange: DateRange): number;
41
58
  /**
42
- * Returns true if the input is a DateRange.
59
+ * Type guard to check if a value is a valid {@link DateRange} with both start and end as Date objects.
43
60
  *
44
- * @param input
45
- * @returns
61
+ * @example
62
+ * ```ts
63
+ * isDateRange({ start: new Date(), end: new Date() }); // true
64
+ * isDateRange({ start: new Date() }); // false
65
+ * isDateRange('not-a-range'); // false
66
+ * ```
46
67
  */
47
68
  export declare function isDateRange(input: unknown): input is DateRange;
69
+ /**
70
+ * Compares two date ranges for exact millisecond equality on both start and end.
71
+ * Returns true if both are nullish.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const a = { start: new Date('2024-01-01'), end: new Date('2024-01-31') };
76
+ * const b = { start: new Date('2024-01-01'), end: new Date('2024-01-31') };
77
+ * isSameDateRange(a, b); // true
78
+ * isSameDateRange(null, null); // true
79
+ * ```
80
+ */
48
81
  export declare function isSameDateRange(a: Maybe<Partial<DateRange>>, b: Maybe<Partial<DateRange>>): boolean;
82
+ /**
83
+ * Compares two date ranges for calendar-day equality, ignoring time-of-day differences.
84
+ * Returns true if both are nullish.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const a = { start: new Date('2024-01-01T08:00:00'), end: new Date('2024-01-31T10:00:00') };
89
+ * const b = { start: new Date('2024-01-01T20:00:00'), end: new Date('2024-01-31T23:00:00') };
90
+ * isSameDateDayRange(a, b); // true (same calendar days)
91
+ * ```
92
+ */
49
93
  export declare function isSameDateDayRange(a: Maybe<Partial<DateRange>>, b: Maybe<Partial<DateRange>>): boolean;
50
94
  /**
51
- * Returns true if the date range has no start or end.
95
+ * Checks whether the range is unbounded (neither start nor end is set), meaning it conceptually includes all dates.
52
96
  *
53
- * @param input
54
- * @returns
97
+ * @example
98
+ * ```ts
99
+ * isInfiniteDateRange({}); // true
100
+ * isInfiniteDateRange({ start: new Date() }); // false
101
+ * ```
55
102
  */
56
103
  export declare function isInfiniteDateRange(input: Partial<DateRange>): boolean;
104
+ /**
105
+ * Checks whether the range has only one of start or end set, but not both.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * isPartialDateRange({ start: new Date() }); // true
110
+ * isPartialDateRange({ start: new Date(), end: new Date() }); // false
111
+ * ```
112
+ */
57
113
  export declare function isPartialDateRange(input: Partial<DateRange>): input is DateRange;
114
+ /**
115
+ * Checks whether the range has both start and end set.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * isFullDateRange({ start: new Date(), end: new Date() }); // true
120
+ * isFullDateRange({ start: new Date() }); // false
121
+ * ```
122
+ */
58
123
  export declare function isFullDateRange(input: Partial<DateRange>): input is DateRange;
124
+ /**
125
+ * Union type representing either a single Date or a {@link DateRange}.
126
+ */
59
127
  export type DateOrDateRange = Date | DateRange;
128
+ /**
129
+ * Normalizes a Date or {@link DateRange} into a DateRange. When given a single Date,
130
+ * uses it as start and optionally uses the provided end date (defaults to the same date).
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * const range = dateOrDateRangeToDateRange(new Date('2024-01-01'), new Date('2024-01-31'));
135
+ * // { start: 2024-01-01, end: 2024-01-31 }
136
+ *
137
+ * const existing = { start: new Date('2024-01-01'), end: new Date('2024-01-31') };
138
+ * dateOrDateRangeToDateRange(existing); // returns the same range
139
+ * ```
140
+ */
60
141
  export declare function dateOrDateRangeToDateRange(startOrDateRange: DateOrDateRange, end?: Maybe<Date>): DateRange;
61
142
  export declare enum DateRangeType {
62
143
  /**
@@ -123,7 +204,7 @@ export declare enum DateRangeType {
123
204
  /**
124
205
  * Params for building a date range.
125
206
  */
126
- export declare class DateRangeParams {
207
+ export interface DateRangeParams {
127
208
  /**
128
209
  * Type of range.
129
210
  */
@@ -133,15 +214,23 @@ export declare class DateRangeParams {
133
214
  */
134
215
  date: Date;
135
216
  distance?: number;
136
- constructor(template: DateRangeParams);
137
217
  }
218
+ /**
219
+ * ArkType schema for {@link DateRangeParams}.
220
+ */
221
+ export declare const dateRangeParamsType: import("arktype/internal/variants/object.ts").ObjectType<{
222
+ type: DateRangeType;
223
+ date: Date;
224
+ distance?: number | undefined;
225
+ }, {}>;
138
226
  export interface DateRangeTypedInput {
139
227
  type: DateRangeType;
140
228
  date?: Maybe<Date>;
141
229
  distance?: Maybe<number>;
142
230
  }
143
231
  /**
144
- * dateRange() input that infers duration to be a number of days, starting from the input date if applicable.
232
+ * Simplified input for {@link dateRange} that treats distance as a number of days from the start date,
233
+ * avoiding the need to specify a {@link DateRangeType}.
145
234
  */
146
235
  export interface DateRangeDayDistanceInput {
147
236
  date?: Maybe<Date>;
@@ -154,18 +243,33 @@ export type DateRangeInput = (DateRangeTypedInput | DateRangeDistanceInput) & {
154
243
  roundToMinute?: boolean;
155
244
  };
156
245
  /**
157
- * Creates a DateRange from the input DateRangeParams
246
+ * Creates a {@link DateRange} from the given type and optional parameters. Supports many range
247
+ * strategies including fixed periods (day, week, month), directional ranges, and radii.
248
+ *
249
+ * @throws Error if the type is not a recognized {@link DateRangeType}
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * // Full day range for today
254
+ * dateRange(DateRangeType.DAY);
158
255
  *
159
- * @param param0
160
- * @param roundToMinute
161
- * @returns
256
+ * // 3 days forward from a specific date
257
+ * dateRange({ type: DateRangeType.DAYS_RANGE, date: new Date('2024-01-01'), distance: 3 });
258
+ *
259
+ * // Calendar month view (includes surrounding weeks)
260
+ * dateRange({ type: DateRangeType.CALENDAR_MONTH, date: new Date('2024-06-15') });
261
+ * ```
162
262
  */
163
263
  export declare function dateRange(input: DateRangeType | DateRangeInput, inputRoundToMinute?: boolean): DateRange;
164
264
  /**
165
- * Convenience function that calls dateRange() to return the first millisecond and last millisecond of the input date.
265
+ * Returns a range spanning the full calendar day (first to last millisecond) of the given date.
266
+ * Convenience wrapper around {@link dateRange} with {@link DateRangeType.DAY}.
166
267
  *
167
- * @param date
168
- * @returns
268
+ * @example
269
+ * ```ts
270
+ * const range = dateRangeFromStartAndEndOfDay(new Date('2024-06-15T14:30:00'));
271
+ * // { start: 2024-06-15T00:00:00, end: 2024-06-15T23:59:59.999 }
272
+ * ```
169
273
  */
170
274
  export declare function dateRangeFromStartAndEndOfDay(date: Date): DateRange;
171
275
  /**
@@ -176,15 +280,19 @@ export type IterateDatesInDateRangeFunction = <T = void>(dateRange: DateRange, f
176
280
  * Returns the next value to iterate on.
177
281
  */
178
282
  export type IterateDaysGetNextValueFunction = MapFunction<Date, Date>;
283
+ /**
284
+ * Configuration for creating an {@link IterateDatesInDateRangeFunction} via {@link iterateDaysInDateRangeFunction}.
285
+ * Controls iteration limits and the step function used to advance between dates.
286
+ */
179
287
  export interface IterateDaysInDateRangeFunctionConfig {
180
288
  /**
181
- * (Optiona) Max expansion size for expanding a date range.
289
+ * (Optional) Max number of iterations allowed when iterating a date range.
182
290
  *
183
- * If the expected expansion is larger than this size, an exception is thrown.
291
+ * If the iteration count exceeds this size, behavior depends on {@link throwErrorOnMaxIterations}.
184
292
  *
185
293
  * If 0 or false, there is no max size.
186
294
  *
187
- * Defaults to 4000 days.
295
+ * Defaults to 4000.
188
296
  */
189
297
  readonly maxIterations?: number | 0 | false;
190
298
  /**
@@ -197,35 +305,52 @@ export interface IterateDaysInDateRangeFunctionConfig {
197
305
  }
198
306
  export declare const DEFAULT_ITERATE_DAYS_IN_DATE_RANGE_MAX_ITERATIONS = 4000;
199
307
  export type IterateDaysInDateRangeFunctionConfigInput = IterateDaysInDateRangeFunctionConfig | IterateDaysGetNextValueFunction;
308
+ /**
309
+ * Sentinel error thrown by {@link endItreateDaysInDateRangeEarly} to signal early termination
310
+ * of date range iteration. Caught internally by {@link iterateDaysInDateRangeFunction}.
311
+ */
200
312
  export declare class IterateDaysInDateRangeFunctionBailError extends Error {
201
313
  constructor(message?: string);
202
314
  }
203
315
  /**
204
- * Call to end iterating days in a date range early.
316
+ * Throws a {@link IterateDaysInDateRangeFunctionBailError} to stop date range iteration early
317
+ * from within a forEach callback. Only works inside functions created by {@link iterateDaysInDateRangeFunction}.
318
+ *
319
+ * @throws {@link IterateDaysInDateRangeFunctionBailError} always
205
320
  */
206
321
  export declare function endItreateDaysInDateRangeEarly(): void;
207
322
  /**
208
- * Creates an IterateDaysInDateRangeFunction
323
+ * Creates a reusable function that iterates over dates within a range using a configurable step function.
324
+ * Supports max iteration limits and early bail-out via {@link endItreateDaysInDateRangeEarly}.
209
325
  *
210
- * @param getNextDate
211
- * @returns
326
+ * @throws Error if max iterations is exceeded and throwErrorOnMaxIterations is true
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * // Iterate every 2 days
331
+ * const iterateEvery2Days = iterateDaysInDateRangeFunction((date) => addDays(date, 2));
332
+ * const results = iterateEvery2Days(range, (date) => date.toISOString());
333
+ * ```
212
334
  */
213
335
  export declare function iterateDaysInDateRangeFunction(input: IterateDaysInDateRangeFunctionConfigInput): IterateDatesInDateRangeFunction;
214
336
  /**
215
- * Iterates date values within the given DateRange.
337
+ * Iterates over dates within a {@link DateRange}, advancing by the provided getNextDate step function.
338
+ * A simpler alternative to {@link iterateDaysInDateRangeFunction} for one-off usage.
216
339
  */
217
340
  export declare function iterateDaysInDateRange(dateRange: DateRange, forEachFn: (date: Date) => void, getNextDate: (date: Date) => Date): void;
218
341
  export declare function iterateDaysInDateRange<T>(dateRange: DateRange, forEachFn: (date: Date) => T, getNextDate: (date: Date) => Date): T[];
219
342
  /**
220
- * Iterates each day in the date range, starting from the start date.
221
- *
222
- * @param dateRange
223
- * @param forEachFn
343
+ * Pre-built iteration function that steps one day at a time through a {@link DateRange}.
344
+ * Calls the provided function for each day starting from the range's start date.
224
345
  */
225
346
  export declare const forEachDayInDateRange: IterateDatesInDateRangeFunction;
347
+ /**
348
+ * Configuration for {@link expandDaysForDateRangeFunction} controlling the safety limit
349
+ * on how many days can be expanded from a single range.
350
+ */
226
351
  export interface ExpandDaysForDateRangeConfig {
227
352
  /**
228
- * (Optiona) Max expansion size for expanding a date range.
353
+ * (Optional) Max expansion size for expanding a date range.
229
354
  *
230
355
  * If the expected expansion is larger than this size, an exception is thrown.
231
356
  *
@@ -238,23 +363,40 @@ export interface ExpandDaysForDateRangeConfig {
238
363
  export declare const DEFAULT_EXPAND_DAYS_FOR_DATE_RANGE_MAX_EXPANSION_SIZE = 1500;
239
364
  export type ExpandDaysForDateRangeFunction = FactoryWithRequiredInput<Date[], DateRange>;
240
365
  /**
241
- * Expands the input range into dates.
366
+ * Creates a reusable function that expands a {@link DateRange} into an array of individual day dates.
367
+ * Includes a configurable safety limit to prevent accidental memory exhaustion from large ranges.
242
368
  *
243
- * @param param0
369
+ * @throws Error if the range spans more days than the configured maxExpansionSize
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * const expand = expandDaysForDateRangeFunction({ maxExpansionSize: 365 });
374
+ * const days = expand({ start: new Date('2024-01-01'), end: new Date('2024-01-03') });
375
+ * // [2024-01-01, 2024-01-02, 2024-01-03]
376
+ * ```
244
377
  */
245
378
  export declare function expandDaysForDateRangeFunction(config?: ExpandDaysForDateRangeConfig): ExpandDaysForDateRangeFunction;
246
379
  /**
247
- * Expands the input range to the days.
380
+ * Expands a {@link DateRange} into an array of one Date per day. Uses the default max expansion size.
381
+ * Convenience wrapper around {@link expandDaysForDateRangeFunction}.
248
382
  *
249
- * @param range
250
- * @returns
383
+ * @example
384
+ * ```ts
385
+ * const days = expandDaysForDateRange({ start: new Date('2024-01-01'), end: new Date('2024-01-03') });
386
+ * // [2024-01-01, 2024-01-02, 2024-01-03]
387
+ * ```
251
388
  */
252
389
  export declare function expandDaysForDateRange(range: DateRange): Date[];
253
390
  /**
254
- * Returns the DateRelativeState from the input DateRange.
391
+ * Determines whether the current moment (or provided `now`) falls before, within, or after the given range.
255
392
  *
256
- * @param param0
257
- * @returns
393
+ * @example
394
+ * ```ts
395
+ * const range = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
396
+ * dateRangeRelativeState(range, new Date('2024-06-15')); // 'present'
397
+ * dateRangeRelativeState(range, new Date('2025-01-01')); // 'past'
398
+ * dateRangeRelativeState(range, new Date('2023-12-31')); // 'future'
399
+ * ```
258
400
  */
259
401
  export declare function dateRangeRelativeState({ start, end }: DateRange, now?: Date): DateRelativeState;
260
402
  export interface GroupDateRangesByDateRelativeStatesResult<T extends DateRange> {
@@ -262,6 +404,19 @@ export interface GroupDateRangesByDateRelativeStatesResult<T extends DateRange>
262
404
  readonly present: T[];
263
405
  readonly future: T[];
264
406
  }
407
+ /**
408
+ * Groups an array of date ranges into past, present, and future buckets based on the current moment (or provided `now`).
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * const ranges = [
413
+ * { start: new Date('2023-01-01'), end: new Date('2023-12-31') },
414
+ * { start: new Date('2024-06-01'), end: new Date('2024-06-30') },
415
+ * ];
416
+ * const grouped = groupDateRangesByDateRelativeState(ranges, new Date('2024-06-15'));
417
+ * // grouped.past = [first range], grouped.present = [second range], grouped.future = []
418
+ * ```
419
+ */
265
420
  export declare function groupDateRangesByDateRelativeState<T extends DateRange>(dateRanges: T[], now?: Date): GroupDateRangesByDateRelativeStatesResult<T>;
266
421
  export type DateRangeFunctionDateRangeRef<T extends Partial<DateRange> = Partial<DateRange>> = {
267
422
  readonly _dateRange: T;
@@ -272,92 +427,215 @@ export type DateRangeFunctionDateRangeRef<T extends Partial<DateRange> = Partial
272
427
  * A dateRange that has no start and end is considered to include all dates.
273
428
  */
274
429
  export type IsDateInDateRangeFunction<T extends Partial<DateRange> = DateRange> = ((date: Date) => boolean) & DateRangeFunctionDateRangeRef<T>;
430
+ /**
431
+ * Checks whether a date falls within a (possibly partial) date range.
432
+ * Convenience wrapper around {@link isDateInDateRangeFunction}.
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * const range = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
437
+ * isDateInDateRange(new Date('2024-06-15'), range); // true
438
+ * isDateInDateRange(new Date('2025-01-01'), range); // false
439
+ * ```
440
+ */
275
441
  export declare function isDateInDateRange(date: Date, dateRange: Partial<DateRange>): boolean;
276
442
  /**
277
- * Creates an IsDateInDateRangeFunction
443
+ * Creates a reusable function that tests whether dates fall within the given range.
444
+ * Handles partial ranges: if only start is set, checks >= start; if only end, checks <= end;
445
+ * if neither, all dates are considered in range.
278
446
  *
279
- * @param dateRange
280
- * @returns
447
+ * @example
448
+ * ```ts
449
+ * const isInQ1 = isDateInDateRangeFunction({
450
+ * start: new Date('2024-01-01'),
451
+ * end: new Date('2024-03-31')
452
+ * });
453
+ * isInQ1(new Date('2024-02-15')); // true
454
+ * isInQ1(new Date('2024-05-01')); // false
455
+ * ```
281
456
  */
282
457
  export declare function isDateInDateRangeFunction<T extends Partial<DateRange>>(dateRange: T): IsDateInDateRangeFunction<T>;
283
458
  /**
284
459
  * Returns true if the input DateRange is contained within the configured DateRange.
285
460
  */
286
461
  export type IsDateRangeInDateRangeFunction<T extends Partial<DateRange> = Partial<DateRange>> = ((dateRange: DateRange) => boolean) & DateRangeFunctionDateRangeRef<T>;
462
+ /**
463
+ * Checks whether a date range is fully contained within another (possibly partial) date range.
464
+ * Convenience wrapper around {@link isDateRangeInDateRangeFunction}.
465
+ *
466
+ * @example
467
+ * ```ts
468
+ * const outer = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
469
+ * const inner = { start: new Date('2024-03-01'), end: new Date('2024-06-30') };
470
+ * isDateRangeInDateRange(inner, outer); // true
471
+ * ```
472
+ */
287
473
  export declare function isDateRangeInDateRange(compareDateRange: DateRange, dateRange: Partial<DateRange>): boolean;
288
474
  /**
289
- * Creates an IsDateRangeInDateRangeFunction
475
+ * Creates a reusable function that tests whether a given date range is fully contained within
476
+ * the configured boundary range. Both start and end of the input must be within bounds.
290
477
  *
291
- * @param dateRange
292
- * @returns
478
+ * @example
479
+ * ```ts
480
+ * const isInYear = isDateRangeInDateRangeFunction({
481
+ * start: new Date('2024-01-01'),
482
+ * end: new Date('2024-12-31')
483
+ * });
484
+ * isInYear({ start: new Date('2024-03-01'), end: new Date('2024-06-30') }); // true
485
+ * isInYear({ start: new Date('2023-12-01'), end: new Date('2024-06-30') }); // false
486
+ * ```
293
487
  */
294
488
  export declare function isDateRangeInDateRangeFunction<T extends Partial<DateRange> = DateRange>(dateRange: T): IsDateRangeInDateRangeFunction<T>;
295
489
  /**
296
490
  * Returns true if the input DateRange overlaps the configured DateRange in any way.
297
491
  */
298
492
  export type DateRangeOverlapsDateRangeFunction<T extends DateRange = DateRange> = ((dateRange: DateRangeStart & Partial<DateRange>) => boolean) & DateRangeFunctionDateRangeRef<T>;
493
+ /**
494
+ * Checks whether two date ranges overlap in any way (partial or full).
495
+ * Convenience wrapper around {@link dateRangeOverlapsDateRangeFunction}.
496
+ *
497
+ * @example
498
+ * ```ts
499
+ * const a = { start: new Date('2024-01-01'), end: new Date('2024-06-30') };
500
+ * const b = { start: new Date('2024-03-01'), end: new Date('2024-12-31') };
501
+ * dateRangeOverlapsDateRange(a, b); // true
502
+ * ```
503
+ */
299
504
  export declare function dateRangeOverlapsDateRange(compareDateRange: DateRange, dateRange: DateRange): boolean;
300
505
  /**
301
- * Creates an DateRangeOverlapsDateRangeFunction
506
+ * Creates a reusable function that tests whether input ranges overlap the configured boundary range.
507
+ * Two ranges overlap if one starts before the other ends, and vice versa.
302
508
  *
303
- * @param dateRange
304
- * @returns
509
+ * @example
510
+ * ```ts
511
+ * const overlapsQ1 = dateRangeOverlapsDateRangeFunction({
512
+ * start: new Date('2024-01-01'),
513
+ * end: new Date('2024-03-31')
514
+ * });
515
+ * overlapsQ1({ start: new Date('2024-03-15'), end: new Date('2024-04-15') }); // true
516
+ * overlapsQ1({ start: new Date('2024-05-01'), end: new Date('2024-06-01') }); // false
517
+ * ```
305
518
  */
306
519
  export declare function dateRangeOverlapsDateRangeFunction<T extends DateRange = DateRange>(dateRange: T): DateRangeOverlapsDateRangeFunction<T>;
307
520
  /**
308
- * Reduces the UTC date range to represent a 24 hour period.
521
+ * Collapses a multi-day UTC date range down to a single 24-hour period, preserving only the
522
+ * time-of-day relationship between start and end. Useful for extracting a daily schedule window
523
+ * from a range that may span multiple days.
309
524
  *
310
- * For example, a range of 10AM one day to 1PM three days later will be simplified to 10AM to 1PM.
525
+ * The order of times is retained. If start and end share the same time but span multiple days,
526
+ * the result is a full 24-hour period.
311
527
  *
312
- * The order of times is retained. Date ranges that are 1PM to 10AM three days later will be simplified to 1PM to 10AM.
528
+ * Operates in UTC, so daylight savings transitions are not considered.
313
529
  *
314
- * For the UTC timezone, meaning changes in daylight savings are not considered.
530
+ * @example
531
+ * ```ts
532
+ * // 10AM to 1PM across 3 days becomes same-day 10AM to 1PM
533
+ * const range = { start: new Date('2024-01-01T10:00:00Z'), end: new Date('2024-01-03T13:00:00Z') };
534
+ * const fitted = fitUTCDateRangeToDayPeriod(range);
535
+ * // fitted.start = 2024-01-01T10:00:00Z, fitted.end = 2024-01-01T13:00:00Z
536
+ * ```
315
537
  */
316
538
  export declare function fitUTCDateRangeToDayPeriod<T extends DateRange = DateRange>(dateRange: T): T;
317
539
  /**
318
540
  * Clamps the input range to the pre-configured date range.
319
541
  */
320
542
  export type ClampDateFunction = ((date: Date) => Date) & DateRangeFunctionDateRangeRef;
543
+ /**
544
+ * Creates a reusable function that clamps dates to fall within the given range boundaries.
545
+ * Dates before start are clamped to start; dates after end are clamped to end.
546
+ * Partial ranges clamp only on the side that is defined.
547
+ *
548
+ * @example
549
+ * ```ts
550
+ * const clamp = clampDateFunction({
551
+ * start: new Date('2024-01-01'),
552
+ * end: new Date('2024-12-31')
553
+ * });
554
+ * clamp(new Date('2023-06-15')); // 2024-01-01
555
+ * clamp(new Date('2024-06-15')); // 2024-06-15 (unchanged)
556
+ * clamp(new Date('2025-06-15')); // 2024-12-31
557
+ * ```
558
+ */
321
559
  export declare function clampDateFunction(dateRange: Partial<DateRange>): ClampDateFunction;
322
560
  /**
323
- * Clamps the date to the date range. Convenience function for clampDateFunction().
561
+ * Clamps a single date to fall within the given range boundaries.
562
+ * Convenience wrapper around {@link clampDateFunction}.
324
563
  *
325
- * @param date
326
- * @param dateRange
327
- * @returns
564
+ * @example
565
+ * ```ts
566
+ * const range = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
567
+ * clampDateToDateRange(new Date('2023-06-15'), range); // 2024-01-01
568
+ * ```
328
569
  */
329
570
  export declare function clampDateToDateRange(date: Date, dateRange: Partial<DateRange>): Date;
330
571
  export type ClampPartialDateRangeFunction = ((date: Partial<DateRange>, clampNullValues?: boolean) => Partial<DateRange>) & DateRangeFunctionDateRangeRef;
331
572
  export type ClampDateRangeFunction = ((date: Partial<DateRange>, clampNullValues?: boolean) => DateRange) & DateRangeFunctionDateRangeRef<DateRange>;
573
+ /**
574
+ * Creates a reusable function that clamps an entire date range to fit within the configured boundaries.
575
+ * When `clampNullValues` is true, missing start/end values on the input are replaced with the boundary values.
576
+ *
577
+ * @example
578
+ * ```ts
579
+ * const clamp = clampDateRangeFunction({
580
+ * start: new Date('2024-01-01'),
581
+ * end: new Date('2024-12-31')
582
+ * });
583
+ * const result = clamp({ start: new Date('2023-06-01'), end: new Date('2024-06-30') });
584
+ * // { start: 2024-01-01, end: 2024-06-30 }
585
+ * ```
586
+ */
332
587
  export declare function clampDateRangeFunction(dateRange: DateRange, defaultClampNullValues?: boolean): ClampDateRangeFunction;
333
588
  export declare function clampDateRangeFunction(dateRange: Partial<DateRange>, defaultClampNullValues?: boolean): ClampPartialDateRangeFunction;
334
589
  /**
335
- * Clamps the input range to the second date range. Convenience function for clampDateRangeFunction().
590
+ * Clamps a date range to fit within a boundary range.
591
+ * Convenience wrapper around {@link clampDateRangeFunction}.
336
592
  *
337
- * @param inputDateRange
338
- * @param limitToDateRange
339
- * @returns
593
+ * @example
594
+ * ```ts
595
+ * const input = { start: new Date('2023-06-01'), end: new Date('2024-06-30') };
596
+ * const limit = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
597
+ * clampDateRangeToDateRange(input, limit);
598
+ * // { start: 2024-01-01, end: 2024-06-30 }
599
+ * ```
340
600
  */
341
601
  export declare function clampDateRangeToDateRange(inputDateRange: Partial<DateRange>, limitToDateRange: Partial<DateRange>): Partial<DateRange>;
342
602
  /**
343
603
  * Transforms both of the dates in the date range function.
344
604
  */
345
605
  export type TransformDateRangeDatesFunction = (dateRange: DateRange) => DateRange;
606
+ /**
607
+ * Creates a function that applies a date transformation to both start and end of a {@link DateRange}.
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * import { startOfHour } from 'date-fns';
612
+ * const roundToHour = transformDateRangeDatesFunction(startOfHour);
613
+ * const range = { start: new Date('2024-01-01T10:30:00'), end: new Date('2024-01-01T14:45:00') };
614
+ * roundToHour(range); // { start: 2024-01-01T10:00:00, end: 2024-01-01T14:00:00 }
615
+ * ```
616
+ */
346
617
  export declare function transformDateRangeDatesFunction(transform: MapFunction<Date, Date>): TransformDateRangeDatesFunction;
347
618
  /**
348
- * TransformDateRangeDatesFunction that transforms the input dates to the start of the day.
619
+ * Pre-built {@link TransformDateRangeDatesFunction} that rounds both start and end to the beginning of their respective days.
349
620
  */
350
621
  export declare const transformDateRangeWithStartOfDay: TransformDateRangeDatesFunction;
351
622
  /**
352
- * DateRange that has values comprised of either a Date, ISO8601DateString, or ISO8601DayString
623
+ * Variant of {@link DateRange} that accepts Date objects, ISO 8601 date-time strings, or ISO 8601 day strings
624
+ * as values, useful for accepting serialized date range input before parsing.
353
625
  */
354
626
  export interface DateRangeWithDateOrStringValue {
355
627
  start: DateOrDateString | ISO8601DayString;
356
628
  end: DateOrDateString | ISO8601DayString;
357
629
  }
358
630
  /**
359
- * Returns each unique day of the week in the date range in the order they appear.
631
+ * Returns each unique day of the week present in the range, in the order they appear starting from
632
+ * the range's start day. For ranges spanning 7+ days, returns all days of the week.
360
633
  *
361
- * @param dateRange
634
+ * @example
635
+ * ```ts
636
+ * // Wednesday through Friday
637
+ * const range = { start: new Date('2024-01-03'), end: new Date('2024-01-05') };
638
+ * getDaysOfWeekInDateRange(range); // [3, 4, 5] (Wed, Thu, Fri)
639
+ * ```
362
640
  */
363
641
  export declare function getDaysOfWeekInDateRange(dateRange: DateRange): DayOfWeek[];