Skip to content

Commit

Permalink
Refactor Order instance for Date
Browse files Browse the repository at this point in the history
  • Loading branch information
mlopes committed May 12, 2019
1 parent fbfa787 commit bd65e32
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/scala/wen/instances/datetime/DateInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ trait DateInstances {

implicit val dateOrderInstance: Order[Date] = new Order[Date] {
override def compare(x: Date, y: Date): Int =
if (x.year =!= y.year)
x.year compare y.year
else if (x.month =!= y.month)
x.month compare y.month
else
x.day compare y.day

(x, y) match {
case (Date(_, _, year1), Date(_, _, year2)) if year1 =!= year2 => year1 compare year2
case (Date(_, month1, _), Date(_, month2, _)) if month1 =!= month2 => month1 compare month2
case (Date(day1, _, _), Date(day2, _,_)) => day1 compare day2
}
}

implicit val dateShowInstance: Show[Date] = new Show[Date] {
Expand Down

0 comments on commit bd65e32

Please sign in to comment.