@dereekb/date 13.0.7 → 13.1.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 +6 -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
@@ -2,69 +2,110 @@ import { type Minutes, type DecisionFunction, type DateRelativeDirection, type D
2
2
  import { type StepRoundDateTimeDown } from './date.round';
3
3
  import { type DateCellScheduleDateFilterConfig, type DateCellScheduleDateFilterInput } from './date.cell.schedule';
4
4
  import { type LimitDateTimeConfig, LimitDateTimeInstance } from './date.time.limit';
5
+ /**
6
+ * Configuration for a {@link DateTimeMinuteInstance} that combines time limits, step intervals, and schedule filtering
7
+ * to control which date/time values are considered valid.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const config: DateTimeMinuteConfig = {
12
+ * date: new Date('2024-01-15T10:00:00'),
13
+ * step: 15,
14
+ * limits: { isFuture: true },
15
+ * behavior: { capToMinLimit: true, capToMaxLimit: true },
16
+ * schedule: { w: '0111110' } // weekdays only
17
+ * };
18
+ *
19
+ * const instance = new DateTimeMinuteInstance(config);
20
+ * ```
21
+ */
5
22
  export interface DateTimeMinuteConfig extends LimitDateTimeConfig {
6
23
  /**
7
- * Default date to consider.
24
+ * Default date to consider. Falls back to the current date/time if not provided.
8
25
  */
9
26
  readonly date?: Date;
10
27
  /**
11
- * Number of minutes each "step" is.
28
+ * Minute interval for stepping and rounding. Defaults to 1.
12
29
  */
13
30
  readonly step?: Minutes;
14
31
  /**
15
- * Additional behavior
32
+ * Controls clamping behavior when a date exceeds configured limits.
16
33
  */
17
34
  readonly behavior?: {
18
35
  /**
19
- * Whether or not to set the date to the min if the steps go above it.
36
+ * When true, rounds/clamps values that fall below the minimum up to the minimum instead of leaving them out of range. Defaults to true.
20
37
  */
21
38
  readonly capToMinLimit?: boolean;
22
39
  /**
23
- * Whether or not to set the date to the max if the steps go above it.
40
+ * When true, rounds/clamps values that exceed the maximum down to the maximum instead of leaving them out of range. Defaults to true.
24
41
  */
25
42
  readonly capToMaxLimit?: boolean;
26
43
  };
27
44
  /**
28
- * Schedule to filter the days to.
45
+ * Optional schedule that restricts which days are considered valid. Useful for excluding weekends or specific dates.
29
46
  */
30
47
  readonly schedule?: DateCellScheduleDateFilterConfig;
31
48
  }
32
49
  /**
33
- * Current state of the date in the instance.
50
+ * Validation status snapshot for a date evaluated against a {@link DateTimeMinuteInstance}'s constraints.
51
+ * Each field defaults to `true` when its corresponding constraint is not configured,
52
+ * so only actively violated constraints will be `false`.
34
53
  */
35
54
  export interface DateTimeMinuteDateStatus {
36
55
  /**
37
- * If the date is at the minimum value.
56
+ * Whether the date is at or after the configured minimum limit.
38
57
  */
39
58
  readonly isAfterMinimum: boolean;
40
59
  /**
41
- * If thte date is at the maximum value.
60
+ * Whether the date is at or before the configured maximum limit.
42
61
  */
43
62
  readonly isBeforeMaximum: boolean;
44
63
  /**
45
- * If the date is in the future.
64
+ * Whether the date satisfies the `isFuture` constraint.
46
65
  */
47
66
  readonly inFuture: boolean;
48
67
  /**
49
- * If the date is in the future at the minimum number of future minutes requested.
68
+ * Whether the date satisfies the `minimumMinutesIntoFuture` constraint.
50
69
  */
51
70
  readonly inFutureMinutes: boolean;
52
71
  /**
53
- * If the date is in the past.
72
+ * Whether the date satisfies the `isPast` constraint.
54
73
  */
55
74
  readonly inPast: boolean;
56
75
  /**
57
- * If the date is on a schedule day.
76
+ * Whether the date falls on a day included in the configured schedule.
58
77
  */
59
78
  readonly isInSchedule: boolean;
60
79
  }
80
+ /**
81
+ * Rounding options for {@link DateTimeMinuteInstance.round} that extend step-based rounding
82
+ * with optional clamping to configured min/max bounds.
83
+ */
61
84
  export interface RoundDateTimeMinute extends StepRoundDateTimeDown {
85
+ /**
86
+ * When true, clamps the rounded result to the configured min/max limits
87
+ * so it never falls outside the valid range.
88
+ */
62
89
  readonly roundToBound?: boolean;
63
90
  }
64
91
  /**
65
- * Instance for working with a single date/time.
92
+ * Manages a mutable date/time value with step-based rounding, min/max limit enforcement,
93
+ * and schedule-aware validation. Combines {@link LimitDateTimeInstance} constraints with
94
+ * {@link DateCellScheduleDateFilter} to determine valid date/time values.
66
95
  *
67
- * Can step the date forward/backwards, and validate.
96
+ * @example
97
+ * ```ts
98
+ * const instance = new DateTimeMinuteInstance({
99
+ * date: new Date('2024-06-15T09:07:00'),
100
+ * step: 15,
101
+ * limits: { min: new Date('2024-06-01'), max: new Date('2024-12-31') },
102
+ * schedule: { w: '0111110' }
103
+ * });
104
+ *
105
+ * const rounded = instance.round({ roundToSteps: true });
106
+ * const clamped = instance.clamp();
107
+ * const status = instance.getStatus();
108
+ * ```
68
109
  */
69
110
  export declare class DateTimeMinuteInstance {
70
111
  private _config;
@@ -83,49 +124,247 @@ export declare class DateTimeMinuteInstance {
83
124
  */
84
125
  get limitInstance(): LimitDateTimeInstance;
85
126
  /**
86
- * Returns true if the input date is on the schedule and possibly holds a valid value for the limit.
127
+ * Checks whether any moment within the given date's day could be valid, considering
128
+ * both the schedule and the configured min/max limits. Useful for calendar UIs to
129
+ * determine which days should be selectable.
130
+ *
131
+ * @param date - the date whose day to evaluate
87
132
  *
88
- * @param date
133
+ * @example
134
+ * ```ts
135
+ * const instance = new DateTimeMinuteInstance({
136
+ * limits: { min: new Date('2024-06-15T14:00:00') },
137
+ * schedule: { w: '0111110' }
138
+ * });
139
+ *
140
+ * // true if June 15 is a weekday and overlaps the limit range
141
+ * instance.dateDayContainsValidDateValue(new Date('2024-06-15'));
142
+ * ```
89
143
  */
90
144
  dateDayContainsValidDateValue(date: Date): boolean;
91
145
  /**
92
- * Returns true if the input is within the range and in the schedule.
146
+ * Checks whether the date satisfies the min/max limits and falls on a scheduled day.
147
+ * Unlike {@link isValid}, this does not check future/past constraints.
148
+ *
149
+ * @param date - date to check; defaults to the instance's current date
93
150
  *
94
- * @param date
95
- * @returns
151
+ * @example
152
+ * ```ts
153
+ * const instance = new DateTimeMinuteInstance({
154
+ * limits: { min: new Date('2024-01-01'), max: new Date('2024-12-31') },
155
+ * schedule: { w: '0111110' }
156
+ * });
157
+ *
158
+ * instance.isInValidRange(new Date('2024-06-15T10:00:00')); // true if a weekday
159
+ * ```
96
160
  */
97
161
  isInValidRange(date?: Date): boolean;
98
162
  /**
99
- * Returns true if the status is completely valid.
163
+ * Checks whether the date passes all configured constraints: min/max limits,
164
+ * future/past requirements, minimum future minutes, and schedule.
165
+ *
166
+ * @param date - date to check; defaults to the instance's current date
100
167
  *
101
- * @param date
102
- * @returns
168
+ * @example
169
+ * ```ts
170
+ * const instance = new DateTimeMinuteInstance({
171
+ * limits: { isFuture: true, min: new Date('2024-01-01') },
172
+ * schedule: { w: '0111110' }
173
+ * });
174
+ *
175
+ * instance.isValid(new Date('2099-03-15T10:00:00')); // true if all constraints pass
176
+ * ```
103
177
  */
104
178
  isValid(date?: Date): boolean;
179
+ /**
180
+ * Evaluates the date against all configured constraints and returns a detailed status.
181
+ * Fields default to `true` when their corresponding constraint is not configured.
182
+ *
183
+ * @param date - date to evaluate; defaults to the instance's current date
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const instance = new DateTimeMinuteInstance({
188
+ * limits: { min: new Date('2024-01-01'), isFuture: true }
189
+ * });
190
+ *
191
+ * const status = instance.getStatus(new Date('2023-06-01'));
192
+ * // status.isAfterMinimum === false (before min)
193
+ * // status.inFuture === false (if date is in the past)
194
+ * ```
195
+ */
105
196
  getStatus(date?: Date): DateTimeMinuteDateStatus;
197
+ /**
198
+ * Checks whether the date falls on a day included in the configured schedule.
199
+ * Always returns `true` if no schedule is configured.
200
+ *
201
+ * @param date - date to check; defaults to the instance's current date
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * const instance = new DateTimeMinuteInstance({
206
+ * schedule: { w: '0111110' } // weekdays only
207
+ * });
208
+ *
209
+ * instance.dateIsInSchedule(new Date('2024-06-15')); // true (Saturday = false)
210
+ * ```
211
+ */
106
212
  dateIsInSchedule(date?: Date): boolean;
213
+ /**
214
+ * Rounds the instance's current date down to the configured step interval,
215
+ * optionally clamping the result to the min/max bounds.
216
+ *
217
+ * @param round - rounding and clamping options
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * const instance = new DateTimeMinuteInstance({
222
+ * date: new Date('2024-06-15T09:07:00'),
223
+ * step: 15,
224
+ * limits: { min: new Date('2024-06-15T09:00:00') }
225
+ * });
226
+ *
227
+ * instance.round({ roundToSteps: true }); // 2024-06-15T09:00:00
228
+ * instance.round({ roundToSteps: true, roundToBound: true }); // clamped to min if below
229
+ * ```
230
+ */
107
231
  round(round: RoundDateTimeMinute): Date;
232
+ /**
233
+ * Clamps the date to both the configured limits and the schedule by first applying
234
+ * {@link clampToLimit}, then {@link clampToSchedule}.
235
+ *
236
+ * @param date - date to clamp; defaults to the instance's current date
237
+ * @param maxClampDistance - maximum number of days to search for a valid schedule day
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * const instance = new DateTimeMinuteInstance({
242
+ * limits: { min: new Date('2024-06-01') },
243
+ * schedule: { w: '0111110' }
244
+ * });
245
+ *
246
+ * instance.clamp(new Date('2024-05-25')); // clamped to min, then nearest weekday
247
+ * ```
248
+ */
108
249
  clamp(date?: Date, maxClampDistance?: Days): Date;
250
+ /**
251
+ * Clamps the date to the configured min/max limits without considering the schedule.
252
+ *
253
+ * @param date - date to clamp; defaults to the instance's current date
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const instance = new DateTimeMinuteInstance({
258
+ * limits: { min: new Date('2024-06-01'), max: new Date('2024-12-31') }
259
+ * });
260
+ *
261
+ * instance.clampToLimit(new Date('2025-03-01')); // returns max (2024-12-31)
262
+ * ```
263
+ */
109
264
  clampToLimit(date?: Date): Date;
265
+ /**
266
+ * Finds the nearest valid schedule day for the given date. Searches forward first,
267
+ * then backward, within the configured limits and max distance. Returns the input
268
+ * date unchanged if no schedule is configured or the date is already on a valid day.
269
+ *
270
+ * @param date - date to clamp; defaults to the instance's current date
271
+ * @param maxClampDistance - maximum number of days to search in each direction; defaults to 370
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * const instance = new DateTimeMinuteInstance({
276
+ * schedule: { w: '0111110' } // weekdays only
277
+ * });
278
+ *
279
+ * // If June 15, 2024 is a Saturday, returns the next Monday
280
+ * instance.clampToSchedule(new Date('2024-06-15'));
281
+ * ```
282
+ */
110
283
  clampToSchedule(date?: Date, maxClampDistance?: Days): Date;
284
+ /**
285
+ * Searches for the next day in the configured schedule in the given direction,
286
+ * excluding the input date itself. Returns `undefined` if no schedule is configured
287
+ * or no matching day is found within the max distance.
288
+ *
289
+ * @param date - starting date for the search
290
+ * @param direction - whether to search forward ('future') or backward ('past')
291
+ * @param maxDistance - maximum number of days to search; defaults to 370
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * const instance = new DateTimeMinuteInstance({
296
+ * schedule: { w: '0111110' } // weekdays only
297
+ * });
298
+ *
299
+ * // Find the next weekday after a Saturday
300
+ * instance.findNextAvailableDayInSchedule(new Date('2024-06-15'), 'future');
301
+ * ```
302
+ */
111
303
  findNextAvailableDayInSchedule(date: DateCellScheduleDateFilterInput, direction: DateRelativeDirection, maxDistance?: Days): Maybe<Date>;
304
+ /**
305
+ * Checks whether the given date falls on a scheduled day. Always returns `true` if no schedule is configured.
306
+ * Accepts any {@link DateCellScheduleDateFilterInput} value (Date, number, or LogicalDate).
307
+ *
308
+ * @param date - date to check against the schedule
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * const instance = new DateTimeMinuteInstance({
313
+ * schedule: { w: '0111110' }
314
+ * });
315
+ *
316
+ * instance.isInSchedule(new Date('2024-06-17')); // true (Monday)
317
+ * instance.isInSchedule(new Date('2024-06-16')); // false (Sunday)
318
+ * ```
319
+ */
112
320
  isInSchedule(date: DateCellScheduleDateFilterInput): boolean;
113
321
  protected _takeBoundedDate(date?: Date): Date;
114
322
  protected _takeMinimumBoundedDate(date?: Date): Date;
115
323
  protected _takeMaximumBoundedDate(date?: Date): Date;
116
324
  }
117
325
  /**
118
- * Creates a DecisionFunction for the input Date value.
326
+ * Creates a {@link DecisionFunction} that evaluates whether a given date passes all
327
+ * constraints defined in the config (limits, future/past, schedule).
328
+ * Uses {@link DateTimeMinuteInstance.isValid} internally.
329
+ *
330
+ * @param config - configuration defining the valid date constraints
119
331
  *
120
- * @param config
121
- * @returns
332
+ * @example
333
+ * ```ts
334
+ * const isValid = dateTimeMinuteDecisionFunction({
335
+ * limits: { isFuture: true, min: new Date('2024-01-01') },
336
+ * schedule: { w: '0111110' }
337
+ * });
338
+ *
339
+ * isValid(new Date('2024-06-17T10:00:00')); // true if future weekday after min
340
+ * ```
122
341
  */
123
342
  export declare function dateTimeMinuteDecisionFunction(config: DateTimeMinuteConfig): DecisionFunction<Date>;
124
343
  /**
125
- * Similar to dateTimeMinuteDecisionFunction(), but compares the first and last instant of the input day to determine the decision.
344
+ * Creates a {@link DecisionFunction} that evaluates an entire day rather than a specific instant.
345
+ * Useful for calendar UIs where you need to enable/disable entire days.
346
+ *
347
+ * When `startAndEndOfDayMustBeValid` is true, both the start and end of the day must pass
348
+ * {@link DateTimeMinuteInstance.isValid}. When false (default), uses
349
+ * {@link DateTimeMinuteInstance.dateDayContainsValidDateValue} to check if any moment
350
+ * in the day could be valid.
351
+ *
352
+ * @param config - configuration defining the valid date constraints
353
+ * @param startAndEndOfDayMustBeValid - when true, requires the entire day to be valid rather than just part of it
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * const isDayValid = dateTimeMinuteWholeDayDecisionFunction({
358
+ * limits: { min: new Date('2024-06-15T14:00:00') },
359
+ * schedule: { w: '0111110' }
360
+ * });
361
+ *
362
+ * // true if any part of June 15 is valid and it's a weekday
363
+ * isDayValid(new Date('2024-06-15'));
126
364
  *
127
- * @param config
128
- * @param startAndEndOfDayMustBeValid Whether or not the start of the day and end of the day must be valid to be considered valid. Defaults to false.
129
- * @returns
365
+ * const isFullDayValid = dateTimeMinuteWholeDayDecisionFunction(config, true);
366
+ * // true only if both 00:00 and 23:59 on June 15 pass all constraints
367
+ * isFullDayValid(new Date('2024-06-15'));
368
+ * ```
130
369
  */
131
370
  export declare function dateTimeMinuteWholeDayDecisionFunction(config: DateTimeMinuteConfig, startAndEndOfDayMustBeValid?: boolean): DecisionFunction<Date>;