Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good date/time API available for Scala? [closed]

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.

like image 253
Erik Engbrecht Avatar asked May 18 '10 11:05

Erik Engbrecht


People also ask

Which APIs represents a date without time zone information?

The LocalDateTime class is used to represent both local date and time without timezone information.

How do you use dates in Scala?

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.

Which package contains date time API?

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.


1 Answers

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

like image 149
Kevin Wright Avatar answered Nov 09 '22 06:11

Kevin Wright