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

ZoneRulesException without timezone #257

Open
marcadella opened this issue Feb 18, 2021 · 5 comments
Open

ZoneRulesException without timezone #257

marcadella opened this issue Feb 18, 2021 · 5 comments

Comments

@marcadella
Copy link

The following code works in scala: LocalDateTime.now().
But in Scalajs it throws: java.time.zone.ZoneRulesException: Unknown time-zone ID: Europe/Oslo.
I do not intend to use any timezone.
Scalajs version: 1.5.0
scala-java-time version: 2.1.0

@marcadella
Copy link
Author

I guess it is because, contrary to what the doc says, the default system timezone is used by default instead of UTC. If it is not what the doc mean, then it should be fixed to specify that one need to use UTC explicitly. Ex: LocalDateTime.now(ZoneId.of("UTC)) works in ScalaJs.

@cquiroz
Copy link
Owner

cquiroz commented Feb 18, 2021

I think you're right. it will try to guess the local timezone, it is better to set a default one.
PRs to the documentation are welcome

@OndrejSpanel
Copy link

I came to this issue because I started to get this exception after upgrading from udash-0.8.0 to udash-0.9.0.

Udash used https://github.com/zoepepper/scalajs-jsjoda in previous versions. I am not sure what its implementation of LocalDateTime.now was, but it did not throw any exceptions. Most likely it just calls ZoneId.systemDefault() from JS Joda.

@OndrejSpanel
Copy link

it is better to set a default one.

When I am using this in a frontend (browser), what way can I use to set the default timezone to something reasonable? I do not want users to have to tell me their timezone, there surely must by some simpler way.

@cquiroz
Copy link
Owner

cquiroz commented Apr 5, 2023

The code tries to guess the timezone but it is not always successful
https://github.com/cquiroz/scala-java-time/blob/master/core/js/src/main/scala/java/util/TimeZone.scala#L28

I'd suggest you try to verify what is being selected with that piece of code.

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