diff --git a/scalding-date/src/main/scala/com/twitter/scalding/RichDate.scala b/scalding-date/src/main/scala/com/twitter/scalding/RichDate.scala index 16efc497c4..6aab75a071 100644 --- a/scalding-date/src/main/scala/com/twitter/scalding/RichDate.scala +++ b/scalding-date/src/main/scala/com/twitter/scalding/RichDate.scala @@ -96,6 +96,9 @@ case class RichDate(val timestamp: Long) extends Ordered[RichDate] { case _ => false } + def before(that: RichDate): Boolean = compare(that) < 0 + def after(that: RichDate): Boolean = compare(that) > 0 + /** * Use String.format to format the date, as opposed to toString, which uses SimpleDateFormat. */ diff --git a/scalding-date/src/test/scala/com/twitter/scalding/DateTest.scala b/scalding-date/src/test/scala/com/twitter/scalding/DateTest.scala index cc0157ede7..9177d3a003 100644 --- a/scalding-date/src/test/scala/com/twitter/scalding/DateTest.scala +++ b/scalding-date/src/test/scala/com/twitter/scalding/DateTest.scala @@ -17,6 +17,7 @@ package com.twitter.scalding import org.scalatest.WordSpec import java.util.Calendar +import java.util.TimeZone class DateTest extends WordSpec { implicit val tz = DateOps.PACIFIC @@ -97,6 +98,12 @@ class DateTest extends WordSpec { assert(rd1 >= rd1) assert(rd2 >= rd2) } + "be able to compare with before() and after() with TimeZone in context" in { + implicit val tz: TimeZone = TimeZone.getDefault + val rd1: RichDate = "2011-01-01" + val rd2: RichDate = "2012-01-01" + assert(rd1.before(rd2)) + } "implicitly convert from long" in { // This kind of implicit is not safe (what does the long mean?) implicit def longToDate(l: Long): RichDate = RichDate(l)