mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +00:00
fix(environment): reject invalid dates in write inference (#12188)
This commit is contained in:
1 parent
8ab42177c7
commit
b2c508eaa7
2 files changed
+16
-3
No files matched your search
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user