I'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.
The LocalDateTime class is used to represent both local date and time without timezone information.
In scala we do not have any date-time library or function available, we can use java data time, calendar, Date library to deal with dates in Scala. By using these functions, we can convert our date to a string and vice versa, also we can format our date.
Java 8 introduces a new date-time API under the package java. time. Following are some of the important classes introduced in java. time package.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With