How to define an Ordering in Scala?
object Joda {
implicit def dateTimeOrdering: Ordering[DateTime] = Ordering.fromLessThan(_ isBefore _)
}
// elsewhere
import Joda._
dateTimes.sorted
To facilitate working with Joda DateTime in Scala, nscala-time was created: https://github.com/nscala-time/nscala-time
After including it in your project with
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "1.8.0"
you can just import OrderingImplicits
. Either all at once:
import com.github.nscala_time.time.OrderingImplicits._
or a particular one:
import com.github.nscala_time.time.OrderingImplicits.DateTimeOrdering