Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to check whether two dates are the same calendar day in Groovy?

Obviously I could create a Calendar object with the date and use get(DAY) on it, but knowing Groovy, I would guess there is an easier, quicker way I just don't know about?

Answer

(date1..date2).size() == 1 // true if two dates are on same calendar day
like image 786
Epaga Avatar asked Oct 20 '08 16:10

Epaga


People also ask

How do you compare two dates that are equal?

We can use compareTo() function from Date class to compare the two dates. compareTo() function returns: 0 if both dates are equal.


1 Answers

Quickly opened the Groovy In Action book and found the following sample that should help:

def today = new Date()
def yesterday = today-1
assert (yesterday..today).size() == 2
like image 56
3 revs, 2 users 72% Avatar answered Sep 29 '22 00:09

3 revs, 2 users 72%