Parse ISO date string¶
parseIsoDateString parses strict ISO‑8601 date strings into Date objects.
It accepts only canonical, standards‑compliant formats and rejects malformed, partial, or non‑standard representation. If the value is not a string, does not match the ISO‑8601 pattern, or produces an invalid timestamp, the rule emits no parse result.
Signature¶
Through the API:
.parse('date');
And internally:
export const parseIsoDateString: ParseRule<unknown>
(value: unknown, path: FieldPath) => ParseResult<unknown>[]
Events¶
| Event code | Description |
|---|---|
string.now.date |
Parsed string into a Date object. |
Design rationale
- Accepts only strict ISO‑8601 formats, including:
YYYY‑MM‑DD.YYYY‑MM‑DDTHH:MM.YYYY‑MM‑DDTHH:MM:SS.YYYY‑MM‑DDTHH:MM:SS.sss.- Optional timezone:
Zor±HH:MM. - Space separator allowed as an ISO‑8601 extension.
- Rejects ambiguous or non‑standard formats such as
"2020/01/01","01‑01‑2020","2020‑13‑40","2020‑01‑01T25:00", or"2020‑01‑01T10:00 PST". - Ensures the resulting Date is valid (
getTime()notNaN). - Produces a single parse step containing the parsed Date and one
parseEvent. - Never guesses, normalizes, or coerces — parsing is explicit and opt‑in.
Invoke¶
parseIsoDateString runs only when explicitly included in a boundary or pipeline. It is not affected by normalization mode and does not run automatically.
The rule activates when:
- The value is a string.
- The string matches the strict ISO‑8601 pattern.
new Date(value)yields a valid timestamp.
Examples¶
Valid ISO date strings¶
parseIsoDateString("2024-01-15", "$");
// → [
// {
// path: "$",
// nextValue: new Date("2024-01-15"),
// events: [
// JaneEvent{ kind: "info", code: "string.now.date", ... }
// ]
// }
// ]
parseIsoDateString("2024-01-15T10:30:45Z", "$");
// → [
// {
// path: "$",
// nextValue: new Date("2024-01-15T10:30:45Z"),
// events: [ JaneEvent{ code: "string.now.date", ... } ]
// }
// ]
Invalid formats — no parse¶
parseIsoDateString("2024/01/15", "$"); // → []
parseIsoDateString("15-01-2024", "$"); // → []
parseIsoDateString("2024-01-15T25:00", "$"); // → []
parseIsoDateString("2024-01-15T10:00 PST", "$"); // → []
parseIsoDateString("not-a-date", "$"); // → []
Non‑string value¶
parseIsoDateString(42, "$"); // → []