-
Notifications
You must be signed in to change notification settings - Fork 407
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
Support java.time
arbitraries on Scala.js & Native
#830
Conversation
When time support was added in #734, it was known that Scala.js could be supported. The issue was deferred was all. |
Absolutely! Well if you are open to it now it would be really helpful :) |
I think the CI flaked :( |
Yeah, it does that on occasion. Re-starting... |
I think it happened again 😅 |
Sadly, I have to close this :( @mpilquist pointed out to me that adding a dependency to scala-java-time here creates a circular dependency between it and scalacheck. The right thing to do is to provide these arbitraries in scala-java-time itself. |
Revisiting this, I realized that actually we don't need scala-java-time here. So there is no circular dependency! |
private final lazy val minJavaDuration: Duration = | ||
Duration.ofSeconds(Long.MinValue) | ||
|
||
private final lazy val maxJavaDuration: Duration = | ||
Duration.ofSeconds(Long.MaxValue, 999999999L) | ||
|
||
implicit final lazy val arbJavaDuration: Arbitrary[Duration] = | ||
implicit final lazy val arbJavaDuration: Arbitrary[Duration] = { | ||
val minJavaDuration = Duration.ofSeconds(Long.MinValue) | ||
val maxJavaDuration = Duration.ofSeconds(Long.MaxValue, 999999999L) | ||
Arbitrary(Gen.choose(minJavaDuration, maxJavaDuration)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Scala.js linker/optimizer was unable to elide the Duration
reference for some reason. This fixed it.
What changed? I don't follow Scala.js developments closely. |
Hmm, nothing changed? Just my own understanding. In my initial attempt I was adding an unneeded dependency. |
Ok, I was wondering if scala-java-time or similar was recently merged with Scala.js internals. If so, was curious if it required a minimum version of Scala.js for these time bindings. |
So FTR my confusion was about compile time vs linking/runtime. Since we are not testing these arbitraries, we don't need |
Ok, thanks for the clarification. |
Do you know if Scala native is similarly able to support Java time API in this way? Should we do that here, as well, while we're at it? |
Yes, I think so. My understanding has been that SJS and native have a similar model wrt compile vs link/run-time. Let me do that here, actually it should simplify this PR! In any case, it seems the |
Great, thanks for looking into it. |
java.time
arbitraries on Scala.jsjava.time
arbitraries on Scala.js & Native
Cool, that seems to have worked :) good idea! |
@rossabaker while you're here this one is good for http4s 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I barely understand scala.JS and native not at all, but it's well argued and got a green CI run.
We can also use these instances on Scala.js via scala-java-time. This would be helpful for http4s/http4s#4938.
I was surprised that most of the tests for this project (not just specific to
java.time
) are only run on the JVM, is there a particular reason for this? It would be great to run more of these on more platforms.Thanks!