NotImplementedError when formatting in ScalaJS
alonsodomin opened this issue · 8 comments
When formating a date time using the java.time.
prefixed classes in ScalaJS I'm getting a NotImplementedError
at method DateTimeFormatter.formatTo
:
Can't really tell at what point inside that method the code is failing (or even if the code arrives to it) as the lack of sourcemaps in the java.time
renamed classes makes it very difficult to debug. The thing is that the same code works if using org.threeten.bp
. The application where this is used is a ScalaJS-only web frontend, deals with a lot of dates and times and everything else seems to work just fine, except formatting them.
After dropping a few printlns around inside scala-java-time
, I found the spot in which the code lands in that NotImplementedError. It´s exactly at line 1354 of the DateTimeFormatterBuilder
:
val tz: TimeZone = TimeZone.getTimeZone(zone.getId)
When landing in the getTimeZone(zone.getId)
call the error is thrown because indeed the method has not been implemented, it is basically a stub:
def getTimeZone(timeZone: String): TimeZone = ???
def getTimeZone(zoneId: ZoneId): TimeZone = ???
Thanks for tracing this. TimeZone
is only minimally implemented to get it to work but in this case obviously the lack of code is a problem
I'm a bit surprised this could work in org.threeten.bp
but not in java.time
but on the other hand the formatting tests are not fully ported as indicated in #10
I believe implementing this is fairly easy, if you want to send a PR or I'll try to fix it myself soon
I can't explain why it did work with the org.threeten.bp
package either, it seems that the only earlier exit point in that method would be in case the ZoneId
is a ZoneOffset
...
Anyway, don't mind giving a hand, it seems that all the time zone information is available in the repo so if you give some directions on how you were planning to read that from ScalaJS I could try to put together a PR for the four methods left out in java.util.TimeZone
.
EDIT: Forget that, the ZoneRulesProvider
class seems to be glue needed...
I'm in the process of porting all the format related tests trying to reproduce the error. I still haven't hit it but the full port will take a few days
Right, I started to implement a bit of SimpleTimeZone
(which in the JVM is not that simple) but did not finish yet and would need to do write to some tests for it. On top of that I'm going for a quick holiday so will pick all this up next week so this is going to take me little bit.
Did you notice that there is already a bare bones implementation at
Yes, and that was the class that I was trying to complete and most of its methods could be implemented based on a ZoneRules
instance, but not all of them. The issue is that given that is a JDK class, in order to make it cross-compile friendly it should provide with the 4 public constructors available in the JDK: http://docs.oracle.com/javase/8/docs/api/
That makes the implementation of the class more complicated, specially considering that the implementation should not be based on JDK code in order to be license-friendly. Doing so sounds to me like opening a can of worms.
Other approach would be not implement java.util.SimpleTimeZone
but having some sort of private implementation of java.util.TimeZone
using the ZoneRules
to get the offset values and using the DateFormatSymbols
that are already implemented in your other lib scala-java-locales. That would highlight the fact that this library is not trying to re-implement the legacy Java time APIs.
In essence, to get this issue solved, the only thing needed is being able to get a locale-sensitive display name for the time zone so for me the latter approach sounds more sensible...
We've been trying to do the minimal work on these very old classes to make scala-java-time
to work. Making a fully compatible class is of course welcome (And perhaps you need it) but not required. These old classes tend to have lots of constructors and methods rarely used
SimpleTimeZone
follows that logic. In the rare case somebody really needs those constructors or methods they could be added of course