Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
Description
It was suggested in the Groovy-users thread to use dates (calendar.getTime) and use that for the range. I think that it would be better to stick to the Calendar objects and methods, since Date is deprecated and Calendar implements correctly Timezones and different Calendars, I think there were issues timezones and calendars in Date.
Implementation suggestion, credit Tim Yates:
http://groovyconsole.appspot.com/edit/44001
def startcal = new GregorianCalendar( 2009, Calendar.NOVEMBER, 1 ) def endcal = new GregorianCalendar( 2009, Calendar.DECEMBER, 1 ) Calendar.metaClass.next = { Calendar c = delegate.clone() c.add( Calendar.DAY_OF_MONTH, 1 ) return c } Calendar.metaClass.previous = { Calendar c = delegate.clone() c.add( Calendar.DAY_OF_MONTH, -1 ) return c } (startcal..endcal).each { println it.time }