jorgeortiz85 / scala-time

A Scala wrapper for Joda Time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Ordering implicit object to DateTime DateMidnight etc

azzoti opened this issue · comments

Recent addition to Scala 2.8pre is the SeqLike.sortBy method which allows you to say

listOfPerson.sortBy(person => person.name)
listOfPerson.sortBy(person => person.shoeSize)
listOfPerson.sortBy(person => person.salary)

but not currently
listOfPerson.sortBy(person => person.dob)

The String/Int/Double sorts works because of implicit object definitions in Ordering.scala. See http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/library/scala/Ordering.scala?view=markup from "trait FloatOrdering extends Ordering[Float]".

Suggestion: Add similar implicit objects to Scala-Time in the same style os those in Ordering.scala
For example:
trait DateTimeOrdering extends Ordering[DateTime] {
def compare(x: DateTime, y: DateTime) = x.compareTo(y)
}
implicit object DateTime extends DateTime Ordering

Simple example of usage shown at end of http://quoiquilensoit.blogspot.com/2009/11/c-linq-orderby-scala-sortwith-and.html