@dereekb/date 10.0.4 → 10.0.6

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