Last active
October 12, 2025 22:33
-
-
Save mfrancis107/3e400b361267912482af5ae2fd33ca34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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