Yup, this is a bug. It's fixed now in the subversion repository.

It is rather unfortunate that java.util.TimeZone silently converts all 
time zones it doesn't understand to GMT instead of throwing an 
exception. That is what happened in this case. If the TimeZone class 
threw a nice IllegalArgumentException, this bug would be more apparent.

Gerald Loeffler wrote:
> hi all,
>
> i think there is a bug in DateTimeZone.toTimeZone(): it does not
> return the correct java.util.TimeZone when the DateTimeZone was
> created from an offset (rather than an ID). (As a direct consequence
> of this, the java.util.GregorianCalendar returned by
> AbstractDateTime.toGregorianCalendar() is also incorrect, because it
> is based on the wrong java.util.TimeZone.)
>
> please have a look at the following test case. in my opinion, all
> assertions should succeed, but the last one fails because the offset
> of the java.util.TimeZone returned by DateTimeZone.toTimeZone() is in
> fact 0.
>
> ------------------------------------------------
> // a dateTime in winter
> final long t = new DateTime("2006-01-12T12:12:00").getMillis();
>
> DateTimeZone dtz;
>
> dtz = DateTimeZone.forID("UTC");
> assertEquals(dtz.getOffset(t), 0); // OK
> assertEquals(dtz.toTimeZone().getOffset(t), 0); // OK
>
> dtz = DateTimeZone.forID("America/Los_Angeles");
> assertEquals(dtz.getOffset(t), -8 * 60 * 60 * 1000); // OK
> assertEquals(dtz.toTimeZone().getOffset(t), -8 * 60 * 60 * 1000); // OK
>
> dtz = DateTimeZone.forOffsetHours(-8);
> assertEquals(dtz.getOffset(t), -8 * 60 * 60 * 1000); // OK
> assertEquals(dtz.toTimeZone().getOffset(t), -8 * 60 * 60 * 1000); // FAILS
> ------------------------------------------------
>
> Is this a misunderstanding on my part or a genuine bug?
>
> (this is for joda-time 1.4)
>
>   cheers,
>   gerald
>
>   

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to