cquiroz / scala-java-time

Implementation of the `java.time` API in scala. Especially useful for scala.js
http://cquiroz.github.io/scala-java-time/
BSD 3-Clause "New" or "Revised" License
126 stars 33 forks source link

ZoneOffset.of("Z") must return UTC #520

Closed keynmol closed 1 week ago

keynmol commented 1 week ago

Closes #518

It seems that this used to work, but relied on the fact that ZoneOffset.UTC will put "Z" in ID_CACHE when object is initialised.

This no longer works because ZoneOffset.UTC was made into a lazy val, so invoking ZoneOffset.of("Z") will not trigger the ZoneOffset.UTC calculation.

To confirm, just touching ZoneOffset.UTC is enough to make repro work:

scala-cli -e 'java.time.ZoneOffset.UTC;java.time.ZoneOffset.of("Z")' --js --dep io.github.cquiroz::scala-java-time::2.6.0 # succeeds

I feel like relying on this cache behaviour is too brittle, so I decided to explictly special-case "Z" as it's a special case in java docs as well.


Note that this case is already tested, but one of the previous tests refers to ZoneOffset.UTC, triggering the cache update.