Groovy startOfDay endOfDay nextDayStart
Copy this code and paste it in your HTML
// TODO check to see if calcs are correct for spring and fall DST changes.
def startOfDay
( java.
util.
Date aDate
) { final long MS_PER_DAY
= (24 * 60 * 60 * 1000); long tzOffset
= java.
util.
TimeZone.
getDefault().
getOffset( aDate.
time ); long msSinceMidnight
= aDate.
time % MS_PER_DAY
; return new java.
util.
Date( aDate.
time - msSinceMidnight
- tzOffset
); }
def endOfDay
( java.
util.
Date aDate
) { final long MS_PER_DAY
= (24 * 60 * 60 * 1000); def long startMs
= startOfDay
( aDate
).
time; def long endMs
= startMs
+ MS_PER_DAY
- 1l
; }
def nextDayStart
( java.
util.
Date aDate
) { final long MS_PER_DAY
= (24 * 60 * 60 * 1000); return new java.
util.
Date( (startOfDay
(aDate
).
time + MS_PER_DAY
) ); }
Report this snippet
Comments
Subscribe to comments