Is there a good date/time API available for Scala? [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this questionI'm looking for something akin to JodaTime or JSR 310 for Scala that leverages nice Scala features such as operator overloading and doesn't rely on implicit conversions (I have an irrational fear of implicit conversions).
I'm aware of http://github.com/jorgeortiz85/scala-time, but it just pimps JodaTime with implicits.
There's nothing wrong with implicit conversions. Even if a Java library wasn't used for the underlying logic, any sensibly designed pure Scala library would still use implicits, allowing you to write expressions such as 5.days + 3.minutes
.
Not all implicits are created equal either, an implicit converting to a very specific type that you have full control over is almost certainly safe .
As others have already stated, such conversions will be optimised away in most cases, especially with escape analysis turned on, so don't let them worry you!
Until JSR 310 is finalised, joda-time is the best you're going to get.
Other than the need to follow Java naming conventions and a lack of operator overloading, joda-time is already a very good fit for idiomatic Scala. The design is very functional in nature, especially the way it embraces immutablity, so scalaj-time is actually only a very thin wrapper around the library.
You also get the benefit that scalaj-time can be easily upgraded to use JSR 310 when it's available, so it'll be much less painful to migrate your code at that time.
Since 2.8, scala-time has been renamed scalaj-time: http://github.com/scalaj/scalaj-time
精彩评论