@dereekb/date 9.24.46 → 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 +13 -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 +3 -1
  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,667 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expandDateCellScheduleRangeToDateCellRanges = exports.expandDateCellScheduleRange = exports.expandDateCellSchedule = exports.expandDateCellScheduleFactory = exports.dateCellScheduleDateCellTimingFilter = exports.dateCellScheduleDateFilter = exports.copyDateCellScheduleDateFilterConfig = exports.fullDateCellScheduleRange = exports.DEFAULT_FULL_DATE_SCHEDULE_RANGE_DURATION = exports.isSameFullDateCellScheduleDateRange = exports.isFullDateCellScheduleDateRange = exports.isSameDateCellScheduleEventRange = exports.dateCellScheduleDateRange = exports.isSameDateCellScheduleDateRange = exports.isDateCellScheduleStartOfDayDateRange = exports.isDateCellScheduleDateRange = exports.DateCellSchedule = exports.isSameDateCellSchedule = exports.isDateCellSchedule = exports.dateCellScheduleDayCodesAreSetsEquivalent = exports.dateCellScheduleDayCodeFactory = exports.rawDateCellScheduleDayCodes = exports.expandDateCellScheduleDayCodesToDayCodesSet = exports.expandDateCellScheduleDayCodes = exports.dateCellScheduleDayCodesSetFromDaysOfWeek = exports.expandDateCellScheduleDayCodesToDayOfWeekSet = exports.simplifyDateCellScheduleDayCodes = exports.dateCellScheduleEncodedWeek = exports.isEmptyDateCellScheduleEncodedWeek = exports.isDateCellScheduleEncodedWeek = exports.DATE_CELL_SCHEDULE_ENCODED_WEEK_REGEX = exports.dateCellScheduleDayCodesFromEnabledDays = exports.enabledDaysFromDateCellScheduleDayCodes = exports.weekendDateCellScheduleDayCodes = exports.weekdayDateCellScheduleDayCodes = exports.fullWeekDateCellScheduleDayCodes = exports.DateCellScheduleDayCode = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const util_1 = require("@dereekb/util");
6
+ const class_transformer_1 = require("class-transformer");
7
+ const class_validator_1 = require("class-validator");
8
+ const date_fns_1 = require("date-fns");
9
+ const date_1 = require("./date");
10
+ const date_cell_1 = require("./date.cell");
11
+ const date_cell_factory_1 = require("./date.cell.factory");
12
+ const date_cell_filter_1 = require("./date.cell.filter");
13
+ const date_cell_index_1 = require("./date.cell.index");
14
+ const date_cell_week_1 = require("./date.cell.week");
15
+ const date_range_1 = require("./date.range");
16
+ const date_timezone_1 = require("./date.timezone");
17
+ const date_week_1 = require("./date.week");
18
+ var DateCellScheduleDayCode;
19
+ (function (DateCellScheduleDayCode) {
20
+ /**
21
+ * Special no-op/unused code
22
+ */
23
+ DateCellScheduleDayCode[DateCellScheduleDayCode["NONE"] = 0] = "NONE";
24
+ DateCellScheduleDayCode[DateCellScheduleDayCode["SUNDAY"] = 1] = "SUNDAY";
25
+ DateCellScheduleDayCode[DateCellScheduleDayCode["MONDAY"] = 2] = "MONDAY";
26
+ DateCellScheduleDayCode[DateCellScheduleDayCode["TUESDAY"] = 3] = "TUESDAY";
27
+ DateCellScheduleDayCode[DateCellScheduleDayCode["WEDNESDAY"] = 4] = "WEDNESDAY";
28
+ DateCellScheduleDayCode[DateCellScheduleDayCode["THURSDAY"] = 5] = "THURSDAY";
29
+ DateCellScheduleDayCode[DateCellScheduleDayCode["FRIDAY"] = 6] = "FRIDAY";
30
+ DateCellScheduleDayCode[DateCellScheduleDayCode["SATURDAY"] = 7] = "SATURDAY";
31
+ /**
32
+ * All weekdays (Mon-Fri)
33
+ */
34
+ DateCellScheduleDayCode[DateCellScheduleDayCode["WEEKDAY"] = 8] = "WEEKDAY";
35
+ /**
36
+ * All weekend days (Sat/Sun)
37
+ */
38
+ DateCellScheduleDayCode[DateCellScheduleDayCode["WEEKEND"] = 9] = "WEEKEND";
39
+ })(DateCellScheduleDayCode = exports.DateCellScheduleDayCode || (exports.DateCellScheduleDayCode = {}));
40
+ function fullWeekDateCellScheduleDayCodes() {
41
+ return [DateCellScheduleDayCode.WEEKDAY, DateCellScheduleDayCode.WEEKEND];
42
+ }
43
+ exports.fullWeekDateCellScheduleDayCodes = fullWeekDateCellScheduleDayCodes;
44
+ function weekdayDateCellScheduleDayCodes() {
45
+ return [DateCellScheduleDayCode.MONDAY, DateCellScheduleDayCode.TUESDAY, DateCellScheduleDayCode.WEDNESDAY, DateCellScheduleDayCode.THURSDAY, DateCellScheduleDayCode.FRIDAY];
46
+ }
47
+ exports.weekdayDateCellScheduleDayCodes = weekdayDateCellScheduleDayCodes;
48
+ function weekendDateCellScheduleDayCodes() {
49
+ return [DateCellScheduleDayCode.SATURDAY, DateCellScheduleDayCode.SUNDAY];
50
+ }
51
+ exports.weekendDateCellScheduleDayCodes = weekendDateCellScheduleDayCodes;
52
+ /**
53
+ * Creates an EnabledDays from the input.
54
+ *
55
+ * @param input
56
+ * @returns
57
+ */
58
+ function enabledDaysFromDateCellScheduleDayCodes(input) {
59
+ const days = expandDateCellScheduleDayCodesToDayOfWeekSet(Array.from(new Set(input)));
60
+ return (0, util_1.enabledDaysFromDaysOfWeek)(days);
61
+ }
62
+ exports.enabledDaysFromDateCellScheduleDayCodes = enabledDaysFromDateCellScheduleDayCodes;
63
+ /**
64
+ * Creates an array of simplified DateCellScheduleDayCode[] values from the input.
65
+ *
66
+ * @param input
67
+ * @returns
68
+ */
69
+ function dateCellScheduleDayCodesFromEnabledDays(input) {
70
+ const days = (0, util_1.daysOfWeekFromEnabledDays)(input);
71
+ const scheduleDayCodes = days.map((x) => x + 1);
72
+ return simplifyDateCellScheduleDayCodes(scheduleDayCodes);
73
+ }
74
+ exports.dateCellScheduleDayCodesFromEnabledDays = dateCellScheduleDayCodesFromEnabledDays;
75
+ exports.DATE_CELL_SCHEDULE_ENCODED_WEEK_REGEX = /^[0-9]{0,9}$/;
76
+ /**
77
+ * Returns true if the input is a DateCellScheduleEncodedWeek.
78
+ *
79
+ * @param input
80
+ * @returns
81
+ */
82
+ function isDateCellScheduleEncodedWeek(input) {
83
+ return exports.DATE_CELL_SCHEDULE_ENCODED_WEEK_REGEX.test(input);
84
+ }
85
+ exports.isDateCellScheduleEncodedWeek = isDateCellScheduleEncodedWeek;
86
+ /**
87
+ * Returns true if the input string represents an empty DateCellScheduleEncodedWeek.
88
+ *
89
+ * @param input
90
+ * @returns
91
+ */
92
+ function isEmptyDateCellScheduleEncodedWeek(input) {
93
+ return input === '' || input === '0';
94
+ }
95
+ exports.isEmptyDateCellScheduleEncodedWeek = isEmptyDateCellScheduleEncodedWeek;
96
+ /**
97
+ * Creates a DateCellScheduleEncodedWeek from an array of DateCellScheduleDayCode values.
98
+ *
99
+ * The returned encoded week is simplified.
100
+ *
101
+ * @param codes
102
+ */
103
+ function dateCellScheduleEncodedWeek(codes) {
104
+ const result = simplifyDateCellScheduleDayCodes(codes);
105
+ return result.join('');
106
+ }
107
+ exports.dateCellScheduleEncodedWeek = dateCellScheduleEncodedWeek;
108
+ /**
109
+ * Reduces/merges any day codes into more simplified day codes.
110
+ *
111
+ * For instance, if all days of the week are selected, they will be reduced to "8".
112
+ *
113
+ * @param codes
114
+ * @returns
115
+ */
116
+ function simplifyDateCellScheduleDayCodes(codes) {
117
+ const codesSet = new Set(codes);
118
+ const result = [];
119
+ if (codesSet.size >= 2) {
120
+ let weekDays;
121
+ let hasAllWeekDays = codesSet.has(DateCellScheduleDayCode.WEEKDAY);
122
+ if (!hasAllWeekDays) {
123
+ weekDays = (0, util_1.range)(DateCellScheduleDayCode.MONDAY, DateCellScheduleDayCode.SATURDAY).filter((code) => codesSet.has(code));
124
+ hasAllWeekDays = weekDays.length === 5;
125
+ }
126
+ const hasSaturday = codesSet.has(DateCellScheduleDayCode.SATURDAY);
127
+ const hasSunday = codesSet.has(DateCellScheduleDayCode.SUNDAY);
128
+ const hasAllWeekendDays = codesSet.has(DateCellScheduleDayCode.WEEKEND) || (hasSaturday && hasSunday);
129
+ if (!hasAllWeekendDays && hasSunday) {
130
+ result.push(DateCellScheduleDayCode.SUNDAY);
131
+ }
132
+ if (!hasAllWeekDays) {
133
+ (0, util_1.mergeArrayIntoArray)(result, weekDays);
134
+ }
135
+ if (!hasAllWeekendDays && hasSaturday) {
136
+ result.push(DateCellScheduleDayCode.SATURDAY);
137
+ }
138
+ if (hasAllWeekDays) {
139
+ result.push(DateCellScheduleDayCode.WEEKDAY);
140
+ }
141
+ if (hasAllWeekendDays) {
142
+ result.push(DateCellScheduleDayCode.WEEKEND);
143
+ }
144
+ }
145
+ else {
146
+ const only = (0, util_1.firstValueFromIterable)(codesSet);
147
+ if (only) {
148
+ result.push(only);
149
+ }
150
+ }
151
+ return result;
152
+ }
153
+ exports.simplifyDateCellScheduleDayCodes = simplifyDateCellScheduleDayCodes;
154
+ /**
155
+ * Expands the input DateCellScheduleDayCodesInput to a Set of DayOfWeek values.
156
+ *
157
+ * @param input
158
+ * @returns
159
+ */
160
+ function expandDateCellScheduleDayCodesToDayOfWeekSet(input) {
161
+ const days = new Set();
162
+ const dayCodesSet = expandDateCellScheduleDayCodesToDayCodesSet(input);
163
+ (0, util_1.forEachInIterable)(dayCodesSet, (code) => {
164
+ days.add((code - 1));
165
+ });
166
+ return days;
167
+ }
168
+ exports.expandDateCellScheduleDayCodesToDayOfWeekSet = expandDateCellScheduleDayCodesToDayOfWeekSet;
169
+ function dateCellScheduleDayCodesSetFromDaysOfWeek(input) {
170
+ const codes = new Set();
171
+ (0, util_1.forEachInIterable)(input, (code) => {
172
+ codes.add((code + 1));
173
+ });
174
+ return codes;
175
+ }
176
+ exports.dateCellScheduleDayCodesSetFromDaysOfWeek = dateCellScheduleDayCodesSetFromDaysOfWeek;
177
+ /**
178
+ * Expands the input into an array of DateCellScheduleDayCode values.
179
+ *
180
+ * @param input
181
+ * @returns
182
+ */
183
+ function expandDateCellScheduleDayCodes(input) {
184
+ return Array.from(expandDateCellScheduleDayCodesToDayCodesSet(input));
185
+ }
186
+ exports.expandDateCellScheduleDayCodes = expandDateCellScheduleDayCodes;
187
+ /**
188
+ * Expands the input DateCellScheduleDayCodesInput to a Set of DayOfWeek values.
189
+ *
190
+ * @param input
191
+ * @returns
192
+ */
193
+ function expandDateCellScheduleDayCodesToDayCodesSet(input) {
194
+ const codes = rawDateCellScheduleDayCodes(input);
195
+ const days = new Set();
196
+ codes.forEach((code) => {
197
+ switch (code) {
198
+ case 0:
199
+ // do nothing
200
+ break;
201
+ case 8:
202
+ (0, util_1.addToSet)(days, weekdayDateCellScheduleDayCodes()); // monday-friday
203
+ break;
204
+ case 9:
205
+ (0, util_1.addToSet)(days, weekendDateCellScheduleDayCodes());
206
+ break;
207
+ default: // remove offset
208
+ days.add(code);
209
+ break;
210
+ }
211
+ });
212
+ return days;
213
+ }
214
+ exports.expandDateCellScheduleDayCodesToDayCodesSet = expandDateCellScheduleDayCodesToDayCodesSet;
215
+ /**
216
+ * Converts the input DateCellScheduleDayCodesInput to an array of DateCellScheduleDayCode values, but does not expand
217
+ *
218
+ * @param input
219
+ * @returns
220
+ */
221
+ function rawDateCellScheduleDayCodes(input) {
222
+ let dayCodes;
223
+ switch (typeof input) {
224
+ case 'string':
225
+ dayCodes = Array.from(new Set(input)).map((x) => Number(x));
226
+ break;
227
+ case 'number':
228
+ dayCodes = [input];
229
+ break;
230
+ default:
231
+ dayCodes = Array.from(input);
232
+ break;
233
+ }
234
+ return dayCodes.filter((x) => Boolean(x)); // filter out "none" code
235
+ }
236
+ exports.rawDateCellScheduleDayCodes = rawDateCellScheduleDayCodes;
237
+ /**
238
+ * Creates a DateCellScheduleDayCodeFactory using the optional input config.
239
+ *
240
+ * @param config
241
+ * @returns
242
+ */
243
+ function dateCellScheduleDayCodeFactory(config) {
244
+ const normal = (0, date_week_1.yearWeekCodeDateTimezoneInstance)(config === null || config === void 0 ? void 0 : config.timezone);
245
+ return (date) => {
246
+ const target = normal.systemDateToTargetDate(date);
247
+ const day = (0, date_fns_1.getDay)(target);
248
+ return day + 1;
249
+ };
250
+ }
251
+ exports.dateCellScheduleDayCodeFactory = dateCellScheduleDayCodeFactory;
252
+ /**
253
+ * Returns true if the input codes, when expanded, are equivalent.
254
+ *
255
+ * @param a
256
+ * @param b
257
+ * @returns
258
+ */
259
+ function dateCellScheduleDayCodesAreSetsEquivalent(a, b) {
260
+ const ae = expandDateCellScheduleDayCodes(a);
261
+ const be = expandDateCellScheduleDayCodes(b);
262
+ return (0, util_1.iterablesAreSetEquivalent)(ae, be);
263
+ }
264
+ exports.dateCellScheduleDayCodesAreSetsEquivalent = dateCellScheduleDayCodesAreSetsEquivalent;
265
+ /**
266
+ * Returns true if the input is a DateCellSchedule.
267
+ *
268
+ * @param input
269
+ * @returns
270
+ */
271
+ function isDateCellSchedule(input) {
272
+ if (typeof input === 'object') {
273
+ const asRange = input;
274
+ return (typeof asRange.w === 'string' && !asRange.ex) || (Array.isArray(asRange.ex) && !asRange.d) || Array.isArray(asRange.d);
275
+ }
276
+ return false;
277
+ }
278
+ exports.isDateCellSchedule = isDateCellSchedule;
279
+ function isSameDateCellSchedule(a, b) {
280
+ if (a && b) {
281
+ return a.w === b.w && (0, util_1.iterablesAreSetEquivalent)(a.ex, b.ex) && (0, util_1.iterablesAreSetEquivalent)(a.d, b.d);
282
+ }
283
+ else {
284
+ return a == b;
285
+ }
286
+ }
287
+ exports.isSameDateCellSchedule = isSameDateCellSchedule;
288
+ class DateCellSchedule {
289
+ constructor(template) {
290
+ if (template) {
291
+ this.w = template.w;
292
+ this.d = template.d;
293
+ this.ex = template.ex;
294
+ }
295
+ }
296
+ }
297
+ tslib_1.__decorate([
298
+ (0, class_transformer_1.Expose)(),
299
+ (0, class_validator_1.IsString)(),
300
+ (0, class_validator_1.Matches)(exports.DATE_CELL_SCHEDULE_ENCODED_WEEK_REGEX),
301
+ tslib_1.__metadata("design:type", String)
302
+ ], DateCellSchedule.prototype, "w", void 0);
303
+ tslib_1.__decorate([
304
+ (0, class_transformer_1.Expose)(),
305
+ (0, class_validator_1.IsOptional)(),
306
+ (0, class_validator_1.Min)(0, { each: true }),
307
+ (0, class_validator_1.IsArray)(),
308
+ tslib_1.__metadata("design:type", Array)
309
+ ], DateCellSchedule.prototype, "d", void 0);
310
+ tslib_1.__decorate([
311
+ (0, class_transformer_1.Expose)(),
312
+ (0, class_validator_1.IsOptional)(),
313
+ (0, class_validator_1.Min)(0, { each: true }),
314
+ (0, class_validator_1.IsArray)(),
315
+ tslib_1.__metadata("design:type", Array)
316
+ ], DateCellSchedule.prototype, "ex", void 0);
317
+ exports.DateCellSchedule = DateCellSchedule;
318
+ /**
319
+ * Returns true if the input is possibly a FullDateCellScheduleRange.
320
+ *
321
+ * Does not check that the input is a valid FullDateCellScheduleRange.
322
+ *
323
+ * @param input
324
+ * @returns
325
+ */
326
+ function isDateCellScheduleDateRange(input) {
327
+ if (typeof input === 'object') {
328
+ const asRange = input;
329
+ return isDateCellSchedule(asRange) && (0, date_1.isDate)(asRange.end) && (0, date_1.isDate)(asRange.start);
330
+ }
331
+ return false;
332
+ }
333
+ exports.isDateCellScheduleDateRange = isDateCellScheduleDateRange;
334
+ /**
335
+ * Returns true if the input is a DateCellScheduleDateRange without a duration or startsAt.
336
+ *
337
+ * @param input
338
+ * @returns
339
+ */
340
+ function isDateCellScheduleStartOfDayDateRange(input) {
341
+ if (isDateCellScheduleDateRange(input) && input.duration == null && input.startsAt == null) {
342
+ const { start, end, timezone } = input;
343
+ const normalInstance = (0, date_timezone_1.dateTimezoneUtcNormal)(timezone);
344
+ return normalInstance.isStartOfDayInTargetTimezone(start) && normalInstance.isStartOfDayInTargetTimezone(end);
345
+ }
346
+ return false;
347
+ }
348
+ exports.isDateCellScheduleStartOfDayDateRange = isDateCellScheduleStartOfDayDateRange;
349
+ /**
350
+ * Returns true if both inputs have the same schedule and date range.
351
+ *
352
+ * @param a
353
+ * @param b
354
+ * @returns
355
+ */
356
+ function isSameDateCellScheduleDateRange(a, b) {
357
+ if (a && b) {
358
+ return (0, date_range_1.isSameDateRange)(a, b) && isSameDateCellSchedule(a, b);
359
+ }
360
+ else {
361
+ return a == b;
362
+ }
363
+ }
364
+ exports.isSameDateCellScheduleDateRange = isSameDateCellScheduleDateRange;
365
+ /**
366
+ * Creates a DateCellScheduleDateRange from the input.
367
+ *
368
+ * @param input
369
+ * @returns
370
+ */
371
+ function dateCellScheduleDateRange(input) {
372
+ const { w, ex, d, start: inputStart, startsAt: inputStartsAt, end: inputEnd, timezone: inputTimezone } = input;
373
+ const timezone = inputTimezone !== null && inputTimezone !== void 0 ? inputTimezone : (0, date_1.requireCurrentTimezone)(); // treat input as the current timezone
374
+ const normalInstance = (0, date_timezone_1.dateTimezoneUtcNormal)(timezone);
375
+ let start;
376
+ let end;
377
+ // either start or startsAt is provided
378
+ if (inputStart != null) {
379
+ const startInSystemTimezone = normalInstance.systemDateToTargetDate(inputStart); // start needs to be in the system timezone normal before processing.
380
+ start = normalInstance.startOfDayInTargetTimezone(startInSystemTimezone); // ensure the start of the day is set/matches the timezone.
381
+ }
382
+ else {
383
+ if (inputStartsAt != null) {
384
+ start = normalInstance.startOfDayInTargetTimezone(inputStartsAt);
385
+ }
386
+ else if (inputEnd != null) {
387
+ start = normalInstance.startOfDayInTargetTimezone(inputEnd); // start on the same day as the end date
388
+ }
389
+ else {
390
+ throw new Error('Could not determine the proper start value for the dateCellScheduleDateRange().');
391
+ }
392
+ }
393
+ // set the end value
394
+ end = inputEnd !== null && inputEnd !== void 0 ? inputEnd : (0, date_fns_1.addMinutes)(start, 1); // default the end to one minute after the start
395
+ return {
396
+ w,
397
+ ex,
398
+ d,
399
+ start,
400
+ end,
401
+ timezone
402
+ };
403
+ }
404
+ exports.dateCellScheduleDateRange = dateCellScheduleDateRange;
405
+ /**
406
+ * Returns true if both inputs have the same FullDateCellScheduleRange.
407
+ *
408
+ * @param a
409
+ * @param b
410
+ * @returns
411
+ */
412
+ function isSameDateCellScheduleEventRange(a, b) {
413
+ if (a && b) {
414
+ return isSameDateCellScheduleDateRange(a, b) && isSameDateCellScheduleEventRange(a, b);
415
+ }
416
+ else {
417
+ return a == b;
418
+ }
419
+ }
420
+ exports.isSameDateCellScheduleEventRange = isSameDateCellScheduleEventRange;
421
+ /**
422
+ * Returns true if the input is possibly a FullDateCellScheduleRange.
423
+ *
424
+ * Does not check that the input is a valid FullDateCellScheduleRange.
425
+ *
426
+ * @param input
427
+ * @returns
428
+ */
429
+ function isFullDateCellScheduleDateRange(input) {
430
+ if (typeof input === 'object') {
431
+ const asRange = input;
432
+ return isDateCellSchedule(asRange) && (0, date_cell_1.isFullDateCellTiming)(asRange);
433
+ }
434
+ return false;
435
+ }
436
+ exports.isFullDateCellScheduleDateRange = isFullDateCellScheduleDateRange;
437
+ /**
438
+ * Returns true if both inputs have the same FullDateCellScheduleRange.
439
+ *
440
+ * @param a
441
+ * @param b
442
+ * @returns
443
+ */
444
+ function isSameFullDateCellScheduleDateRange(a, b) {
445
+ if (a && b) {
446
+ return isSameDateCellScheduleDateRange(a, b) && (0, date_cell_1.isSameFullDateCellTiming)(a, b);
447
+ }
448
+ else {
449
+ return a == b;
450
+ }
451
+ }
452
+ exports.isSameFullDateCellScheduleDateRange = isSameFullDateCellScheduleDateRange;
453
+ /**
454
+ * If a duration is not set, this is the default used.
455
+ */
456
+ exports.DEFAULT_FULL_DATE_SCHEDULE_RANGE_DURATION = 1;
457
+ /**
458
+ * Creates a FullDateCellScheduleRange from the input.
459
+ */
460
+ function fullDateCellScheduleRange(input) {
461
+ const { dateCellScheduleRange, duration: inputDefaultDuration, startsAtTime: inputDefaultStartsAtTime, updateWithDefaults } = input;
462
+ let initialFullDateRange;
463
+ const inputStartsAt = dateCellScheduleRange.startsAt;
464
+ const inputDuration = dateCellScheduleRange.duration;
465
+ const needsDurationAdjustment = inputStartsAt == null || (updateWithDefaults && inputDefaultDuration != null);
466
+ const needsStartsAtAdjustment = inputDuration == null || (updateWithDefaults && inputDefaultStartsAtTime != null);
467
+ if (isFullDateCellScheduleDateRange(dateCellScheduleRange)) {
468
+ initialFullDateRange = dateCellScheduleRange; // no need to create a FullDateCellScheduleRange
469
+ }
470
+ else {
471
+ // fill in the blanks for the date range
472
+ const initialDateRange = dateCellScheduleDateRange(dateCellScheduleRange);
473
+ initialDateRange.startsAt = inputStartsAt !== null && inputStartsAt !== void 0 ? inputStartsAt : initialDateRange.start;
474
+ initialDateRange.duration = inputDuration !== null && inputDuration !== void 0 ? inputDuration : exports.DEFAULT_FULL_DATE_SCHEDULE_RANGE_DURATION; // copy duration and startsAt
475
+ initialFullDateRange = initialDateRange;
476
+ if (isDateCellScheduleStartOfDayDateRange(dateCellScheduleRange)) {
477
+ initialFullDateRange.end = (0, date_fns_1.addMinutes)(initialFullDateRange.end, initialDateRange.duration);
478
+ }
479
+ }
480
+ let fullDateCellTiming = initialFullDateRange;
481
+ // Apply adjustments as needed
482
+ if (needsDurationAdjustment || needsStartsAtAdjustment) {
483
+ fullDateCellTiming = (0, date_cell_factory_1.updateDateCellTimingWithDateCellTimingEvent)({
484
+ timing: initialFullDateRange,
485
+ event: {
486
+ startsAt: inputDefaultStartsAtTime !== null && inputDefaultStartsAtTime !== void 0 ? inputDefaultStartsAtTime : initialFullDateRange.startsAt,
487
+ duration: inputDefaultDuration !== null && inputDefaultDuration !== void 0 ? inputDefaultDuration : initialFullDateRange.duration
488
+ },
489
+ // flag to replace the necessary items
490
+ replaceStartsAt: needsStartsAtAdjustment,
491
+ replaceDuration: needsDurationAdjustment
492
+ });
493
+ }
494
+ const result = {
495
+ timezone: fullDateCellTiming.timezone,
496
+ start: fullDateCellTiming.start,
497
+ startsAt: fullDateCellTiming.startsAt,
498
+ end: fullDateCellTiming.end,
499
+ duration: fullDateCellTiming.duration,
500
+ w: initialFullDateRange.w,
501
+ ex: initialFullDateRange.ex,
502
+ d: initialFullDateRange.d
503
+ };
504
+ return result;
505
+ }
506
+ exports.fullDateCellScheduleRange = fullDateCellScheduleRange;
507
+ function copyDateCellScheduleDateFilterConfig(inputFilter) {
508
+ return {
509
+ start: inputFilter.start,
510
+ startsAt: inputFilter.startsAt,
511
+ end: inputFilter.end,
512
+ timezone: inputFilter.timezone,
513
+ w: inputFilter.w,
514
+ d: inputFilter.d,
515
+ ex: inputFilter.ex,
516
+ // filter extras
517
+ minMaxDateRange: inputFilter.minMaxDateRange,
518
+ setStartAsMinDate: inputFilter.setStartAsMinDate
519
+ };
520
+ }
521
+ exports.copyDateCellScheduleDateFilterConfig = copyDateCellScheduleDateFilterConfig;
522
+ /**
523
+ * Creates a DateCellScheduleDateFilter.
524
+ *
525
+ * @param config
526
+ * @returns
527
+ */
528
+ function dateCellScheduleDateFilter(config) {
529
+ const { w, start: inputStart, startsAt: inputStartsAt, end: inputEnd, timezone: inputTimezone, setStartAsMinDate = true, minMaxDateRange } = config;
530
+ const timezone = inputTimezone !== null && inputTimezone !== void 0 ? inputTimezone : (0, date_1.requireCurrentTimezone)(); // if the timezone is not provided, assume the startsAt is a system timezone normal.
531
+ const normalInstance = (0, date_timezone_1.dateTimezoneUtcNormal)(timezone);
532
+ // derive the startsAt time for the range. If not provided, defaults to inputStart, or midnight in the target timezone.
533
+ const startsAt = inputStartsAt != null ? inputStartsAt : inputStart !== null && inputStart !== void 0 ? inputStart : normalInstance.startOfDayInTargetTimezone();
534
+ const startsAtInSystem = normalInstance.systemDateToTargetDate(startsAt);
535
+ const allowedDays = expandDateCellScheduleDayCodesToDayOfWeekSet(w);
536
+ // Start date is either now or the filter's start date. It is never the minMax's start date, since that is irrelevant to the filter's range.
537
+ const firstDateDay = (0, date_fns_1.getDay)(startsAtInSystem);
538
+ const dayForIndex = (0, date_cell_week_1.dateCellDayOfWeekFactory)(firstDateDay);
539
+ const dateIndexForDate = (0, date_cell_factory_1.dateCellTimingRelativeIndexFactory)({ startsAt, timezone });
540
+ let end;
541
+ if (inputEnd != null) {
542
+ // use the startsAt time instead of the end time because endsAt can fall into the next day index range
543
+ const { expectedFinalStartsAt } = (0, date_cell_1.calculateExpectedDateCellTimingDurationPair)({ startsAt, timezone, end: inputEnd });
544
+ end = expectedFinalStartsAt;
545
+ }
546
+ const indexFloor = setStartAsMinDate ? 0 : Number.MIN_SAFE_INTEGER;
547
+ const minAllowedIndex = (minMaxDateRange === null || minMaxDateRange === void 0 ? void 0 : minMaxDateRange.start) != null ? Math.max(indexFloor, dateIndexForDate(minMaxDateRange.start)) : indexFloor; // start date should be the min inde
548
+ const maxAllowedIndex = end != null ? dateIndexForDate(end) : (minMaxDateRange === null || minMaxDateRange === void 0 ? void 0 : minMaxDateRange.end) != null ? dateIndexForDate(minMaxDateRange.end) : Number.MAX_SAFE_INTEGER; // max "to" value
549
+ const includedIndexes = new Set(config.d);
550
+ const excludedIndexes = new Set(config.ex);
551
+ return (input) => {
552
+ let i;
553
+ let day;
554
+ if (typeof input === 'number') {
555
+ i = input;
556
+ }
557
+ else {
558
+ i = dateIndexForDate(input);
559
+ }
560
+ day = dayForIndex(i);
561
+ const result = (i >= minAllowedIndex && i <= maxAllowedIndex && allowedDays.has(day) && !excludedIndexes.has(i)) || includedIndexes.has(i);
562
+ return result;
563
+ };
564
+ }
565
+ exports.dateCellScheduleDateFilter = dateCellScheduleDateFilter;
566
+ /**
567
+ * Creates a DateCellScheduleDateCellTimingFilter.
568
+ *
569
+ * @param param0
570
+ * @returns
571
+ */
572
+ function dateCellScheduleDateCellTimingFilter({ timing, schedule }) {
573
+ const isAllowed = dateCellScheduleDateFilter({
574
+ w: schedule.w,
575
+ d: schedule.d,
576
+ ex: schedule.ex,
577
+ startsAt: timing.startsAt,
578
+ end: timing.end,
579
+ timezone: timing.timezone
580
+ });
581
+ return (block) => {
582
+ const i = block.i;
583
+ return isAllowed(i);
584
+ };
585
+ }
586
+ exports.dateCellScheduleDateCellTimingFilter = dateCellScheduleDateCellTimingFilter;
587
+ /**
588
+ * Creates a DateCellTimingExpansionFactory using the input DateCellScheduleDateCellTimingFilterConfig.
589
+ *
590
+ * @param config
591
+ * @returns
592
+ */
593
+ function expandDateCellScheduleFactory(config) {
594
+ const { invertSchedule = false, now, onlyBlocksThatHaveEnded, onlyBlocksThatHaveStarted, onlyBlocksNotYetEnded, onlyBlocksNotYetStarted, maxDateCellsToReturn, durationSpanFilter: inputDurationSpanFilter } = config;
595
+ let durationSpanFilter;
596
+ let durationSpanFilters = [];
597
+ if (inputDurationSpanFilter) {
598
+ durationSpanFilters.push(inputDurationSpanFilter);
599
+ }
600
+ if (onlyBlocksNotYetStarted) {
601
+ durationSpanFilters.push((0, date_cell_filter_1.dateCellDurationSpanHasNotStartedFilterFunction)(now));
602
+ }
603
+ else if (onlyBlocksThatHaveEnded) {
604
+ durationSpanFilters.push((0, date_cell_filter_1.dateCellDurationSpanHasEndedFilterFunction)(now));
605
+ }
606
+ else {
607
+ if (onlyBlocksThatHaveStarted) {
608
+ durationSpanFilters.push((0, date_cell_filter_1.dateCellDurationSpanHasStartedFilterFunction)(now));
609
+ }
610
+ if (onlyBlocksNotYetEnded) {
611
+ durationSpanFilters.push((0, date_cell_filter_1.dateCellDurationSpanHasNotEndedFilterFunction)(now));
612
+ }
613
+ }
614
+ durationSpanFilter = (0, util_1.mergeFilterFunctions)(...durationSpanFilters);
615
+ const expansionFactory = (0, date_cell_factory_1.dateCellTimingExpansionFactory)({
616
+ timing: config.timing,
617
+ filter: (0, util_1.invertFilter)(dateCellScheduleDateCellTimingFilter(config), invertSchedule),
618
+ durationSpanFilter,
619
+ maxDateCellsToReturn
620
+ });
621
+ return expansionFactory;
622
+ }
623
+ exports.expandDateCellScheduleFactory = expandDateCellScheduleFactory;
624
+ /**
625
+ * Expands the input DateCellTiming and DateCellSchedule into an array of DateCellDurationSpan value that correspond with blocks in the event.
626
+ *
627
+ * Can optionally provide an IndexRange to specify a specific range to filter on. The range will be capped to the range of the timing.
628
+ *
629
+ * @param timing
630
+ * @param schedule
631
+ * @param inputRange
632
+ * @returns
633
+ */
634
+ function expandDateCellSchedule(input) {
635
+ const { timing, limitIndexRange } = input;
636
+ const expansionFactory = expandDateCellScheduleFactory(input);
637
+ const completeRange = (0, date_cell_factory_1.dateCellIndexRange)(timing);
638
+ const range = limitIndexRange ? { minIndex: Math.max(limitIndexRange.minIndex, completeRange.minIndex), maxIndex: Math.min(limitIndexRange.maxIndex, completeRange.maxIndex) } : completeRange;
639
+ const dateCellForRange = {
640
+ i: range.minIndex,
641
+ to: range.maxIndex
642
+ }; // Index is considered to be used as inclusive already, so no need to use dateCellIndexRangeToDateCellRange
643
+ return expansionFactory([dateCellForRange]);
644
+ }
645
+ exports.expandDateCellSchedule = expandDateCellSchedule;
646
+ /**
647
+ *
648
+ * @param input
649
+ * @returns
650
+ */
651
+ function expandDateCellScheduleRange(input) {
652
+ const { dateCellScheduleRange, duration, startsAtTime } = input;
653
+ const fullDateRange = fullDateCellScheduleRange({
654
+ dateCellScheduleRange,
655
+ duration,
656
+ startsAtTime,
657
+ updateWithDefaults: true
658
+ });
659
+ return expandDateCellSchedule(Object.assign(Object.assign({}, input), { schedule: fullDateRange, timing: fullDateRange }));
660
+ }
661
+ exports.expandDateCellScheduleRange = expandDateCellScheduleRange;
662
+ function expandDateCellScheduleRangeToDateCellRanges(input) {
663
+ const dateCellDurationSpans = expandDateCellScheduleRange(input);
664
+ return (0, date_cell_index_1.groupToDateCellRanges)(dateCellDurationSpans);
665
+ }
666
+ exports.expandDateCellScheduleRangeToDateCellRanges = expandDateCellScheduleRangeToDateCellRanges;
667
+ //# sourceMappingURL=date.cell.schedule.js.map