Skip to content

Instantly share code, notes, and snippets.

@mfrancis107
Last active October 12, 2025 22:33
Show Gist options
  • Select an option

  • Save mfrancis107/3e400b361267912482af5ae2fd33ca34 to your computer and use it in GitHub Desktop.

Select an option

Save mfrancis107/3e400b361267912482af5ae2fd33ca34 to your computer and use it in GitHub Desktop.
import "temporal-polyfill/global";
import { createSerializationAdapter } from "@tanstack/react-router";
export const temporalInstantAdapter = createSerializationAdapter({
key: "sedrino/temporal/instant",
test: (value): value is Temporal.Instant =>
value instanceof Temporal.Instant,
toSerializable: (value) => value.toString(),
fromSerializable: (value) => Temporal.Instant.from(value),
});
export const temporalZonedDateTimeAdapter = createSerializationAdapter({
key: "sedrino/temporal/zoned-datetime",
test: (value): value is Temporal.ZonedDateTime =>
value instanceof Temporal.ZonedDateTime,
toSerializable: (value) => value.toString(),
fromSerializable: (value) => Temporal.ZonedDateTime.from(value),
});
export const temporalPlainDateTimeAdapter = createSerializationAdapter({
key: "sedrino/temporal/plain-datetime",
test: (value): value is Temporal.PlainDateTime =>
value instanceof Temporal.PlainDateTime,
toSerializable: (value) => value.toString(),
fromSerializable: (value) => Temporal.PlainDateTime.from(value),
});
export const temporalPlainDateAdapter = createSerializationAdapter({
key: "sedrino/temporal/plain-date",
test: (value): value is Temporal.PlainDate =>
value instanceof Temporal.PlainDate,
toSerializable: (value) => value.toString(),
fromSerializable: (value) => Temporal.PlainDate.from(value),
});
export const temporalPlainTimeAdapter = createSerializationAdapter({
key: "sedrino/temporal/plain-time",
test: (value): value is Temporal.PlainTime =>
value instanceof Temporal.PlainTime,
toSerializable: (value) => value.toString(),
fromSerializable: (value) => Temporal.PlainTime.from(value),
});
export const temporalDurationAdapter = createSerializationAdapter({
key: "sedrino/temporal/duration",
test: (value): value is Temporal.Duration =>
value instanceof Temporal.Duration,
toSerializable: (value) => value.toString(),
fromSerializable: (value) => Temporal.Duration.from(value),
});
export const temporalAdapters = [
temporalInstantAdapter,
temporalZonedDateTimeAdapter,
temporalPlainDateTimeAdapter,
temporalPlainDateAdapter,
temporalPlainTimeAdapter,
temporalDurationAdapter,
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment