public void testLocalTime() throws ParseException {
Date dsum = DF.parse("AD 2010-05-09 20:00:00:0 UTC");
Date dwin = DF.parse("AD 2010-01-01 20:00:00:0 UTC");
TimeZone tzRome = TimeZone.getTimeZone("Europe/Rome");
if (tzRome.getOffset(0) == 0) {
throw new RuntimeException(
"Can't get time zone for Europe/Rome!");
}
assertEquals(
"2010-05-09T22:00:00+02",
dateToISO8601DateTimeString(dsum, tzRome));
assertEquals(
"2010-01-01T21:00:00+01",
dateToISO8601DateTimeString(dwin, tzRome));
assertEquals(
"2010-05-09",
dateToISO8601DateString(dsum, tzRome));
assertEquals(
"2010-01-01",
dateToISO8601DateString(dwin, tzRome));
assertEquals(
"22:00:00+02",
dateToISO8601TimeString(dsum, tzRome));
assertEquals(
"21:00:00+01",
dateToISO8601TimeString(dwin, tzRome));
TimeZone tzNY = TimeZone.getTimeZone("America/New_York");
if (tzNY.getOffset(0) == 0) {
throw new RuntimeException(
"Can't get time zone for America/New_York!");
}
assertEquals(
"2010-05-09T16:00:00-04",
dateToISO8601DateTimeString(dsum, tzNY));
assertEquals(
"2010-01-01T15:00:00-05",
dateToISO8601DateTimeString(dwin, tzNY));
assertEquals(
"2010-05-09",
dateToISO8601DateString(dsum, tzNY));
assertEquals(
"2010-01-01",
dateToISO8601DateString(dwin, tzNY));
assertEquals(
"16:00:00-04",
dateToISO8601TimeString(dsum, tzNY));
assertEquals(
"15:00:00-05",
dateToISO8601TimeString(dwin, tzNY));
TimeZone tzFixed = TimeZone.getTimeZone("GMT+02:30");
assertEquals(
"2010-05-09T22:30:00+02:30",
dateToISO8601DateTimeString(dsum, tzFixed));
assertEquals(
"2010-01-01T22:30:00+02:30",