Interpret SimpleTimeZone rules when creating DateTimeZone
Project moved to GitHub
Brought to you by:
broneill,
scolebourne
I was trying to create a DateTimeZone using the static method forTimeZone(java.util.TimeZone.
My jdk TimeZone id is not a joda recognized time zone id.
It seems that the implementation of this method ignores the daylight saving information within the jdk TimeZone and only uses the raw offset for creating the DateTimeZone. This means that this method is not always behave as expected.
I bypassed this bug by calculating the daylight saving and use the forOffsetMillis() static method instead, supplying the calculated offset.
Here is a unit test proving the existence of the bug:
public void testForTimeZoneBug() {
SimpleTimeZone tz = new SimpleTimeZone(0, "");
tz.setDSTSavings(60601000);
DateTime dstStart = new DateTime(2007, 3, 25, 1, 0, 0, 0); DateTime dstEnd = new DateTime(2007, 10, 28, 2, 0, 0, 0); tz.setStartRule(dstStart.getMonthOfYear() - 1, dstStart.getDayOfMonth(), calcTimeOfDay(dstStart)); tz.setStartYear(dstStart.getYear()); tz.setEndRule(dstEnd.getMonthOfYear() - 1, dstEnd.getDayOfMonth(), calcTimeOfDay(dstEnd)); DateTimeZone timeZone = DateTimeZone.forTimeZone(tz); assertEquals(timeZone, DateTimeZone.forOffsetHours(1)); } private static final int calcTimeOfDay(DateTime time) { DateTime startOfDay = time.toDateMidnight().toDateTime(); return (int) (time.getMillis() - startOfDay.getMillis()); }
Logged In: YES
user_id=408725
Originator: NO
The conversion from TimeZone to DateTimeZone was only ever designed to handle time zones that actually exist in the JDK, not ones that applications have created using SimpleTimeZone.
I have converted this to an enhancement request, but I have no current plans to implement it.