@dereekb/date 9.24.47 → 9.25.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 (77) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/package.json +2 -2
  3. package/src/lib/date/date.block.d.ts +373 -16
  4. package/src/lib/date/date.block.day.d.ts +1 -0
  5. package/src/lib/date/date.block.day.js +1 -0
  6. package/src/lib/date/date.block.day.js.map +1 -1
  7. package/src/lib/date/date.block.js +236 -24
  8. package/src/lib/date/date.block.js.map +1 -1
  9. package/src/lib/date/{date.validator.d.ts → date.block.validator.d.ts} +6 -0
  10. package/src/lib/date/{date.validator.js → date.block.validator.js} +7 -1
  11. package/src/lib/date/date.block.validator.js.map +1 -0
  12. package/src/lib/date/date.block.week.d.ts +24 -0
  13. package/src/lib/date/date.block.week.js +12 -0
  14. package/src/lib/date/date.block.week.js.map +1 -1
  15. package/src/lib/date/date.cell.d.ts +357 -0
  16. package/src/lib/date/date.cell.factory.d.ts +337 -0
  17. package/src/lib/date/date.cell.factory.js +479 -0
  18. package/src/lib/date/date.cell.factory.js.map +1 -0
  19. package/src/lib/date/date.cell.filter.d.ts +18 -0
  20. package/src/lib/date/date.cell.filter.js +65 -0
  21. package/src/lib/date/date.cell.filter.js.map +1 -0
  22. package/src/lib/date/date.cell.index.d.ts +375 -0
  23. package/src/lib/date/date.cell.index.js +731 -0
  24. package/src/lib/date/date.cell.index.js.map +1 -0
  25. package/src/lib/date/date.cell.js +518 -0
  26. package/src/lib/date/date.cell.js.map +1 -0
  27. package/src/lib/date/date.cell.schedule.d.ts +409 -0
  28. package/src/lib/date/date.cell.schedule.day.d.ts +9 -0
  29. package/src/lib/date/date.cell.schedule.day.js +15 -0
  30. package/src/lib/date/date.cell.schedule.day.js.map +1 -0
  31. package/src/lib/date/date.cell.schedule.js +667 -0
  32. package/src/lib/date/date.cell.schedule.js.map +1 -0
  33. package/src/lib/date/date.cell.validator.d.ts +14 -0
  34. package/src/lib/date/date.cell.validator.js +67 -0
  35. package/src/lib/date/date.cell.validator.js.map +1 -0
  36. package/src/lib/date/date.cell.week.d.ts +31 -0
  37. package/src/lib/date/date.cell.week.js +40 -0
  38. package/src/lib/date/date.cell.week.js.map +1 -0
  39. package/src/lib/date/date.d.ts +18 -0
  40. package/src/lib/date/date.duration.d.ts +2 -1
  41. package/src/lib/date/date.duration.js +6 -1
  42. package/src/lib/date/date.duration.js.map +1 -1
  43. package/src/lib/date/date.format.js +2 -1
  44. package/src/lib/date/date.format.js.map +1 -1
  45. package/src/lib/date/date.js +29 -1
  46. package/src/lib/date/date.js.map +1 -1
  47. package/src/lib/date/date.range.d.ts +4 -2
  48. package/src/lib/date/date.range.js +6 -4
  49. package/src/lib/date/date.range.js.map +1 -1
  50. package/src/lib/date/date.range.timezone.d.ts +27 -6
  51. package/src/lib/date/date.range.timezone.js +21 -7
  52. package/src/lib/date/date.range.timezone.js.map +1 -1
  53. package/src/lib/date/date.schedule.d.ts +99 -0
  54. package/src/lib/date/date.schedule.js +63 -0
  55. package/src/lib/date/date.schedule.js.map +1 -1
  56. package/src/lib/date/date.time.js +3 -3
  57. package/src/lib/date/date.time.js.map +1 -1
  58. package/src/lib/date/date.timezone.d.ts +98 -3
  59. package/src/lib/date/date.timezone.js +191 -24
  60. package/src/lib/date/date.timezone.js.map +1 -1
  61. package/src/lib/date/date.week.js +2 -0
  62. package/src/lib/date/date.week.js.map +1 -1
  63. package/src/lib/date/index.d.ts +8 -1
  64. package/src/lib/date/index.js +8 -1
  65. package/src/lib/date/index.js.map +1 -1
  66. package/src/lib/expires/expires.js +1 -1
  67. package/src/lib/expires/expires.js.map +1 -1
  68. package/src/lib/timezone/index.d.ts +1 -0
  69. package/src/lib/timezone/index.js +1 -0
  70. package/src/lib/timezone/index.js.map +1 -1
  71. package/src/lib/timezone/timezone.d.ts +7 -0
  72. package/src/lib/timezone/timezone.js +14 -2
  73. package/src/lib/timezone/timezone.js.map +1 -1
  74. package/src/lib/timezone/timezone.validator.d.ts +6 -0
  75. package/src/lib/timezone/timezone.validator.js +26 -0
  76. package/src/lib/timezone/timezone.validator.js.map +1 -0
  77. package/src/lib/date/date.validator.js.map +0 -1
@@ -0,0 +1,375 @@
1
+ import { Maybe, SortCompareFunction, RequiredOnKeys, ArrayOrValue, UniqueModel, IndexNumber, FactoryWithRequiredInput, DateRelativeState } from '@dereekb/util';
2
+ import { DateCell, DateCellIndex, DateOrDateCellIndex } from './date.cell';
3
+ import { DateRange } from './date.range';
4
+ /**
5
+ * Represents a range of DateCell values.
6
+ */
7
+ export interface DateCellRange extends DateCell {
8
+ /**
9
+ * Index this block ends at, inclusive. A block with i=0 and to=0 encompases only the block 0.
10
+ *
11
+ * If not provided, assumes this has no range and starts/ends at the same index, i.
12
+ */
13
+ to?: DateCellIndex;
14
+ }
15
+ export declare class DateCellRange extends DateCell {
16
+ to?: DateCellIndex;
17
+ constructor(template?: DateCellRange);
18
+ }
19
+ /**
20
+ * Returns true if the input is a DateCellRange.
21
+ *
22
+ * Does not check validity. Use isValidDateCellRange()
23
+ *
24
+ * @param input
25
+ * @returns
26
+ */
27
+ export declare function isDateCellRange(input: unknown): input is DateCellRange;
28
+ /**
29
+ * A DateCellIndex, DateCell, or DateCellRange
30
+ */
31
+ export declare type DateCellOrDateCellIndexOrDateCellRange = DateCellIndex | DateCell | DateCellRange;
32
+ /**
33
+ * Returns true if the input is a valid DateCellRange.
34
+ *
35
+ * @param input
36
+ * @returns
37
+ */
38
+ export declare function isValidDateCellRange(input: DateCellRange): boolean;
39
+ /**
40
+ * Returns true if the input is a sorted DateCellRange array and there are no repeat indexes.
41
+ *
42
+ * @param input
43
+ * @returns
44
+ */
45
+ export declare function isValidDateCellRangeSeries(input: DateCellRange[]): boolean;
46
+ /**
47
+ * Returns the lowest index between all the input date block ranges. Returns 0 by default if there is no minimum or input blocks.
48
+ *
49
+ * The input range is not expected to be sorted.
50
+ */
51
+ export declare function getLeastDateCellIndexInDateCellRanges(input: (DateCell | DateCellRange)[]): DateCellIndex;
52
+ /**
53
+ * Returns the largest index between all the input date block ranges. Returns 0 by default.
54
+ *
55
+ * The input range is not expected to be sorted.
56
+ */
57
+ export declare function getGreatestDateCellIndexInDateCellRanges(input: (DateCell | DateCellRange)[]): DateCellIndex;
58
+ export interface LeastAndGreatestDateCellIndexResult<T> {
59
+ leastIndex: number;
60
+ leastIndexItem: T;
61
+ greatestIndex: number;
62
+ greatestIndexItem: T;
63
+ }
64
+ /**
65
+ * Returns the largest index between all the input date block ranges. Returns null if the input is empty.
66
+ *
67
+ * The input range is not expected to be sorted.
68
+ */
69
+ export declare function getLeastAndGreatestDateCellIndexInDateCellRanges<T extends DateCellRange>(input: T[]): Maybe<LeastAndGreatestDateCellIndexResult<T>>;
70
+ /**
71
+ * Input type used for cases where a DateRange or a DateCellRange are allowed as input but used the start/end parameters in DateRange.
72
+ */
73
+ export interface DateCellRangeOrDateRange {
74
+ start?: Maybe<DateOrDateCellIndex>;
75
+ end?: Maybe<DateOrDateCellIndex>;
76
+ }
77
+ export declare type DateOrDateCellIndexOrDateCellRange = DateOrDateCellIndex | DateCellRange;
78
+ export declare type DateOrDateRangeOrDateCellIndexOrDateCellRange = DateRange | DateOrDateCellIndexOrDateCellRange;
79
+ /**
80
+ * Creates a DateCellRange
81
+ *
82
+ * @param i
83
+ * @param to
84
+ * @returns
85
+ */
86
+ export declare function dateCellRange(i: number, to?: number): DateCellRangeWithRange;
87
+ /**
88
+ * Creates a DateCellRangeWithRange from the input DateCellIndex.
89
+ *
90
+ * @param dateCellIndex
91
+ * @returns
92
+ */
93
+ export declare function dateCellRangeWithRangeFromIndex(dateCellIndex: DateCellIndex): DateCellRangeWithRange;
94
+ /**
95
+ * Creates a DateCellRangeWithRange from the input DateCellIndex, DateCell, or DateCellRange.
96
+ *
97
+ * @param input
98
+ * @returns
99
+ */
100
+ export declare function dateCellRangeWithRange(input: DateCellOrDateCellIndexOrDateCellRange): DateCellRangeWithRange;
101
+ /**
102
+ * Function that returns true if the input range covers the full range of the configured DateCellRange.
103
+ */
104
+ export declare type DateCellRangeIncludedByRangeFunction = (range: DateCellOrDateCellIndexOrDateCellRange) => boolean;
105
+ /**
106
+ * Creates a DateCellRangeIncludedByRangeFunction
107
+ *
108
+ * @param inputRange
109
+ * @returns
110
+ */
111
+ export declare function dateCellRangeIncludedByRangeFunction(inputRange: DateCellOrDateCellIndexOrDateCellRange): DateCellRangeIncludedByRangeFunction;
112
+ /**
113
+ * Function that returns true if the input range overlaps the range of the configured DateCellRange.
114
+ */
115
+ export declare type DateCellRangeOverlapsRangeFunction = (range: DateCellOrDateCellIndexOrDateCellRange) => boolean;
116
+ /**
117
+ * Creates a DateCellRangeOverlapsRangeFunction
118
+ *
119
+ * @param inputRange
120
+ * @returns
121
+ */
122
+ export declare function dateCellRangeOverlapsRangeFunction(inputRange: DateCellOrDateCellIndexOrDateCellRange): DateCellRangeOverlapsRangeFunction;
123
+ /**
124
+ * Returns true if either of the ranges overlap eachother.
125
+ *
126
+ * @param rangeA
127
+ * @param rangeB
128
+ * @returns
129
+ */
130
+ export declare function dateCellRangeOverlapsRange(rangeA: DateCellOrDateCellIndexOrDateCellRange, rangeB: DateCellOrDateCellIndexOrDateCellRange): boolean;
131
+ /**
132
+ * Sorts the input ranges by index and distance (to values).
133
+ *
134
+ * In many cases sortAscendingIndexNumberRefFunction may be preferential since
135
+ *
136
+ * @returns
137
+ */
138
+ export declare function sortDateCellRangeAndSizeFunction<T extends DateCellRange>(): SortCompareFunction<T>;
139
+ /**
140
+ * Sorts the input date ranges. This will retain the before/after order while also sorting items by index.
141
+ *
142
+ * @param input
143
+ * @returns
144
+ */
145
+ export declare function sortDateCellRanges<T extends DateCellRange>(input: T[]): T[];
146
+ /**
147
+ * DateCellRange that is known to have a to value.
148
+ */
149
+ export declare type DateCellRangeWithRange = RequiredOnKeys<DateCellRange, 'to'>;
150
+ /**
151
+ * Groups the input values into DateCellRange values.
152
+ *
153
+ * @param input
154
+ */
155
+ export declare function groupToDateCellRanges(input: (DateCell | DateCellRange)[]): DateCellRangeWithRange[];
156
+ /**
157
+ * Returns an array containing all indexes in the date block range.
158
+ */
159
+ export declare function allIndexesInDateCellRange(input: DateCellRange): DateCellIndex[];
160
+ /**
161
+ * Returns the set of all indexes within the input.
162
+ *
163
+ * @param input
164
+ * @returns
165
+ */
166
+ export declare function allIndexesInDateCellRanges(input: (DateCellIndex | DateCellRange)[]): Set<DateCellIndex>;
167
+ /**
168
+ * Returns blocks that are only in the given DateCellRange.
169
+ *
170
+ * @param blocks
171
+ * @param range
172
+ * @returns
173
+ */
174
+ export declare function filterDateCellsInDateCellRange<T extends DateCell | DateCellRange>(blocks: T[], range: DateCellRangeWithRange): T[];
175
+ export declare type IsDateCellWithinDateCellRangeInput = DateCellOrDateCellIndexOrDateCellRange;
176
+ /**
177
+ * Function that returns true if the input range is equal or falls within the configured DateCellRange.
178
+ */
179
+ export declare type IsDateCellWithinDateCellRangeFunction = (input: IsDateCellWithinDateCellRangeInput) => boolean;
180
+ export declare function isDateCellWithinDateCellRangeFunction(inputRange: IsDateCellWithinDateCellRangeInput): IsDateCellWithinDateCellRangeFunction;
181
+ /**
182
+ * Returns true if the first DateCell or DateCellRange contains the second input.
183
+ *
184
+ * @param range
185
+ * @param isContainedWithin
186
+ * @returns
187
+ */
188
+ export declare function isDateCellWithinDateCellRange(range: IsDateCellWithinDateCellRangeInput, contains: IsDateCellWithinDateCellRangeInput): boolean;
189
+ export interface DateCellRangeBlockCountInfo {
190
+ /**
191
+ * Total number of blocks.
192
+ */
193
+ readonly count: number;
194
+ /**
195
+ * The "total" if all indexes were added together. Used for calculating the average.
196
+ */
197
+ readonly total: number;
198
+ /**
199
+ * The average block index
200
+ */
201
+ readonly average: number;
202
+ }
203
+ /**
204
+ * Counts the number of blocks in the input range.
205
+ *
206
+ * @param inputDateCellRange
207
+ * @returns
208
+ */
209
+ export declare function dateCellRangeBlocksCountInfo(inputDateCellRange: ArrayOrValue<DateCell | DateCellRange>): DateCellRangeBlockCountInfo;
210
+ /**
211
+ * Counts the number of blocks in the input range.
212
+ *
213
+ * @param inputDateCellRange
214
+ * @returns
215
+ */
216
+ export declare function dateCellRangeBlocksCount(inputDateCellRange: ArrayOrValue<DateCell | DateCellRange>): number;
217
+ /**
218
+ * Checks whether or not the input range is fully included by the configured ranges.
219
+ */
220
+ export declare type DateCellRangesFullyCoverDateCellRangeFunction = (range: DateCellRange) => boolean;
221
+ /**
222
+ * Creates a dateCellRangesFullyCoverDateCellRangeFunction
223
+ *
224
+ * @param ranges
225
+ * @returns
226
+ */
227
+ export declare function dateCellRangesFullyCoverDateCellRangeFunction(ranges: ArrayOrValue<DateCellRange>): DateCellRangesFullyCoverDateCellRangeFunction;
228
+ export interface GetNextDateCellTimingIndexInput<T extends DateCellRange> {
229
+ /**
230
+ * Relevant index for now.
231
+ */
232
+ readonly currentIndex: DateCellIndex;
233
+ /**
234
+ * All possible ranges to pick from.
235
+ */
236
+ readonly ranges: ArrayOrValue<T>;
237
+ }
238
+ export interface GetNextDateCellTimingIndexResult<T extends DateCellRange> {
239
+ /**
240
+ * The item that matches the current index first out of the options.
241
+ */
242
+ readonly currentResult: Maybe<T>;
243
+ /**
244
+ * The next picked index, if available.
245
+ */
246
+ readonly nextIndex: Maybe<DateCellIndex>;
247
+ /**
248
+ * The item that matches the next index first out of the options.
249
+ */
250
+ readonly nextResult: Maybe<T>;
251
+ /**
252
+ * All ranges that match/contain the current index.
253
+ */
254
+ readonly presentResults: T[];
255
+ /**
256
+ * All ranges that come before the current index.
257
+ */
258
+ readonly pastResults: T[];
259
+ /**
260
+ * All ranges that come after the current index.
261
+ */
262
+ readonly futureResults: T[];
263
+ }
264
+ /**
265
+ * Computes a GetNextDateCellTimingIndexResult from the input.
266
+ *
267
+ * @param input
268
+ */
269
+ export declare function getNextDateCellTimingIndex<T extends DateCellRange>(input: GetNextDateCellTimingIndexInput<T>): GetNextDateCellTimingIndexResult<T>;
270
+ /**
271
+ * Returns the DateRelativeState for the given index and range.
272
+ *
273
+ * @param nowIndex
274
+ * @param range
275
+ */
276
+ export declare function dateRelativeStateForDateCellRangeComparedToIndex(range: DateCellRange, nowIndex: DateCellIndex): DateRelativeState;
277
+ /**
278
+ * Expands a DateCellRange into an array of DateCell values.
279
+ *
280
+ * @param block
281
+ * @returns
282
+ */
283
+ export declare function expandDateCellRange<B extends DateCellRange | DateCellRangeWithRange>(block: B): B[];
284
+ /**
285
+ * A DateCell that also has the potential for a unique identifier.
286
+ */
287
+ export interface UniqueDateCell extends DateCell, UniqueModel {
288
+ }
289
+ /**
290
+ * Represents a range of UniqueDateCell values keyed by a similar identifier (or lack of identifier).
291
+ */
292
+ export interface UniqueDateCellRange extends UniqueDateCell, DateCellRange {
293
+ }
294
+ /**
295
+ * Returns true if the input DateCellRange is longer than 1 block (I.E. has a "to" value greater than it's "i" value).
296
+ *
297
+ * @param input
298
+ */
299
+ export declare function dateCellRangeHasRange(input: DateCellRange | UniqueDateCell): input is DateCellRangeWithRange;
300
+ /**
301
+ * Reads the to index if it exists, or returns the block's index itself.
302
+ *
303
+ * @param input
304
+ * @returns
305
+ */
306
+ export declare function dateCellEndIndex(input: DateCellRange | UniqueDateCell): IndexNumber;
307
+ /**
308
+ * A grouping of UniqueDateCell values, sorted by date range.
309
+ */
310
+ export interface UniqueDateCellRangeGroup<B extends DateCellRange | UniqueDateCell> extends DateCellRange {
311
+ /**
312
+ * Blocks are sorted by index.
313
+ */
314
+ blocks: B[];
315
+ }
316
+ /**
317
+ * Groups all input DateCellRange or UniqueDateCell values into a UniqueDateCellRangeGroup value amd sorts the input.
318
+ */
319
+ export declare function groupUniqueDateCells<B extends DateCellRange | UniqueDateCell>(input: B[]): UniqueDateCellRangeGroup<B>;
320
+ /**
321
+ * Determines how to "fill" a DateRange when an empty range is detected.
322
+ * - extend: extends the previous block to fill the range.
323
+ * - fill: creates a new value using a factory.
324
+ */
325
+ export declare type ExpandUniqueDateCellsFillOption = 'extend' | 'fill';
326
+ /**
327
+ * Determines how overwrite block values that are completely overlapping eachother.
328
+ * - current: keeps the "current" value
329
+ * - next: the next/new value overwrites the previous one
330
+ */
331
+ export declare type ExpandUniqueDateCellsRetainOverlapOption = 'current' | 'next';
332
+ export interface ExpandUniqueDateCellsConfig<B extends DateCellRange | UniqueDateCell> {
333
+ /**
334
+ * The expected start index.
335
+ *
336
+ * If provided, will expand the first block to start at this index, and filter out any blocks that end before this index.
337
+ */
338
+ startAtIndex?: number;
339
+ /**
340
+ * The expected end index, inclusive.
341
+ *
342
+ * If provided, will expand the final block to end at this index, and filter out any blocks that start past this index.
343
+ */
344
+ endAtIndex?: number;
345
+ /**
346
+ * Determines how to fill empty ranges.
347
+ */
348
+ fillOption: ExpandUniqueDateCellsFillOption;
349
+ /**
350
+ * (Optional) Determines how to handle overwrites.
351
+ *
352
+ * - next: will retain the latest value (next) and overwrite the current value.
353
+ * - current: will retain the current value and ignore any future values at that index.
354
+ *
355
+ * Defaults to next
356
+ */
357
+ retainOnOverlap?: ExpandUniqueDateCellsRetainOverlapOption;
358
+ /**
359
+ * Used to create new items to fill empty block sets. Required when mode is set to "fill".
360
+ */
361
+ fillFactory?: FactoryWithRequiredInput<B, DateCellRangeWithRange>;
362
+ }
363
+ export interface ExpandUniqueDateCellsResult<B extends DateCellRange | UniqueDateCell> extends UniqueDateCellRangeGroup<B> {
364
+ /**
365
+ * Blocks that were competely removed. Some blocks stay partially retained.
366
+ */
367
+ discarded: B[];
368
+ }
369
+ /**
370
+ * Expansion function used to sort/merge/replace DateCellRange values by block.
371
+ *
372
+ * Can optionally specify a second array/group of blocks that are treated as "next" blocks which can take priority or not depending on the retain options.
373
+ */
374
+ export declare type ExpandUniqueDateCellsFunction<B extends DateCellRange | UniqueDateCell> = (input: B[] | UniqueDateCellRangeGroup<B>, newBlocks?: B[] | UniqueDateCellRangeGroup<B>) => ExpandUniqueDateCellsResult<B>;
375
+ export declare function expandUniqueDateCellsFunction<B extends DateCellRange | UniqueDateCell>(config: ExpandUniqueDateCellsConfig<B>): ExpandUniqueDateCellsFunction<B>;