From b2c508eaa7a86e8a3dbe87279c45ad53bba955f7 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Thu, 19 Nov 2026 12:55:03 +0800 Subject: [PATCH] fix(environment): reject invalid dates in write inference (#12188) --- .../analysisView/environmentStateWriteCopies.ts | 5 ++--- .../environmentStateWriteExplain.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/domain/analysisView/environmentStateWriteCopies.ts b/src/domain/analysisView/environmentStateWriteCopies.ts index aa162e9d54..c098387a81 100644 --- a/src/domain/analysisView/environmentStateWriteCopies.ts +++ b/src/domain/analysisView/environmentStateWriteCopies.ts @@ -214,9 +214,8 @@ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/; /** The instant a string spells: an ISO date, or a time readClock reads. */ const instantOf = (value: JsonValue | undefined): number | undefined => { if (typeof value !== "string") return undefined; - return DATE_ONLY.test(value) - ? Date.parse(`${value}T00:00:00Z`) - : readClock(value)?.ms; + // Date.parse can roll invalid calendar dates into the following month. + return readClock(DATE_ONLY.test(value) ? `${value}T00:00:00Z` : value)?.ms; }; /** Body members sending a date or time that a constant named after the member lies within two days of: the application derived it, so another value would leave it stale. */ diff --git a/src/domain/analysisView/environmentStateWriteExplain.test.ts b/src/domain/analysisView/environmentStateWriteExplain.test.ts index 1603efaf23..124caa4598 100644 --- a/src/domain/analysisView/environmentStateWriteExplain.test.ts +++ b/src/domain/analysisView/environmentStateWriteExplain.test.ts @@ -1354,3 +1354,17 @@ it("trims a created clock's fraction, and its sibling clock's, when held entitie format: trimmed, }); }); + +it.each([ + ["2024-02-29", "2024-02-29T00:00:00Z", false], + ["2024-02-30", "2024-03-01T00:00:00Z", true], + ["2023-02-29", "2023-03-01T00:00:00Z", true], +])( + "only pins the date-only member %s when it denotes a real date", + (dateEnd, dateEndUtc, editable) => { + const { body } = explainCreate( + created({ id: "42", dateEnd, dateEndUtc }, { dateEnd }), + ); + expect(body.accepted.includes("dateEnd")).toBe(editable); + }, +);