Code example for GregorianCalendar

Methods: add, set

0
        assertEquals(24.0, hoursSinceEpoch(calendar) - hoursSinceEpoch);
        assertCalendarEquals(calendar, 2011, 9, 16, 2, 0); // 02:00 GMT-2; +24 hours
    } 
 
    public void testAddOneDayAndOneDayOver30MinuteDstForwardAdds48Hours() { 
        Calendar calendar = new GregorianCalendar(AUSTRALIA_LORD_HOWE);
        calendar.set(2011, 9, 1, 2, 10); // 02:10 GMT+10:30
        double hoursSinceEpoch = hoursSinceEpoch(calendar);
        calendar.add(Calendar.DATE, 1);
        calendar.add(Calendar.DATE, 1);
        // The RI fails this test by returning 47.0. It adjusts for DST on both of the add() calls! 
        assertEquals(48.0, hoursSinceEpoch(calendar) - hoursSinceEpoch);
        assertCalendarEquals(calendar, 2011, 9, 3, 2, 40); // 02:40 GMT+11:00; +48.0 hours
    } 
 
    public void testAddTwoDaysOver30MinuteDstForwardAdds47AndAHalfHours() { 
        Calendar calendar = new GregorianCalendar(AUSTRALIA_LORD_HOWE);
        calendar.set(2011, 9, 1, 2, 10); // 02:10 GMT+10:30
        double hoursSinceEpoch = hoursSinceEpoch(calendar);
        calendar.add(Calendar.DATE, 2);
        assertEquals(47.5, hoursSinceEpoch(calendar) - hoursSinceEpoch);