public void test_toOffsetTime_fixedOffset() { GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("GMT+12:00")); gcal.set(2008, 0, 1, 0, 0, 0); gcal.set(Calendar.MILLISECOND, 0); for (int i = 0; i < 500; i++) { OffsetTime test = gcal.toOffsetTime(); assertEquals(test.toLocalTime().toNanoOfDay(), 0); assertEquals(test.getOffset().getID(), "+12:00"); gcal.add(Calendar.DATE, 1); } }
public void test_toOffsetTime_endOfDay() { GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); gcal.set(2008, 0, 1, 23, 59, 59); gcal.set(Calendar.MILLISECOND, 0); for (int i = 0; i < 500; i++) { OffsetTime test = gcal.toOffsetTime(); assertEquals(test.toLocalTime().toNanoOfDay(), (24L * 60L * 60L - 1L) * 1000000000L); assertEquals(test.getOffset().getID(), "Z"); gcal.add(Calendar.DATE, 1); } }
public void test_toOffsetTime_variableOffset() { GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris")); gcal.set(2008, 0, 1, 0, 0, 0); gcal.set(Calendar.MILLISECOND, 0); for (int i = 0; i < 500; i++) { OffsetTime test = gcal.toOffsetTime(); assertEquals(test.toLocalTime().toNanoOfDay(), 0); boolean isDST = TimeZone.getTimeZone("Europe/Paris").inDaylightTime(gcal.getTime()); assertEquals(test.getOffset().getID(), isDST ? "+02:00" : "+01:00"); gcal.add(Calendar.DATE, 1); } }
public void test_toOffsetTime_manualOffset() { GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris")); gcal.set(2008, 0, 1, 0, 0, 0); gcal.set(Calendar.MILLISECOND, 0); gcal.set(Calendar.ZONE_OFFSET, 30 * 60 * 1000); gcal.set(Calendar.DST_OFFSET, 15 * 60 * 1000); for (int i = 0; i < 500; i++) { OffsetTime test = gcal.toOffsetTime(); assertEquals(test.toLocalTime().toNanoOfDay(), 0); assertEquals(test.getOffset().getID(), "+00:45"); gcal.add(Calendar.DATE, 1); gcal.set(Calendar.ZONE_OFFSET, 30 * 60 * 1000); gcal.set(Calendar.DST_OFFSET, 15 * 60 * 1000); } }