fix(grid): keep tz-aware Now values and duckdb lockfile in sync
This commit is contained in:
4 files changed
+37
-6
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatTemporalInputValue, parseTemporalInputValue, stepTemporalInputValue, temporalCellEditorConfig, temporalCellEditorKind } from "@/lib/dataGrid/dataGridTemporalEditor";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { formatTemporalInputValue, hostTimezoneOffsetSuffix, parseTemporalInputValue, stepTemporalInputValue, temporalCellEditorConfig, temporalCellEditorKind } from "@/lib/dataGrid/dataGridTemporalEditor";
|
||||
|
||||
describe("dataGridTemporalEditor", () => {
|
||||
it("resolves temporal editor configs with fractional precision", () => {
|
||||
@@ -54,4 +54,26 @@ describe("dataGridTemporalEditor", () => {
|
||||
expect(formatTemporalInputValue("2026-07-09 12:34:56", "datetime")).toBe("2026-07-09T12:34:56");
|
||||
expect(parseTemporalInputValue("2026-07-09T12:34:56", "datetime")).toBe("2026-07-09 12:34:56");
|
||||
});
|
||||
|
||||
it("formats the host timezone offset for tz-aware Now values", () => {
|
||||
const now = new Date("2026-09-13T12:00:00Z");
|
||||
const spy = vi.spyOn(Date.prototype, "getTimezoneOffset");
|
||||
|
||||
try {
|
||||
spy.mockReturnValue(-480);
|
||||
expect(hostTimezoneOffsetSuffix(now)).toBe("+08:00");
|
||||
|
||||
spy.mockReturnValue(330);
|
||||
expect(hostTimezoneOffsetSuffix(now)).toBe("-05:30");
|
||||
|
||||
spy.mockReturnValue(0);
|
||||
expect(hostTimezoneOffsetSuffix(now)).toBe("+00:00");
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
});
|
||||
@@ -78,6 +78,13 @@ export function temporalOffsetSuffix(value: string, kind: TemporalCellEditorKind
|
||||
return basePattern.test(withoutOffset) ? offset : "";
|
||||
}
|
||||
|
||||
export function hostTimezoneOffsetSuffix(now: Date): string {
|
||||
const minutes = -now.getTimezoneOffset();
|
||||
const sign = minutes >= 0 ? "+" : "-";
|
||||
const abs = Math.abs(minutes);
|
||||
return `${sign}${String(Math.floor(abs / 60)).padStart(2, "0")}:${String(abs % 60).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
export function stepTemporalInputValue(value: string, kind: TemporalCellEditorKind, part: TemporalCellEditorPart, delta: number): string {
|
||||
const dateParts = temporalDateParts(value);
|
||||
const timeParts = temporalTimeParts(value, kind);
|
||||
|
||||
Reference in new issue
Block a user