@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.
- package/index.cjs.js +987 -356
- package/index.esm.js +983 -357
- package/package.json +5 -4
- package/src/lib/date/date.calendar.d.ts +3 -3
- package/src/lib/date/date.cell.d.ts +5 -0
- package/src/lib/date/date.cell.factory.d.ts +77 -0
- package/src/lib/date/date.cell.filter.d.ts +7 -0
- package/src/lib/date/date.cell.index.d.ts +44 -4
- package/src/lib/date/date.cell.schedule.d.ts +2 -0
- package/src/lib/date/date.d.ts +6 -0
- package/src/lib/date/date.day.d.ts +22 -3
- package/src/lib/date/date.format.d.ts +70 -8
- package/src/lib/date/date.range.d.ts +105 -2
- package/src/lib/date/date.range.timezone.d.ts +1 -0
- package/src/lib/date/date.time.d.ts +12 -0
- package/src/lib/date/date.time.limit.d.ts +9 -0
- package/src/lib/date/date.time.minute.d.ts +28 -0
- package/src/lib/date/date.timezone.d.ts +107 -15
- package/src/lib/date/date.week.d.ts +9 -4
- package/src/lib/date/index.d.ts +0 -1
- package/src/lib/query/query.builder.mongo.d.ts +9 -3
- package/src/lib/rrule/date.recurrence.d.ts +21 -7
- package/src/lib/rrule/date.rrule.d.ts +2 -0
- package/src/lib/rrule/date.rrule.extension.d.ts +10 -0
- package/src/lib/rrule/date.rrule.parse.d.ts +41 -0
- package/src/lib/timezone/index.d.ts +0 -1
- package/src/lib/timezone/timezone.d.ts +38 -4
|
@@ -8,6 +8,9 @@ export interface DateRangeStart {
|
|
|
8
8
|
/**
|
|
9
9
|
* Type guard to check if a value conforms to the {@link DateRangeStart} interface.
|
|
10
10
|
*
|
|
11
|
+
* @param value - the value to check
|
|
12
|
+
* @returns true if the value has a valid Date `start` property
|
|
13
|
+
*
|
|
11
14
|
* @example
|
|
12
15
|
* ```ts
|
|
13
16
|
* isDateRangeStart({ start: new Date() }); // true
|
|
@@ -41,6 +44,9 @@ export interface DateRange extends DateRangeStart {
|
|
|
41
44
|
* Counts the total number of calendar days spanned by the range, inclusive of both endpoints.
|
|
42
45
|
* Always returns at least 1, even for same-day ranges.
|
|
43
46
|
*
|
|
47
|
+
* @param dateRange - the date range to measure
|
|
48
|
+
* @returns the number of days in the range, inclusive
|
|
49
|
+
*
|
|
44
50
|
* @example
|
|
45
51
|
* ```ts
|
|
46
52
|
* const range = { start: new Date('2024-01-01'), end: new Date('2024-01-03') };
|
|
@@ -51,6 +57,9 @@ export declare function dateRangeDaysCount(dateRange: DateRange): number;
|
|
|
51
57
|
/**
|
|
52
58
|
* Type guard to check if a value is a valid {@link DateRange} with both start and end as Date objects.
|
|
53
59
|
*
|
|
60
|
+
* @param input - the value to check
|
|
61
|
+
* @returns true if the value has valid Date `start` and `end` properties
|
|
62
|
+
*
|
|
54
63
|
* @example
|
|
55
64
|
* ```ts
|
|
56
65
|
* isDateRange({ start: new Date(), end: new Date() }); // true
|
|
@@ -63,6 +72,10 @@ export declare function isDateRange(input: unknown): input is DateRange;
|
|
|
63
72
|
* Compares two date ranges for exact millisecond equality on both start and end.
|
|
64
73
|
* Returns true if both are nullish.
|
|
65
74
|
*
|
|
75
|
+
* @param a - first date range to compare
|
|
76
|
+
* @param b - second date range to compare
|
|
77
|
+
* @returns true if both ranges are equal or both are nullish
|
|
78
|
+
*
|
|
66
79
|
* @example
|
|
67
80
|
* ```ts
|
|
68
81
|
* const a = { start: new Date('2024-01-01'), end: new Date('2024-01-31') };
|
|
@@ -76,6 +89,10 @@ export declare function isSameDateRange(a: Maybe<Partial<DateRange>>, b: Maybe<P
|
|
|
76
89
|
* Compares two date ranges for calendar-day equality, ignoring time-of-day differences.
|
|
77
90
|
* Returns true if both are nullish.
|
|
78
91
|
*
|
|
92
|
+
* @param a - first date range to compare
|
|
93
|
+
* @param b - second date range to compare
|
|
94
|
+
* @returns true if both ranges fall on the same calendar days or both are nullish
|
|
95
|
+
*
|
|
79
96
|
* @example
|
|
80
97
|
* ```ts
|
|
81
98
|
* const a = { start: new Date('2024-01-01T08:00:00'), end: new Date('2024-01-31T10:00:00') };
|
|
@@ -87,6 +104,9 @@ export declare function isSameDateDayRange(a: Maybe<Partial<DateRange>>, b: Mayb
|
|
|
87
104
|
/**
|
|
88
105
|
* Checks whether the range is unbounded (neither start nor end is set), meaning it conceptually includes all dates.
|
|
89
106
|
*
|
|
107
|
+
* @param input - the partial date range to check
|
|
108
|
+
* @returns true if neither start nor end is set
|
|
109
|
+
*
|
|
90
110
|
* @example
|
|
91
111
|
* ```ts
|
|
92
112
|
* isInfiniteDateRange({}); // true
|
|
@@ -97,6 +117,9 @@ export declare function isInfiniteDateRange(input: Partial<DateRange>): boolean;
|
|
|
97
117
|
/**
|
|
98
118
|
* Checks whether the range has only one of start or end set, but not both.
|
|
99
119
|
*
|
|
120
|
+
* @param input - the partial date range to check
|
|
121
|
+
* @returns true if exactly one of start or end is set
|
|
122
|
+
*
|
|
100
123
|
* @example
|
|
101
124
|
* ```ts
|
|
102
125
|
* isPartialDateRange({ start: new Date() }); // true
|
|
@@ -107,6 +130,9 @@ export declare function isPartialDateRange(input: Partial<DateRange>): input is
|
|
|
107
130
|
/**
|
|
108
131
|
* Checks whether the range has both start and end set.
|
|
109
132
|
*
|
|
133
|
+
* @param input - the partial date range to check
|
|
134
|
+
* @returns true if both start and end are set
|
|
135
|
+
*
|
|
110
136
|
* @example
|
|
111
137
|
* ```ts
|
|
112
138
|
* isFullDateRange({ start: new Date(), end: new Date() }); // true
|
|
@@ -122,6 +148,10 @@ export type DateOrDateRange = Date | DateRange;
|
|
|
122
148
|
* Normalizes a Date or {@link DateRange} into a DateRange. When given a single Date,
|
|
123
149
|
* uses it as start and optionally uses the provided end date (defaults to the same date).
|
|
124
150
|
*
|
|
151
|
+
* @param startOrDateRange - a Date or existing DateRange
|
|
152
|
+
* @param end - optional end date when the first argument is a plain Date
|
|
153
|
+
* @returns a DateRange
|
|
154
|
+
*
|
|
125
155
|
* @example
|
|
126
156
|
* ```ts
|
|
127
157
|
* const range = dateOrDateRangeToDateRange(new Date('2024-01-01'), new Date('2024-01-31'));
|
|
@@ -231,6 +261,9 @@ export type DateRangeInput = (DateRangeTypedInput | DateRangeDistanceInput) & {
|
|
|
231
261
|
* Creates a {@link DateRange} from the given type and optional parameters. Supports many range
|
|
232
262
|
* strategies including fixed periods (day, week, month), directional ranges, and radii.
|
|
233
263
|
*
|
|
264
|
+
* @param input - the range type or full configuration object
|
|
265
|
+
* @param inputRoundToMinute - optional override to round the date to the start of its minute
|
|
266
|
+
* @returns a computed DateRange
|
|
234
267
|
* @throws Error if the type is not a recognized {@link DateRangeType}
|
|
235
268
|
*
|
|
236
269
|
* @example
|
|
@@ -250,6 +283,9 @@ export declare function dateRange(input: DateRangeType | DateRangeInput, inputRo
|
|
|
250
283
|
* Returns a range spanning the full calendar day (first to last millisecond) of the given date.
|
|
251
284
|
* Convenience wrapper around {@link dateRange} with {@link DateRangeType.DAY}.
|
|
252
285
|
*
|
|
286
|
+
* @param date - the date whose full day range to return
|
|
287
|
+
* @returns a DateRange from start of day to end of day
|
|
288
|
+
*
|
|
253
289
|
* @example
|
|
254
290
|
* ```ts
|
|
255
291
|
* const range = dateRangeFromStartAndEndOfDay(new Date('2024-06-15T14:30:00'));
|
|
@@ -308,6 +344,8 @@ export declare function endItreateDaysInDateRangeEarly(): void;
|
|
|
308
344
|
* Creates a reusable function that iterates over dates within a range using a configurable step function.
|
|
309
345
|
* Supports max iteration limits and early bail-out via {@link endItreateDaysInDateRangeEarly}.
|
|
310
346
|
*
|
|
347
|
+
* @param input - configuration or a step function for advancing between dates
|
|
348
|
+
* @returns a reusable iteration function
|
|
311
349
|
* @throws Error if max iterations is exceeded and throwErrorOnMaxIterations is true
|
|
312
350
|
*
|
|
313
351
|
* @example
|
|
@@ -321,6 +359,11 @@ export declare function iterateDaysInDateRangeFunction(input: IterateDaysInDateR
|
|
|
321
359
|
/**
|
|
322
360
|
* Iterates over dates within a {@link DateRange}, advancing by the provided getNextDate step function.
|
|
323
361
|
* A simpler alternative to {@link iterateDaysInDateRangeFunction} for one-off usage.
|
|
362
|
+
*
|
|
363
|
+
* @param dateRange - the range to iterate over
|
|
364
|
+
* @param forEachFn - callback invoked for each date in the range
|
|
365
|
+
* @param getNextDate - step function that returns the next date from the current one
|
|
366
|
+
* @returns an array of results from forEachFn, or void
|
|
324
367
|
*/
|
|
325
368
|
export declare function iterateDaysInDateRange(dateRange: DateRange, forEachFn: (date: Date) => void, getNextDate: (date: Date) => Date): void;
|
|
326
369
|
export declare function iterateDaysInDateRange<T>(dateRange: DateRange, forEachFn: (date: Date) => T, getNextDate: (date: Date) => Date): T[];
|
|
@@ -343,7 +386,7 @@ export interface ExpandDaysForDateRangeConfig {
|
|
|
343
386
|
*
|
|
344
387
|
* Defaults to 1500 days.
|
|
345
388
|
*/
|
|
346
|
-
maxExpansionSize?: number | 0 | false;
|
|
389
|
+
readonly maxExpansionSize?: number | 0 | false;
|
|
347
390
|
}
|
|
348
391
|
export declare const DEFAULT_EXPAND_DAYS_FOR_DATE_RANGE_MAX_EXPANSION_SIZE = 1500;
|
|
349
392
|
export type ExpandDaysForDateRangeFunction = FactoryWithRequiredInput<Date[], DateRange>;
|
|
@@ -351,6 +394,8 @@ export type ExpandDaysForDateRangeFunction = FactoryWithRequiredInput<Date[], Da
|
|
|
351
394
|
* Creates a reusable function that expands a {@link DateRange} into an array of individual day dates.
|
|
352
395
|
* Includes a configurable safety limit to prevent accidental memory exhaustion from large ranges.
|
|
353
396
|
*
|
|
397
|
+
* @param config - optional configuration for the max expansion size
|
|
398
|
+
* @returns a function that expands a DateRange into an array of Dates
|
|
354
399
|
* @throws Error if the range spans more days than the configured maxExpansionSize
|
|
355
400
|
*
|
|
356
401
|
* @example
|
|
@@ -365,6 +410,9 @@ export declare function expandDaysForDateRangeFunction(config?: ExpandDaysForDat
|
|
|
365
410
|
* Expands a {@link DateRange} into an array of one Date per day. Uses the default max expansion size.
|
|
366
411
|
* Convenience wrapper around {@link expandDaysForDateRangeFunction}.
|
|
367
412
|
*
|
|
413
|
+
* @param range - the date range to expand
|
|
414
|
+
* @returns an array of Dates, one per day in the range
|
|
415
|
+
*
|
|
368
416
|
* @example
|
|
369
417
|
* ```ts
|
|
370
418
|
* const days = expandDaysForDateRange({ start: new Date('2024-01-01'), end: new Date('2024-01-03') });
|
|
@@ -375,6 +423,12 @@ export declare function expandDaysForDateRange(range: DateRange): Date[];
|
|
|
375
423
|
/**
|
|
376
424
|
* Determines whether the current moment (or provided `now`) falls before, within, or after the given range.
|
|
377
425
|
*
|
|
426
|
+
* @param dateRange - the date range to compare against
|
|
427
|
+
* @param dateRange.start - the start of the range
|
|
428
|
+
* @param dateRange.end - the end of the range
|
|
429
|
+
* @param now - the reference date, defaults to the current moment
|
|
430
|
+
* @returns 'past', 'present', or 'future'
|
|
431
|
+
*
|
|
378
432
|
* @example
|
|
379
433
|
* ```ts
|
|
380
434
|
* const range = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
|
|
@@ -392,6 +446,10 @@ export interface GroupDateRangesByDateRelativeStatesResult<T extends DateRange>
|
|
|
392
446
|
/**
|
|
393
447
|
* Groups an array of date ranges into past, present, and future buckets based on the current moment (or provided `now`).
|
|
394
448
|
*
|
|
449
|
+
* @param dateRanges - the date ranges to group
|
|
450
|
+
* @param _now - the reference date, defaults to the current moment
|
|
451
|
+
* @returns an object with past, present, and future arrays
|
|
452
|
+
*
|
|
395
453
|
* @example
|
|
396
454
|
* ```ts
|
|
397
455
|
* const ranges = [
|
|
@@ -402,7 +460,7 @@ export interface GroupDateRangesByDateRelativeStatesResult<T extends DateRange>
|
|
|
402
460
|
* // grouped.past = [first range], grouped.present = [second range], grouped.future = []
|
|
403
461
|
* ```
|
|
404
462
|
*/
|
|
405
|
-
export declare function groupDateRangesByDateRelativeState<T extends DateRange>(dateRanges: T[],
|
|
463
|
+
export declare function groupDateRangesByDateRelativeState<T extends DateRange>(dateRanges: T[], _now?: Date): GroupDateRangesByDateRelativeStatesResult<T>;
|
|
406
464
|
export type DateRangeFunctionDateRangeRef<T extends Partial<DateRange> = Partial<DateRange>> = {
|
|
407
465
|
readonly _dateRange: T;
|
|
408
466
|
};
|
|
@@ -416,6 +474,10 @@ export type IsDateInDateRangeFunction<T extends Partial<DateRange> = DateRange>
|
|
|
416
474
|
* Checks whether a date falls within a (possibly partial) date range.
|
|
417
475
|
* Convenience wrapper around {@link isDateInDateRangeFunction}.
|
|
418
476
|
*
|
|
477
|
+
* @param date - the date to test
|
|
478
|
+
* @param dateRange - the range to test against
|
|
479
|
+
* @returns true if the date falls within the range
|
|
480
|
+
*
|
|
419
481
|
* @example
|
|
420
482
|
* ```ts
|
|
421
483
|
* const range = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
|
|
@@ -429,6 +491,9 @@ export declare function isDateInDateRange(date: Date, dateRange: Partial<DateRan
|
|
|
429
491
|
* Handles partial ranges: if only start is set, checks >= start; if only end, checks <= end;
|
|
430
492
|
* if neither, all dates are considered in range.
|
|
431
493
|
*
|
|
494
|
+
* @param dateRange - the boundary range to test against
|
|
495
|
+
* @returns a function that tests whether a date falls within the range
|
|
496
|
+
*
|
|
432
497
|
* @example
|
|
433
498
|
* ```ts
|
|
434
499
|
* const isInQ1 = isDateInDateRangeFunction({
|
|
@@ -448,6 +513,10 @@ export type IsDateRangeInDateRangeFunction<T extends Partial<DateRange> = Partia
|
|
|
448
513
|
* Checks whether a date range is fully contained within another (possibly partial) date range.
|
|
449
514
|
* Convenience wrapper around {@link isDateRangeInDateRangeFunction}.
|
|
450
515
|
*
|
|
516
|
+
* @param compareDateRange - the range to test for containment
|
|
517
|
+
* @param dateRange - the boundary range
|
|
518
|
+
* @returns true if compareDateRange is fully within dateRange
|
|
519
|
+
*
|
|
451
520
|
* @example
|
|
452
521
|
* ```ts
|
|
453
522
|
* const outer = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
|
|
@@ -460,6 +529,9 @@ export declare function isDateRangeInDateRange(compareDateRange: DateRange, date
|
|
|
460
529
|
* Creates a reusable function that tests whether a given date range is fully contained within
|
|
461
530
|
* the configured boundary range. Both start and end of the input must be within bounds.
|
|
462
531
|
*
|
|
532
|
+
* @param dateRange - the boundary range
|
|
533
|
+
* @returns a function that tests containment of other ranges
|
|
534
|
+
*
|
|
463
535
|
* @example
|
|
464
536
|
* ```ts
|
|
465
537
|
* const isInYear = isDateRangeInDateRangeFunction({
|
|
@@ -479,6 +551,10 @@ export type DateRangeOverlapsDateRangeFunction<T extends DateRange = DateRange>
|
|
|
479
551
|
* Checks whether two date ranges overlap in any way (partial or full).
|
|
480
552
|
* Convenience wrapper around {@link dateRangeOverlapsDateRangeFunction}.
|
|
481
553
|
*
|
|
554
|
+
* @param compareDateRange - the range to test for overlap
|
|
555
|
+
* @param dateRange - the reference range
|
|
556
|
+
* @returns true if the ranges overlap
|
|
557
|
+
*
|
|
482
558
|
* @example
|
|
483
559
|
* ```ts
|
|
484
560
|
* const a = { start: new Date('2024-01-01'), end: new Date('2024-06-30') };
|
|
@@ -491,6 +567,9 @@ export declare function dateRangeOverlapsDateRange(compareDateRange: DateRange,
|
|
|
491
567
|
* Creates a reusable function that tests whether input ranges overlap the configured boundary range.
|
|
492
568
|
* Two ranges overlap if one starts before the other ends, and vice versa.
|
|
493
569
|
*
|
|
570
|
+
* @param dateRange - the boundary range to test overlap against
|
|
571
|
+
* @returns a function that tests overlap of other ranges
|
|
572
|
+
*
|
|
494
573
|
* @example
|
|
495
574
|
* ```ts
|
|
496
575
|
* const overlapsQ1 = dateRangeOverlapsDateRangeFunction({
|
|
@@ -512,6 +591,9 @@ export declare function dateRangeOverlapsDateRangeFunction<T extends DateRange =
|
|
|
512
591
|
*
|
|
513
592
|
* Operates in UTC, so daylight savings transitions are not considered.
|
|
514
593
|
*
|
|
594
|
+
* @param dateRange - the date range to fit into a single day period
|
|
595
|
+
* @returns a new date range with the same start and an end within 24 hours of start
|
|
596
|
+
*
|
|
515
597
|
* @example
|
|
516
598
|
* ```ts
|
|
517
599
|
* // 10AM to 1PM across 3 days becomes same-day 10AM to 1PM
|
|
@@ -530,6 +612,9 @@ export type ClampDateFunction = ((date: Date) => Date) & DateRangeFunctionDateRa
|
|
|
530
612
|
* Dates before start are clamped to start; dates after end are clamped to end.
|
|
531
613
|
* Partial ranges clamp only on the side that is defined.
|
|
532
614
|
*
|
|
615
|
+
* @param dateRange - the boundary range for clamping
|
|
616
|
+
* @returns a function that clamps dates to the range
|
|
617
|
+
*
|
|
533
618
|
* @example
|
|
534
619
|
* ```ts
|
|
535
620
|
* const clamp = clampDateFunction({
|
|
@@ -546,6 +631,10 @@ export declare function clampDateFunction(dateRange: Partial<DateRange>): ClampD
|
|
|
546
631
|
* Clamps a single date to fall within the given range boundaries.
|
|
547
632
|
* Convenience wrapper around {@link clampDateFunction}.
|
|
548
633
|
*
|
|
634
|
+
* @param date - the date to clamp
|
|
635
|
+
* @param dateRange - the boundary range
|
|
636
|
+
* @returns the clamped date
|
|
637
|
+
*
|
|
549
638
|
* @example
|
|
550
639
|
* ```ts
|
|
551
640
|
* const range = { start: new Date('2024-01-01'), end: new Date('2024-12-31') };
|
|
@@ -559,6 +648,10 @@ export type ClampDateRangeFunction = ((date: Partial<DateRange>, clampNullValues
|
|
|
559
648
|
* Creates a reusable function that clamps an entire date range to fit within the configured boundaries.
|
|
560
649
|
* When `clampNullValues` is true, missing start/end values on the input are replaced with the boundary values.
|
|
561
650
|
*
|
|
651
|
+
* @param dateRange - the boundary range for clamping
|
|
652
|
+
* @param defaultClampNullValues - whether to fill missing values with boundary values
|
|
653
|
+
* @returns a function that clamps date ranges
|
|
654
|
+
*
|
|
562
655
|
* @example
|
|
563
656
|
* ```ts
|
|
564
657
|
* const clamp = clampDateRangeFunction({
|
|
@@ -575,6 +668,10 @@ export declare function clampDateRangeFunction(dateRange: Partial<DateRange>, de
|
|
|
575
668
|
* Clamps a date range to fit within a boundary range.
|
|
576
669
|
* Convenience wrapper around {@link clampDateRangeFunction}.
|
|
577
670
|
*
|
|
671
|
+
* @param inputDateRange - the date range to clamp
|
|
672
|
+
* @param limitToDateRange - the boundary range
|
|
673
|
+
* @returns the clamped date range
|
|
674
|
+
*
|
|
578
675
|
* @example
|
|
579
676
|
* ```ts
|
|
580
677
|
* const input = { start: new Date('2023-06-01'), end: new Date('2024-06-30') };
|
|
@@ -591,6 +688,9 @@ export type TransformDateRangeDatesFunction = (dateRange: DateRange) => DateRang
|
|
|
591
688
|
/**
|
|
592
689
|
* Creates a function that applies a date transformation to both start and end of a {@link DateRange}.
|
|
593
690
|
*
|
|
691
|
+
* @param transform - the transformation to apply to both dates
|
|
692
|
+
* @returns a function that transforms both dates of a DateRange
|
|
693
|
+
*
|
|
594
694
|
* @example
|
|
595
695
|
* ```ts
|
|
596
696
|
* import { startOfHour } from 'date-fns';
|
|
@@ -616,6 +716,9 @@ export interface DateRangeWithDateOrStringValue {
|
|
|
616
716
|
* Returns each unique day of the week present in the range, in the order they appear starting from
|
|
617
717
|
* the range's start day. For ranges spanning 7+ days, returns all days of the week.
|
|
618
718
|
*
|
|
719
|
+
* @param dateRange - the date range to inspect
|
|
720
|
+
* @returns an array of unique day-of-week values present in the range
|
|
721
|
+
*
|
|
619
722
|
* @example
|
|
620
723
|
* ```ts
|
|
621
724
|
* // Wednesday through Friday
|
|
@@ -32,5 +32,6 @@ export declare function fitDateRangeToDayPeriodFunction(timezone: DateTimezoneUt
|
|
|
32
32
|
*
|
|
33
33
|
* @param dateRange - the range to fit
|
|
34
34
|
* @param timezone - the timezone for day boundary calculation
|
|
35
|
+
* @returns the date range fitted to a single day period
|
|
35
36
|
*/
|
|
36
37
|
export declare function fitDateRangeToDayPeriod<T extends DateRange = DateRange>(dateRange: T, timezone: DateTimezoneUtcNormalFunctionInput): T;
|
|
@@ -63,6 +63,7 @@ export interface ValidDateFromTimestringResult extends Required<DateFromTimestri
|
|
|
63
63
|
* guaranteeing that `raw` and `result` are defined.
|
|
64
64
|
*
|
|
65
65
|
* @param result - The parse result to check.
|
|
66
|
+
* @returns `true` if the result is valid, narrowing the type to {@link ValidDateFromTimestringResult}.
|
|
66
67
|
*
|
|
67
68
|
* @example
|
|
68
69
|
* ```ts
|
|
@@ -99,6 +100,7 @@ export declare class DateTimeUtilityInstance {
|
|
|
99
100
|
*
|
|
100
101
|
* @param date - The date to check. Defaults to now.
|
|
101
102
|
* @param timezone - Overrides the instance's configured timezone for this call.
|
|
103
|
+
* @returns {@link TimeAM.AM} or {@link TimeAM.PM} depending on the time of day.
|
|
102
104
|
*
|
|
103
105
|
* @example
|
|
104
106
|
* ```ts
|
|
@@ -112,6 +114,7 @@ export declare class DateTimeUtilityInstance {
|
|
|
112
114
|
*
|
|
113
115
|
* @param date - The date to format.
|
|
114
116
|
* @param timezone - Overrides the instance's configured timezone for this call.
|
|
117
|
+
* @returns The formatted time string (e.g., "1:30PM").
|
|
115
118
|
*
|
|
116
119
|
* @example
|
|
117
120
|
* ```ts
|
|
@@ -163,6 +166,8 @@ export declare class DateTimeUtilityInstance {
|
|
|
163
166
|
/**
|
|
164
167
|
* Creates a {@link DateTimeUtilityInstance} configured for UTC.
|
|
165
168
|
*
|
|
169
|
+
* @returns A new {@link DateTimeUtilityInstance} using the UTC timezone.
|
|
170
|
+
*
|
|
166
171
|
* @example
|
|
167
172
|
* ```ts
|
|
168
173
|
* const utcInstance = dateTimeInstanceUtc();
|
|
@@ -175,6 +180,7 @@ export declare function dateTimeInstanceUtc(): DateTimeUtilityInstance;
|
|
|
175
180
|
* Defaults to UTC when no timezone is provided.
|
|
176
181
|
*
|
|
177
182
|
* @param timezone - The IANA timezone identifier (e.g., 'America/New_York').
|
|
183
|
+
* @returns A new {@link DateTimeUtilityInstance} for the specified timezone.
|
|
178
184
|
*
|
|
179
185
|
* @example
|
|
180
186
|
* ```ts
|
|
@@ -188,6 +194,7 @@ export declare function dateTimeInstance(timezone?: Maybe<TimezoneString>): Date
|
|
|
188
194
|
*
|
|
189
195
|
* @param date - The date to check. Defaults to now.
|
|
190
196
|
* @param timezone - The IANA timezone to evaluate in. Defaults to UTC.
|
|
197
|
+
* @returns {@link TimeAM.AM} or {@link TimeAM.PM} depending on the time of day.
|
|
191
198
|
*
|
|
192
199
|
* @example
|
|
193
200
|
* ```ts
|
|
@@ -203,6 +210,7 @@ export declare function getTimeAM(date?: Date, timezone?: Maybe<TimezoneString>)
|
|
|
203
210
|
* unlike {@link toReadableTimeString} which defaults to UTC.
|
|
204
211
|
*
|
|
205
212
|
* @param date - The date to format.
|
|
213
|
+
* @returns The formatted time string in the system's local timezone.
|
|
206
214
|
*
|
|
207
215
|
* @example
|
|
208
216
|
* ```ts
|
|
@@ -215,6 +223,7 @@ export declare function toLocalReadableTimeString(date: Date): ReadableTimeStrin
|
|
|
215
223
|
*
|
|
216
224
|
* @param date - The date to format.
|
|
217
225
|
* @param timezone - The IANA timezone to format in. Defaults to UTC.
|
|
226
|
+
* @returns The formatted time string (e.g., "10:30AM").
|
|
218
227
|
*
|
|
219
228
|
* @example
|
|
220
229
|
* ```ts
|
|
@@ -229,6 +238,7 @@ export declare function toReadableTimeString(date: Date, timezone?: Maybe<Timezo
|
|
|
229
238
|
*
|
|
230
239
|
* @param input - A time string such as "1:30PM", "13:30", or "1PM".
|
|
231
240
|
* @param config - Optional configuration specifying the timezone and reference date.
|
|
241
|
+
* @returns The parsed time string result, or `undefined` if parsing failed.
|
|
232
242
|
*
|
|
233
243
|
* @example
|
|
234
244
|
* ```ts
|
|
@@ -246,6 +256,7 @@ export declare function parseReadableTimeString(input: ReadableTimeString, confi
|
|
|
246
256
|
*
|
|
247
257
|
* @param input - A time string such as "1:30PM" or "13:30".
|
|
248
258
|
* @param config - Optional configuration specifying the timezone and reference date.
|
|
259
|
+
* @returns The resolved date, or `undefined` if the input could not be parsed.
|
|
249
260
|
*
|
|
250
261
|
* @example
|
|
251
262
|
* ```ts
|
|
@@ -257,6 +268,7 @@ export declare function readableTimeStringToDate(input: ReadableTimeString, conf
|
|
|
257
268
|
* Creates a {@link LimitDateTimeInstance} for clamping and constraining dates to a configured range.
|
|
258
269
|
*
|
|
259
270
|
* @param config - The limit configuration specifying min/max bounds, future requirements, etc.
|
|
271
|
+
* @returns A new {@link LimitDateTimeInstance} configured with the given bounds.
|
|
260
272
|
*
|
|
261
273
|
* @example
|
|
262
274
|
* ```ts
|
|
@@ -78,6 +78,8 @@ export declare class LimitDateTimeInstance {
|
|
|
78
78
|
* const limiter = new LimitDateTimeInstance({ limits: { isFuture: true } });
|
|
79
79
|
* const range = limiter.dateRange(); // { start: <now>, end: undefined }
|
|
80
80
|
* ```
|
|
81
|
+
*
|
|
82
|
+
* @returns A partial {@link DateRange} with `start` and/or `end` derived from the limits.
|
|
81
83
|
*/
|
|
82
84
|
dateRange(): Partial<DateRange>;
|
|
83
85
|
/**
|
|
@@ -85,6 +87,7 @@ export declare class LimitDateTimeInstance {
|
|
|
85
87
|
* like "now" or relative future offsets to resolve against the given moment.
|
|
86
88
|
*
|
|
87
89
|
* @param instant - The reference point in time for resolving dynamic limits.
|
|
90
|
+
* @returns A partial {@link DateRange} resolved against the given instant.
|
|
88
91
|
*/
|
|
89
92
|
dateRangeForInstant(instant: Date): {
|
|
90
93
|
start: Date | undefined;
|
|
@@ -103,6 +106,8 @@ export declare class LimitDateTimeInstance {
|
|
|
103
106
|
* });
|
|
104
107
|
* const safe = limiter.clamp(new Date()); // at least 30 minutes from now
|
|
105
108
|
* ```
|
|
109
|
+
*
|
|
110
|
+
* @returns The clamped date within the allowed range.
|
|
106
111
|
*/
|
|
107
112
|
clamp(date: Date): Date;
|
|
108
113
|
/**
|
|
@@ -117,6 +122,8 @@ export declare class LimitDateTimeInstance {
|
|
|
117
122
|
* const clamped = limiter.clampDateRange({ start: pastDate, end: futureDate });
|
|
118
123
|
* // clamped.start will be at least now
|
|
119
124
|
* ```
|
|
125
|
+
*
|
|
126
|
+
* @returns The date range clamped to the allowed limits.
|
|
120
127
|
*/
|
|
121
128
|
clampDateRange(dateRange: DateRange): DateRange;
|
|
122
129
|
}
|
|
@@ -133,5 +140,7 @@ export declare class LimitDateTimeInstance {
|
|
|
133
140
|
* });
|
|
134
141
|
* const clamped = limiter.clamp(someDate);
|
|
135
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @returns A new {@link LimitDateTimeInstance}.
|
|
136
145
|
*/
|
|
137
146
|
export declare function limitDateTimeInstance(config: LimitDateTimeConfig): LimitDateTimeInstance;
|
|
@@ -121,6 +121,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
121
121
|
set step(step: Minutes);
|
|
122
122
|
/**
|
|
123
123
|
* Returns the LimitDateTimeInstance. This does not take the schedule into consideration.
|
|
124
|
+
*
|
|
125
|
+
* @returns The underlying {@link LimitDateTimeInstance}.
|
|
124
126
|
*/
|
|
125
127
|
get limitInstance(): LimitDateTimeInstance;
|
|
126
128
|
/**
|
|
@@ -140,6 +142,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
140
142
|
* // true if June 15 is a weekday and overlaps the limit range
|
|
141
143
|
* instance.dateDayContainsValidDateValue(new Date('2024-06-15'));
|
|
142
144
|
* ```
|
|
145
|
+
*
|
|
146
|
+
* @returns `true` if the day contains at least one valid date/time value.
|
|
143
147
|
*/
|
|
144
148
|
dateDayContainsValidDateValue(date: Date): boolean;
|
|
145
149
|
/**
|
|
@@ -157,6 +161,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
157
161
|
*
|
|
158
162
|
* instance.isInValidRange(new Date('2024-06-15T10:00:00')); // true if a weekday
|
|
159
163
|
* ```
|
|
164
|
+
*
|
|
165
|
+
* @returns `true` if the date is within the min/max limits and on a scheduled day.
|
|
160
166
|
*/
|
|
161
167
|
isInValidRange(date?: Date): boolean;
|
|
162
168
|
/**
|
|
@@ -174,6 +180,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
174
180
|
*
|
|
175
181
|
* instance.isValid(new Date('2099-03-15T10:00:00')); // true if all constraints pass
|
|
176
182
|
* ```
|
|
183
|
+
*
|
|
184
|
+
* @returns `true` if the date passes all configured constraints.
|
|
177
185
|
*/
|
|
178
186
|
isValid(date?: Date): boolean;
|
|
179
187
|
/**
|
|
@@ -192,6 +200,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
192
200
|
* // status.isAfterMinimum === false (before min)
|
|
193
201
|
* // status.inFuture === false (if date is in the past)
|
|
194
202
|
* ```
|
|
203
|
+
*
|
|
204
|
+
* @returns A {@link DateTimeMinuteDateStatus} snapshot for the given date.
|
|
195
205
|
*/
|
|
196
206
|
getStatus(date?: Date): DateTimeMinuteDateStatus;
|
|
197
207
|
/**
|
|
@@ -208,6 +218,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
208
218
|
*
|
|
209
219
|
* instance.dateIsInSchedule(new Date('2024-06-15')); // true (Saturday = false)
|
|
210
220
|
* ```
|
|
221
|
+
*
|
|
222
|
+
* @returns `true` if the date is on a scheduled day or no schedule is configured.
|
|
211
223
|
*/
|
|
212
224
|
dateIsInSchedule(date?: Date): boolean;
|
|
213
225
|
/**
|
|
@@ -227,6 +239,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
227
239
|
* instance.round({ roundToSteps: true }); // 2024-06-15T09:00:00
|
|
228
240
|
* instance.round({ roundToSteps: true, roundToBound: true }); // clamped to min if below
|
|
229
241
|
* ```
|
|
242
|
+
*
|
|
243
|
+
* @returns The rounded (and optionally clamped) date.
|
|
230
244
|
*/
|
|
231
245
|
round(round: RoundDateTimeMinute): Date;
|
|
232
246
|
/**
|
|
@@ -245,6 +259,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
245
259
|
*
|
|
246
260
|
* instance.clamp(new Date('2024-05-25')); // clamped to min, then nearest weekday
|
|
247
261
|
* ```
|
|
262
|
+
*
|
|
263
|
+
* @returns The date clamped to both the limits and the schedule.
|
|
248
264
|
*/
|
|
249
265
|
clamp(date?: Date, maxClampDistance?: Days): Date;
|
|
250
266
|
/**
|
|
@@ -260,6 +276,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
260
276
|
*
|
|
261
277
|
* instance.clampToLimit(new Date('2025-03-01')); // returns max (2024-12-31)
|
|
262
278
|
* ```
|
|
279
|
+
*
|
|
280
|
+
* @returns The date clamped to the configured min/max limits.
|
|
263
281
|
*/
|
|
264
282
|
clampToLimit(date?: Date): Date;
|
|
265
283
|
/**
|
|
@@ -279,6 +297,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
279
297
|
* // If June 15, 2024 is a Saturday, returns the next Monday
|
|
280
298
|
* instance.clampToSchedule(new Date('2024-06-15'));
|
|
281
299
|
* ```
|
|
300
|
+
*
|
|
301
|
+
* @returns The nearest valid scheduled date, or the input date if already valid or no schedule is configured.
|
|
282
302
|
*/
|
|
283
303
|
clampToSchedule(date?: Date, maxClampDistance?: Days): Date;
|
|
284
304
|
/**
|
|
@@ -299,6 +319,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
299
319
|
* // Find the next weekday after a Saturday
|
|
300
320
|
* instance.findNextAvailableDayInSchedule(new Date('2024-06-15'), 'future');
|
|
301
321
|
* ```
|
|
322
|
+
*
|
|
323
|
+
* @returns The next valid schedule date, or `undefined` if none found within the max distance.
|
|
302
324
|
*/
|
|
303
325
|
findNextAvailableDayInSchedule(date: DateCellScheduleDateFilterInput, direction: DateRelativeDirection, maxDistance?: Days): Maybe<Date>;
|
|
304
326
|
/**
|
|
@@ -316,6 +338,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
316
338
|
* instance.isInSchedule(new Date('2024-06-17')); // true (Monday)
|
|
317
339
|
* instance.isInSchedule(new Date('2024-06-16')); // false (Sunday)
|
|
318
340
|
* ```
|
|
341
|
+
*
|
|
342
|
+
* @returns `true` if the date is on a scheduled day or no schedule is configured.
|
|
319
343
|
*/
|
|
320
344
|
isInSchedule(date: DateCellScheduleDateFilterInput): boolean;
|
|
321
345
|
protected _takeBoundedDate(date?: Date): Date;
|
|
@@ -338,6 +362,8 @@ export declare class DateTimeMinuteInstance {
|
|
|
338
362
|
*
|
|
339
363
|
* isValid(new Date('2024-06-17T10:00:00')); // true if future weekday after min
|
|
340
364
|
* ```
|
|
365
|
+
*
|
|
366
|
+
* @returns A decision function that returns `true` for valid dates.
|
|
341
367
|
*/
|
|
342
368
|
export declare function dateTimeMinuteDecisionFunction(config: DateTimeMinuteConfig): DecisionFunction<Date>;
|
|
343
369
|
/**
|
|
@@ -366,5 +392,7 @@ export declare function dateTimeMinuteDecisionFunction(config: DateTimeMinuteCon
|
|
|
366
392
|
* // true only if both 00:00 and 23:59 on June 15 pass all constraints
|
|
367
393
|
* isFullDayValid(new Date('2024-06-15'));
|
|
368
394
|
* ```
|
|
395
|
+
*
|
|
396
|
+
* @returns A decision function that returns `true` for valid days.
|
|
369
397
|
*/
|
|
370
398
|
export declare function dateTimeMinuteWholeDayDecisionFunction(config: DateTimeMinuteConfig, startAndEndOfDayMustBeValid?: boolean): DecisionFunction<Date>;
|