mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 19:22:06 +00:00
fix(work-orders): use local calendar day for completedDate
Restore todayIso() after parent merge reintroduced UTC slice, and keep the wizard-date-utils regression test. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
150eb86bf1
commit
e2a11926e0
2 changed files with 29 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import {
|
||||||
useUploadWorkOrderMedia,
|
useUploadWorkOrderMedia,
|
||||||
} from "@/domain/work-orders/use-cases/use-work-order-mutations";
|
} from "@/domain/work-orders/use-cases/use-work-order-mutations";
|
||||||
import { isWorkOrderDocumentsReadOnly } from "@/domain/work-orders/utils/work-order-media-limits";
|
import { isWorkOrderDocumentsReadOnly } from "@/domain/work-orders/utils/work-order-media-limits";
|
||||||
|
import { todayIso } from "@/domain/work-orders/utils/wizard-date-utils";
|
||||||
import { useAuthContext } from "@/providers/auth-context";
|
import { useAuthContext } from "@/providers/auth-context";
|
||||||
import { useSlideOverEditState } from "./use-slide-over-edit-state";
|
import { useSlideOverEditState } from "./use-slide-over-edit-state";
|
||||||
import { useSlideOverMediaState } from "./use-slide-over-media-state";
|
import { useSlideOverMediaState } from "./use-slide-over-media-state";
|
||||||
|
|
@ -103,7 +104,7 @@ export function useWorkOrderSlideOver({
|
||||||
// Mirror CompDoc finalize: ensure completedDate then mark docStatus Yes.
|
// Mirror CompDoc finalize: ensure completedDate then mark docStatus Yes.
|
||||||
const patch: WorkOrderTablePatch = { docStatus: "Yes" };
|
const patch: WorkOrderTablePatch = { docStatus: "Yes" };
|
||||||
if (!infoSource.completedDate) {
|
if (!infoSource.completedDate) {
|
||||||
patch.completedDate = new Date().toISOString().slice(0, 10);
|
patch.completedDate = todayIso();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { describe, expect, it } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
import {
|
import {
|
||||||
fmtDateRange,
|
fmtDateRange,
|
||||||
fmtShortDate,
|
fmtShortDate,
|
||||||
|
pad2,
|
||||||
rangeDayCount,
|
rangeDayCount,
|
||||||
|
todayIso,
|
||||||
} from "@/domain/work-orders/utils/wizard-date-utils";
|
} from "@/domain/work-orders/utils/wizard-date-utils";
|
||||||
|
|
||||||
describe("fmtShortDate", () => {
|
describe("fmtShortDate", () => {
|
||||||
|
|
@ -29,3 +31,27 @@ describe("rangeDayCount", () => {
|
||||||
expect(rangeDayCount("2026-06-08", "2026-06-08")).toBe(1);
|
expect(rangeDayCount("2026-06-08", "2026-06-08")).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("todayIso", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses local calendar day, not UTC ISO date, near midnight", () => {
|
||||||
|
// 02:30 UTC is still the previous local evening in Americas (UTC−N).
|
||||||
|
vi.useFakeTimers();
|
||||||
|
vi.setSystemTime(new Date("2026-08-11T02:30:00.000Z"));
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const expectedLocal = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}`;
|
||||||
|
const utcSlice = now.toISOString().slice(0, 10);
|
||||||
|
|
||||||
|
expect(todayIso()).toBe(expectedLocal);
|
||||||
|
expect(utcSlice).toBe("2026-08-11");
|
||||||
|
|
||||||
|
if (now.getTimezoneOffset() > 0) {
|
||||||
|
expect(todayIso()).toBe("2026-08-10");
|
||||||
|
expect(todayIso()).not.toBe(utcSlice);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue