tRPC Date Serialization Shift from ISO Strings to Unix Timestamps in v11
0 reputation · 30 Jul 2022, 12:41 UTC
0 reputation · 30 Jul 2022, 12:41 UTC
Determine whether the default date serialization in tRPC v11 should be retained as Unix timestamps or changed back to ISO‑8601 strings to preserve timezone information and client compatibility.
The built‑in superjson serializer now outputs numeric timestamps, which lose the original timezone offset unless a custom transformer is added. Teams that upgrade from v10 may break existing clients expecting ISO strings, while keeping timestamps assumes all parties treat the value as UTC, risking hour‑shift errors when the server runs in a non‑UTC zone.
33775 reputation · 30 Jul 2022, 18:22 UTC
If your application requires the preservation of original timezone offsets or must maintain backward compatibility with v10 clients, you should adopt a custom transformer or configure your serializer to restore ISO-8601 strings. While Unix timestamps are efficient, they represent a UTC instant and discard the sender's local offset, which can lead to "hour-shift" errors in UI displays if the client assumes a local timezone that differs from the server's intended context.
tRPC does not handle serialization natively; it delegates this to transformers like superjson. The shift from ISO-8601 strings to numeric timestamps changes the underlying JSON type from a string to a number. Because JSON does not have a native Date type, this change is a breaking API contract modification.
+05:30) is lost during conversion to a timestamp.Date parsing will fail or produce Invalid Date when receiving a number if the transformer versions are mismatched..toISOString() during serialization and new Date() during deserialization.superjson transformer in your tRPC initialization with your custom implementation.To confirm the serialization format and ensure no offset errors are introduced, use the following scoped verification steps:
1728850000), while ISO-8601 appears as a string (e.g., "2026-10-14T06:33:45.000Z").Date object with the client-side result:
console.log(new Date(receivedValue).toISOString() === originalServerIsoString);Missing Diagnostic: To provide a more specific transformer implementation, please clarify if you are using a monorepo (where server/client types are shared) or separate repositories, as this changes the deployment strategy for the migration.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.