Why this Joda offset cannot get daylightsaving right

I have the following code using Joda to calculate offset for any given day, for example

int offset = DateTimeZone.forID("EST").getOffset(new DateTime(2013,8,1,1,1));

this will give me offset of -18000000. But for:

 int offset = DateTimeZone.forID("EST").getOffset(new DateTime(2012,12,1,1,1));

this also give me offset of -18000000.

Looks like daylightsaving is not taken in to calculation. Anyone knows why? Thanks.

I am using Joda-time-2.3

Jon Skeet
people
quotationmark

You're expected to give a time zone ID - not the abbreviation for "half" a time zone. So for example, America/New_York is one example of a time zone ID for Eastern Time (there are others, for time zones which may be like New York now, but weren't historically, etc).

import org.joda.time.*;

class Test {
    public static void main(String[] args) {
        DateTimeZone zone = DateTimeZone.forID("America/New_York");
        System.out.println(zone.getOffset(new DateTime(2013,8,1,1,1)));
        System.out.println(zone.getOffset(new DateTime(2012,12,1,1,1)));
   }
}

Output:

-14400000
-18000000

You should stay away from the abbreviated forms as far as possible - they're ambiguous (non-unique) and usually only define one part of a time zone. Ick.

people

See more on this question at Stackoverflow