Return to Snippet

Revision: 45913
at May 11, 2011 01:23 by laurenceosx


Initial Code
// 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;
    return new java.util.Date( endMs );
}

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) );
}

Initial URL

                                

Initial Description

                                

Initial Title
Groovy startOfDay endOfDay nextDayStart

Initial Tags

                                

Initial Language
Groovy