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

Experiment with TC39 Temporal proposal #365

Closed
armanbilge opened this issue Mar 5, 2022 · 1 comment
Closed

Experiment with TC39 Temporal proposal #365

armanbilge opened this issue Mar 5, 2022 · 1 comment

Comments

@armanbilge
Copy link

This is a proposal for a JS-native date/time API:

We should investigate implementing the java.time.* APIs in terms of Temporal. If successful, it may improve performance and more importantly help solve #69 by reducing the size of the generated JS code.

Although the Temporal APIs are not yet available it is in the process of implementation in browsers and the API is not expected to change.

There are currently polyfills which we can target for initial experiments. In http4s/http4s-dom#30 (comment) I estimated the size of scala-java-time to be roughly 100kb; meanwhile, this polyfill boasts a size of 15 kb. So that's something to think about :)

@armanbilge
Copy link
Author

Hmm, this might not be possible at all 😕 I ran into problems really quickly.

Compare:

scala> java.time.Instant.ofEpochSecond(31556889864403199L)
val res0: java.time.Instant = +1000000000-12-31T23:59:59Z

With:

> Temporal.Instant.fromEpochSeconds(BigInt('31556889864403199'))
Uncaught TypeError: Cannot convert BigInt to number

> Temporal.Instant.fromEpochMicroseconds(BigInt('31556889864403199') * BigInt(1000000))
Uncaught RangeError: Instant outside of supported range

So I think scala-java-time must continue to serve as the de facto compliant implementation of java.time.* on Scala.js.

Meanwhile, Temporal could be used to implement a non-compliant java.time.* similar to scalajs-jsjoda. But that seems outside the scope of this project.

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

1 participant