Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the Temporal API objects #223

Open
hornta opened this issue Mar 3, 2023 · 2 comments
Open

Support the Temporal API objects #223

hornta opened this issue Mar 3, 2023 · 2 comments

Comments

@hornta
Copy link

hornta commented Mar 3, 2023

Like PlainDate and more

https://tc39.es/proposal-temporal/docs/plaindate.html

@Skn0tt
Copy link
Member

Skn0tt commented Mar 3, 2023

Hadn't heard of that proposal yet, that looks great! Good work by the Igalia folks.

This is in Stage 3 right now, and not yet available in Browsers (I checked Chrome), so i'd like to hold off on including it in SuperJSON core right now.

If you want to support PlainDate in your project right now, you can use SuperJSON.registerCustom: https://github.com/blitz-js/superjson#decimaljs--prismadecimal

@KATT
Copy link
Contributor

KATT commented Jul 14, 2023

I do this

import { Temporal } from '@js-temporal/polyfill';
import superjson from 'superjson';

superjson.registerCustom<Temporal.PlainDate, string>(
  {
    isApplicable: (v): v is Temporal.PlainDate =>
      v instanceof Temporal.PlainDate,
    serialize: (v) => v.toJSON(),
    deserialize: (v) => Temporal.PlainDate.from(v),
  },
  'Temporal.PlainDate',
);

superjson.registerCustom<Temporal.Instant, string>(
  {
    isApplicable: (v): v is Temporal.Instant => v instanceof Temporal.Instant,
    serialize: (v) => v.toJSON(),
    deserialize: (v) => Temporal.Instant.from(v),
  },
  'Temporal.Instant',
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants