Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created July 23, 2009 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislewis/152965 to your computer and use it in GitHub Desktop.
Save chrislewis/152965 to your computer and use it in GitHub Desktop.
import java.util.{Calendar, Date}
import Calendar._
class TimeIncrement(val increment: Int /* FIXME */, val amount: Int)
class IntDate(val number: Int) {
def days = new TimeIncrement(DATE, number)
}
object IntDate {
implicit def int2IntDate(i: Int) = new IntDate(i)
}
class RichDate(val date: Date) {
def > (date: Date) = this.date.after(date)
def < (date: Date) = this.date.before(date)
def + (ti: TimeIncrement) = {
val cal = Calendar.getInstance
cal.setTime(date)
cal.add(ti.increment, ti.amount)
cal.getTime
}
}
object RichDate {
implicit def date2RichDate(date: Date) = new RichDate(date)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment