gantt-lib 0.7.0 → 0.7.1

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.mjs CHANGED
@@ -142,6 +142,20 @@ var formatDateLabel = (date) => {
142
142
  const month = String(parsed.getUTCMonth() + 1).padStart(2, "0");
143
143
  return `${day}.${month}`;
144
144
  };
145
+ var normalizeTaskDates = (startDate, endDate) => {
146
+ const start = parseUTCDate(startDate);
147
+ const end = parseUTCDate(endDate);
148
+ if (end.getTime() < start.getTime()) {
149
+ return {
150
+ startDate: end.toISOString().split("T")[0],
151
+ endDate: start.toISOString().split("T")[0]
152
+ };
153
+ }
154
+ return {
155
+ startDate: start.toISOString().split("T")[0],
156
+ endDate: end.toISOString().split("T")[0]
157
+ };
158
+ };
145
159
 
146
160
  // src/utils/dependencyUtils.ts
147
161
  function buildAdjacencyList(tasks) {
@@ -522,7 +536,10 @@ function flattenHierarchy(tasks) {
522
536
  return result;
523
537
  }
524
538
  function normalizeHierarchyTasks(tasks) {
525
- const orderedTasks = flattenHierarchy(tasks).map((task) => ({ ...task }));
539
+ const orderedTasks = flattenHierarchy(tasks).map((task) => {
540
+ const { startDate, endDate } = normalizeTaskDates(task.startDate, task.endDate);
541
+ return { ...task, startDate, endDate };
542
+ });
526
543
  for (const task of [...orderedTasks].reverse()) {
527
544
  if (!isTaskParent(task.id, orderedTasks)) continue;
528
545
  const { startDate, endDate } = computeParentDates(task.id, orderedTasks);
@@ -2794,7 +2811,11 @@ var TaskListRow = React9.memo(
2794
2811
  const durationMs = origEnd.getTime() - origStart.getTime();
2795
2812
  const newStart = /* @__PURE__ */ new Date(newDateISO + "T00:00:00Z");
2796
2813
  const newEnd = new Date(newStart.getTime() + durationMs);
2797
- onTaskChange?.({ ...task, startDate: newDateISO, endDate: newEnd.toISOString().split("T")[0] });
2814
+ const { startDate: normalizedStart, endDate: normalizedEnd } = normalizeTaskDates(
2815
+ newDateISO,
2816
+ newEnd.toISOString().split("T")[0]
2817
+ );
2818
+ onTaskChange?.({ ...task, startDate: normalizedStart, endDate: normalizedEnd });
2798
2819
  }, [task, onTaskChange]);
2799
2820
  const handleEndDateChange = useCallback4((newDateISO) => {
2800
2821
  if (!newDateISO) return;
@@ -2803,7 +2824,11 @@ var TaskListRow = React9.memo(
2803
2824
  const durationMs = origEnd.getTime() - origStart.getTime();
2804
2825
  const newEnd = /* @__PURE__ */ new Date(newDateISO + "T00:00:00Z");
2805
2826
  const newStart = new Date(newEnd.getTime() - durationMs);
2806
- onTaskChange?.({ ...task, startDate: newStart.toISOString().split("T")[0], endDate: newDateISO });
2827
+ const { startDate: normalizedStart, endDate: normalizedEnd } = normalizeTaskDates(
2828
+ newStart.toISOString().split("T")[0],
2829
+ newDateISO
2830
+ );
2831
+ onTaskChange?.({ ...task, startDate: normalizedStart, endDate: normalizedEnd });
2807
2832
  }, [task, onTaskChange]);
2808
2833
  const handleRowClickInternal = useCallback4(() => {
2809
2834
  onRowClick?.(task.id);
@@ -4365,6 +4390,7 @@ export {
4365
4390
  isToday,
4366
4391
  isWeekend,
4367
4392
  normalizeHierarchyTasks,
4393
+ normalizeTaskDates,
4368
4394
  parseUTCDate,
4369
4395
  pixelsToDate,
4370
4396
  recalculateIncomingLags,