Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda time zone calculation

Been playing around with Joda timezones and found the following which seemed odd.

I ran the following code

    DateTimeZone gmt = DateTimeZone.forID( "Etc/GMT" );
    DateTimeZone gmtPlusOne = DateTimeZone.forID( "Etc/GMT+1" );
    DateTimeZone gmtMinusOne = DateTimeZone.forID( "Etc/GMT-1" );

    System.out.println( new DateTime( gmt ).toString() );
    System.out.println( new DateTime( gmtPlusOne ).toString() );
    System.out.println( new DateTime( gmtMinusOne ).toString() );

And got the following output

2011-10-24T13:00:12.890Z
2011-10-24T12:00:12.937-01:00
2011-10-24T14:00:12.937+01:00

I was a bit suprised to see "gmtPlusOne" coming out as one hour behind with -01:00 and the reverse for "gmtMinusOne". Can someone explain why these come out like this as I would have expected the opposite.

like image 526
Mike Q Avatar asked Oct 24 '11 13:10

Mike Q


1 Answers

This documentation explains the reason for this not so intuitive behavior. It says Etc/GMT+1 has a standard offset of -1:00 and Etc/GMT-1 has a standard offset of +1:00. This reversal of offset holds for any Etc/GMT+n.

From wiki

The special area of Etc is used for some administrative zones, particularly for "Etc/UTC" which represents Coordinated Universal Time. In order to conform with the POSIX style, those zone names beginning with "Etc/GMT" have their sign reversed from what most people expect. In this style, zones west of GMT have a positive sign and those east have a negative sign in their name (e.g "Etc/GMT-14" is 14 hours ahead/east of GMT.)

like image 100
Narendra Yadala Avatar answered Sep 22 '22 23:09

Narendra Yadala