@outbuild-company/schedule-core 1.31.1 → 1.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -24251,6 +24251,13 @@ function computeProjectWorkHours(calendars) {
24251
24251
  var DAY_MS = 24 * 60 * 60 * 1e3;
24252
24252
  var EXCEPTION_DATE_FORMAT_REGEX = /^(\d{4})[/-](\d{1,2})[/-](\d{1,2})/;
24253
24253
  var WEEKDAYS_PER_WEEK = 7;
24254
+ var EXCEPTION_EVERY_TYPE = {
24255
+ DAILY: "DAILY",
24256
+ WEEKLY: "WEEKLY",
24257
+ MONTHLY: "MONTHLY",
24258
+ YEARLY: "YEARLY"
24259
+ };
24260
+ var MONTHS_PER_YEAR = 12;
24254
24261
  var CALENDAR_FALLBACK_WORKING_DAYS = [false, true, true, true, true, true, false];
24255
24262
  var WORKING_DAY_TRUE_VALUES = /* @__PURE__ */ new Set([
24256
24263
  "1",
@@ -24347,7 +24354,8 @@ function parseExceptionDays(exceptions, range) {
24347
24354
  const rangeKeys = expandRangeToUtcKeys(
24348
24355
  exception.from_date,
24349
24356
  exception.to_date,
24350
- range
24357
+ range,
24358
+ exception.every_type
24351
24359
  );
24352
24360
  if (rangeKeys.length === 0) continue;
24353
24361
  const value = exceptionToDateValue(exception);
@@ -24356,19 +24364,59 @@ function parseExceptionDays(exceptions, range) {
24356
24364
  }
24357
24365
  return Object.keys(map).length > 0 ? map : null;
24358
24366
  }
24359
- function expandRangeToUtcKeys(from, to, range) {
24367
+ function expandRangeToUtcKeys(from, to, range, everyType) {
24360
24368
  const fromTs = parseExceptionDate(from);
24361
24369
  const toTs = parseExceptionDate(to);
24362
24370
  if (fromTs === null || toTs === null) return [];
24363
24371
  if (range && (toTs < range.start || fromTs > range.end)) return [];
24364
- const keys = [];
24365
- let cursor = range ? Math.max(fromTs, range.start) : fromTs;
24372
+ const first = range ? Math.max(fromTs, range.start) : fromTs;
24366
24373
  const last = range ? Math.min(toTs, range.end) : toTs;
24367
- while (cursor <= last) {
24368
- keys.push(String(cursor));
24369
- cursor += DAY_MS;
24374
+ const timestamps = steppedTimestamps(fromTs, first, last, everyType);
24375
+ return timestamps.map(String);
24376
+ }
24377
+ function steppedTimestamps(anchor, first, last, everyType) {
24378
+ switch (everyType) {
24379
+ case EXCEPTION_EVERY_TYPE.DAILY:
24380
+ return everyNthDay(anchor, first, last, 1);
24381
+ case EXCEPTION_EVERY_TYPE.WEEKLY:
24382
+ return everyNthDay(anchor, first, last, WEEKDAYS_PER_WEEK);
24383
+ case EXCEPTION_EVERY_TYPE.MONTHLY:
24384
+ return monthlyOccurrences(anchor, first, last, 1);
24385
+ case EXCEPTION_EVERY_TYPE.YEARLY:
24386
+ return monthlyOccurrences(anchor, first, last, MONTHS_PER_YEAR);
24387
+ default:
24388
+ return everyNthDay(anchor, first, last, 1);
24389
+ }
24390
+ }
24391
+ function everyNthDay(anchor, first, last, stepDays) {
24392
+ const stepMs = stepDays * DAY_MS;
24393
+ const skipped = Math.max(0, Math.ceil((first - anchor) / stepMs));
24394
+ const timestamps = [];
24395
+ for (let cursor = anchor + skipped * stepMs; cursor <= last; cursor += stepMs) {
24396
+ timestamps.push(cursor);
24397
+ }
24398
+ return timestamps;
24399
+ }
24400
+ function monthlyOccurrences(anchor, first, last, stepMonths) {
24401
+ const anchorDate = new Date(anchor);
24402
+ const anchorMonthIndex = anchorDate.getUTCFullYear() * MONTHS_PER_YEAR + anchorDate.getUTCMonth();
24403
+ const firstDate = new Date(first);
24404
+ const firstMonthIndex = firstDate.getUTCFullYear() * MONTHS_PER_YEAR + firstDate.getUTCMonth();
24405
+ const anchorDay = anchorDate.getUTCDate();
24406
+ const skipped = Math.max(
24407
+ 0,
24408
+ Math.floor((firstMonthIndex - anchorMonthIndex) / stepMonths)
24409
+ );
24410
+ const timestamps = [];
24411
+ for (let step = skipped; ; step += 1) {
24412
+ const monthIndex = anchorMonthIndex + step * stepMonths;
24413
+ const year = Math.floor(monthIndex / MONTHS_PER_YEAR);
24414
+ const month = monthIndex % MONTHS_PER_YEAR;
24415
+ const timestamp = Date.UTC(year, month, anchorDay);
24416
+ if (timestamp > last) return timestamps;
24417
+ const dayExists = new Date(timestamp).getUTCMonth() === month;
24418
+ if (dayExists && timestamp >= first) timestamps.push(timestamp);
24370
24419
  }
24371
- return keys;
24372
24420
  }
24373
24421
  function parseExceptionDate(raw) {
24374
24422
  if (typeof raw !== "string") return null;