import type { SuperJSON } from "superjson"; import { Temporal } from "ponyfill-temporal"; export const registerSuperJSONTemporal = ( superjson: Pick, ): void => { superjson.registerCustom( { isApplicable: (v): v is Temporal.ZonedDateTime => v instanceof Temporal.ZonedDateTime, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.ZonedDateTime.from(raw), }, "Temporal.ZonedDateTime", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.PlainTime => v instanceof Temporal.PlainTime, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.PlainTime.from(raw), }, "Temporal.PlainTime", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.PlainMonthDay => v instanceof Temporal.PlainMonthDay, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.PlainMonthDay.from(raw), }, "Temporal.PlainMonthDay", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.PlainYearMonth => v instanceof Temporal.PlainYearMonth, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.PlainYearMonth.from(raw), }, "Temporal.PlainYearMonth", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.PlainDate => v instanceof Temporal.PlainDate, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.PlainDate.from(raw), }, "Temporal.PlainDate", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.PlainDateTime => v instanceof Temporal.PlainDateTime, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.PlainDateTime.from(raw), }, "Temporal.PlainDateTime", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.Duration => v instanceof Temporal.Duration, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.Duration.from(raw), }, "Temporal.Duration", ); superjson.registerCustom( { isApplicable: (v): v is Temporal.Instant => v instanceof Temporal.Instant, serialize: (v) => v.toJSON(), deserialize: (raw) => Temporal.Instant.from(raw), }, "Temporal.Instant", ); };