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

Wrapper for use in shared JS/JVM projects? #29

Open
migo opened this issue Jan 14, 2017 · 5 comments
Open

Wrapper for use in shared JS/JVM projects? #29

migo opened this issue Jan 14, 2017 · 5 comments

Comments

@migo
Copy link

migo commented Jan 14, 2017

Wouldn't it be cool if the facade could be used in cross projects and not just in Scala.JS only projects?

We would need some kind of wrapper for this purpose. Either a wrapper for Moment.js using java.time in the JVM or a wrapper of java.time (or joda time or whatever) using Moment.js in the JS part.

There is already https://github.com/zoepepper/scalajs-jsjoda and https://github.com/cquiroz/scala-java-time for this purpose, but both have some problems at the moment. The first one is very incomplete and the second one has very limited support for Locales and time zones.
Moment.js, in contrast, seems to be quite complete.

@vpavkin
Copy link
Owner

vpavkin commented Jan 14, 2017

Hi, @migo!
This idea came to me also quite a while ago. At my job I'm writing a scala/scala-js scheduling app, and having cross-platform dates is vital.
Everything is not so simple, though. We ended up with type-class based approach to write cross-platform code in terms of some abstract T time value, and using java8 time and moment js on the specific platform.

I have an article with a more in-depth look at the problem: http://pavkin.ru/cross-platform-polymorphic-datetime-values-in-scala-with-type-classes/
And a library to try out the approach (we use something very similar at my job):
https://github.com/vpavkin/dtc

@migo
Copy link
Author

migo commented Jan 14, 2017

Ok, cool. That sounds interesting.

@migo
Copy link
Author

migo commented Jan 14, 2017

I have read your article and looked at the library. It's cool that it works like that.
However, I don't quite understand yet why type classes are really needed here. Why wasn't it possible to just implement the java.time classes using MomentLocalDateTime directly?
Then, in a cross project, you would just have to include the library for the JS part only and could use java.time classes directly without the need for polymorphic types. Moreover, it would be possible to directly instantiate DateTime classes in cross projects (which is not possible with the current approach, as I understand it).

@vpavkin
Copy link
Owner

vpavkin commented Jan 14, 2017

Why wasn't it possible to just implement the java.time classes using MomentLocalDateTime directly?

Because you can't run javascript on the JVM. All the moment-js power is useless at the backend.
And vice versa. That's the core of the problem :)

which is not possible with the current approach, as I understand it

It is possible, see for example ZoneDateTimeTC#of method.

@migo
Copy link
Author

migo commented Jan 14, 2017

Because you can't run javascript on the JVM. All the moment-js power is useless at the backend.
And vice versa. That's the core of the problem :)

I think that's not a problem in principle. If you implement java.time in the frontend using moment.js, you do not need to implement anything in the backend, because you can use java.time directly there. That's the approach taken by https://github.com/zoepepper/scalajs-jsjoda, and it works. Just that many methods of java.time are not yet implemented correctly there and timezone support is mostly missing.

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

2 participants