'Joda Time DateTimeZone
I was going through TimeZone page at joda website and I came across this
-05:00 EST
-05:00 EST5EDT
-05:00 Etc/GMT+5
I just wanted to know what does that EST5EDT
means, I generally use EST
so was just wanted to know about it.
I have searched about it and found nothing before posting the question.
Solution 1:[1]
EST - eastern Standard Time wihtout day light. EDT - Eastern Standard Time with Day Light Saving Time
This is the short id of TimeZone that is used.
EST5EDT means either in EST or EDT ; value of offset in hours would be the same i.e. -5 hours.
Solution 2:[2]
I ran into an issue with US/Eastern
, Americas/New_York
, and EST5EDT
. Here is what I discovered.
For dates after the Uniform Time Act of 1966 went into effect in 1967, these timezones are all identical. Also the US enforced standard DST rules during the World Wars, so they are all identical 1918-1919 and 1942-1945.
For any date before 1918, between 1920 and 1941 inclusive, and between 1946 and 1966 inclusive, EST5EDT
will always be identical to EST
. No DST is observed. Any date before 1883 Nov 18 12:03:58 will be treated as if the timezone EST existed.
Prior to 1967, Americas/New_York
will provide the time as observed in New York City. So Daylight Savings Time will follow the rules in place by the NYC municipal or NY state government. Any date before 1883 Nov 18 12:03:58 will be in local mean time with an offset of -4:56:02 from UTC.
Here is a fragment of Ruby showing the difference:
# you may need to install the tzinfo gem with
# gem install tzinfo
require 'tzinfo'
# Using EST5EDT
# In 1966 DST is not observed.
Time.new(1966, 6, 1, 0, 0, 0, TZInfo::Timezone.get("EST5EDT"))
=> 1966-06-01 00:00:00 -0500
# DST is observed in 1967.
Time.new(1967, 6, 1, 0, 0, 0, TZInfo::Timezone.get("EST5EDT"))
=> 1967-06-01 00:00:00 -0400
# Now with America/New_York
# DST is observed in 1966
Time.new(1966, 6, 1, 0, 0, 0, TZInfo::Timezone.get("America/New_York"))
=> 1966-06-01 00:00:00 -0400
# DST is also observed in 1967
Time.new(1967, 6, 1, 0, 0, 0, TZInfo::Timezone.get("America/New_York"))
=> 1967-06-01 00:00:00 -0400
# America/New_York yields local time for pre-timezone dates.
Time.new(1867, 6, 1, 0, 0, 0, TZInfo::Timezone.get("America/New_York"))
=> 1867-06-01 00:00:00 -0456
# But EST5EDT retroactively applies timezones
Time.new(1867, 6, 1, 0, 0, 0, TZInfo::Timezone.get("EST5EDT"))
=> 1867-06-01 00:00:00 -0500
Odd things can happen if you have multiple systems where one assumes EST5EDT
and the other assumes Americas/New_York
, especially when a system is storing DATE
fields as DATETIME
fields with the hours/minutes/seconds set to midnight. Data might look fine for anything recent. But a birthdate for example, from the summer of 1966 might get moved an hour, then truncated so it appears to be on the prior day.
And just for extra fun if you are dealing with old dates in Alaska, you need to remember that Alaska was Purchased from Russia. Dates before 1867 Oct 18 are on the other side of the international date line and use the Julian, not Gregorian Calendar. So Juneau, for example, went from 6 Oct 1867 (Julian) +15:02:19 to 18-Oct-1867 (Gregorian) -8:57:41. (The TZInfo library doesn't handle the Gregorian to Julian change.)
require 'tzinfo'
Time.new(1867, 10, 18, 0, 0, 0, TZInfo::Timezone.get("America/Juneau"))
=> 1867-10-18 00:00:00 +1502
Time.new(1867, 10, 19, 0, 0, 0, TZInfo::Timezone.get("America/Juneau"))
#error message
TZInfo::AmbiguousTime (1867-10-19 00:00:00 is an ambiguous local time.)
Time.new(1867, 10, 20, 0, 0, 0, TZInfo::Timezone.get("America/Juneau"))
=> 1867-10-20 00:00:00 -0857
# The Ruby DateTime datatype handles Julian,
# so convert Time to DateTime then to julian
Time.new(1867, 10, 18, 0, 0, 0, TZInfo::Timezone.get("America/Juneau")).to_datetime.julian
=> 1867-10-06 00:00:00 +1502
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kumar |
Solution 2 |