@outbuild-company/schedule-core 1.31.0 → 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
@@ -14909,11 +14909,14 @@ var PASTE_PLACEMENT = {
14909
14909
  };
14910
14910
 
14911
14911
  // src/activity-copy-paste/paste.ts
14912
+ function childIdsInCorrelativeOrder(parentId, adapter) {
14913
+ return collectChildrenSnapshots(parentId, adapter).sort(compareActivitiesInVisualOrder).map((activity) => activity.id);
14914
+ }
14912
14915
  function resolveEndDestination(adapter) {
14913
- const rootIds = adapter.getRootIds();
14916
+ const rootIds = childIdsInCorrelativeOrder(ROOT_PARENT_ID, adapter);
14914
14917
  const [soleRootId] = rootIds;
14915
14918
  if (rootIds.length === 1 && soleRootId !== void 0) {
14916
- const lastChildId = adapter.getChildren(soleRootId).at(-1);
14919
+ const lastChildId = childIdsInCorrelativeOrder(soleRootId, adapter).at(-1);
14917
14920
  return lastChildId === void 0 ? { ok: true, parentId: soleRootId } : { ok: true, parentId: soleRootId, afterSiblingId: lastChildId };
14918
14921
  }
14919
14922
  const lastRootId = rootIds.at(-1);
@@ -14932,14 +14935,14 @@ function resolvePasteDestination(destination, adapter) {
14932
14935
  return adapter.getRootIds().length === 1 ? {
14933
14936
  ok: true,
14934
14937
  parentId: sibling.id,
14935
- beforeSiblingId: adapter.getChildren(sibling.id)[0]
14938
+ beforeSiblingId: childIdsInCorrelativeOrder(sibling.id, adapter)[0]
14936
14939
  } : { ok: true, parentId: ROOT_PARENT_ID, afterSiblingId };
14937
14940
  }
14938
14941
  if (adapter.hasChildren(sibling.id)) {
14939
14942
  return {
14940
14943
  ok: true,
14941
14944
  parentId: sibling.id,
14942
- beforeSiblingId: adapter.getChildren(sibling.id)[0]
14945
+ beforeSiblingId: childIdsInCorrelativeOrder(sibling.id, adapter)[0]
14943
14946
  };
14944
14947
  }
14945
14948
  return {
@@ -24248,6 +24251,13 @@ function computeProjectWorkHours(calendars) {
24248
24251
  var DAY_MS = 24 * 60 * 60 * 1e3;
24249
24252
  var EXCEPTION_DATE_FORMAT_REGEX = /^(\d{4})[/-](\d{1,2})[/-](\d{1,2})/;
24250
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;
24251
24261
  var CALENDAR_FALLBACK_WORKING_DAYS = [false, true, true, true, true, true, false];
24252
24262
  var WORKING_DAY_TRUE_VALUES = /* @__PURE__ */ new Set([
24253
24263
  "1",
@@ -24344,7 +24354,8 @@ function parseExceptionDays(exceptions, range) {
24344
24354
  const rangeKeys = expandRangeToUtcKeys(
24345
24355
  exception.from_date,
24346
24356
  exception.to_date,
24347
- range
24357
+ range,
24358
+ exception.every_type
24348
24359
  );
24349
24360
  if (rangeKeys.length === 0) continue;
24350
24361
  const value = exceptionToDateValue(exception);
@@ -24353,19 +24364,59 @@ function parseExceptionDays(exceptions, range) {
24353
24364
  }
24354
24365
  return Object.keys(map).length > 0 ? map : null;
24355
24366
  }
24356
- function expandRangeToUtcKeys(from, to, range) {
24367
+ function expandRangeToUtcKeys(from, to, range, everyType) {
24357
24368
  const fromTs = parseExceptionDate(from);
24358
24369
  const toTs = parseExceptionDate(to);
24359
24370
  if (fromTs === null || toTs === null) return [];
24360
24371
  if (range && (toTs < range.start || fromTs > range.end)) return [];
24361
- const keys = [];
24362
- let cursor = range ? Math.max(fromTs, range.start) : fromTs;
24372
+ const first = range ? Math.max(fromTs, range.start) : fromTs;
24363
24373
  const last = range ? Math.min(toTs, range.end) : toTs;
24364
- while (cursor <= last) {
24365
- keys.push(String(cursor));
24366
- 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);
24367
24419
  }
24368
- return keys;
24369
24420
  }
24370
24421
  function parseExceptionDate(raw) {
24371
24422
  if (typeof raw !== "string") return null;