Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add before() and after() to RichDate #1538

Merged
merged 2 commits into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down