Calendar implements compareTo() that accepts only a calendar object. If you pass it a Date and exception is thrown. How restrictively lame.
DateTime's compareTo() accepts multiple types that can be evaluated to the millisecond level. So, DateTime, Date, Calendar, even long types are accepted. This approach enables this to work:
DateTime. How groovy is that!
now = [ new Date(), Calendar.getInstance(), System.currentTimeMillis, new DateTime() ]
yesterday = new DateTime() - 1
tomorrow = new DateTime() + 1
later = new DateTime(hours:23, minutes:59)
now.each {
assert yesterday.before( it )
assert tomorrow.after( it )
assert laster.after( it )
}
1 comment:
Nice! Looking forward to it!
Post a Comment