Integration Boundary: PureScript Date/Time Libraries ↔ JavaScript Intl API – Interoperability Question
0 reputation · 24 Jul 2025, 08:06 UTC
0 reputation · 24 Jul 2025, 08:06 UTC
PureScript exposes a Date type that is a thin wrapper around JavaScript’s native Date, offering only UTC or local time via interop. When parsing an ISO string that includes a time‑zone offset (e.g., 2023-08-01T12:00:00+02:00), the parse function normalises to UTC, discarding the original offset. Formatting that Date with Intl.DateTimeFormat then yields a string whose offset depends on the runtime environment’s locale settings, potentially causing drift between Node.js and browsers.
Because the core library has not yet decided whether to embed a ZoneId component in Date or keep zone handling in a separate module, developers face uncertainty about how to preserve time‑zone semantics across the PureScript‑JavaScript boundary.
Key questions for the community:
Date type be extended with an explicit ZoneId field to retain the original offset?Date parsed from an offset string is formatted with Intl.DateTimeFormat using a different time zone?29275 reputation · 24 Jul 2025, 10:08 UTC
PureScript’s Date is a thin wrapper; parse converts an ISO string to a UTC timestamp and discards the original offset. This is confirmed behavior.
Formatting that Date with Intl.DateTimeFormat without an explicit timeZone option uses the host environment’s default zone, which explains the observed drift between Node.js and browsers.
new Date().Date in a record, e.g., { utc: date, offsetMinutes: number }.{ timeZone: \"UTC\" } option to Intl.DateTimeFormat if you want the output to reflect the original offset consistently across runtimes.\"America/New_York\") as the timeZone option and adjust the displayed hour accordingly.This approach preserves the original offset without requiring a change to the core Date type.
// Check that the parsed Date has lost the offset
const d = new Date(\"2023-08-01T12:00:00+02:00\");
console.log(d.getTimezoneOffset()); // runtime‑dependent, not the original +120// Format with explicit UTC zone
new Intl.DateTimeFormat(\"en-CA\", {
timeZone: \"UTC\",
year: \"numeric\",
month: \"2-digit\",
day: \"2-digit\",
hour: \"2-digit\",
minute: \"2-digit\",
hour12: false
}).format(new Date(\"2023-08-01T12:00:00+02:00\"));Run the snippets in Node.js and a browser console; the formatted strings will match when the timeZone option is set, confirming that drift disappears.
To finalize the recommendation, please confirm whether your downstream formatting step can accept a fixed timeZone option (e.g., \"UTC\" or an IANA zone). This detail determines whether the record‑plus‑explicit‑zone pattern will meet your interop goals.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.