I was trying to convert US/Eastern timezone dates to UTC to upload to a website that only accepts UTC times, but displays time in local timezone. I have the following code example where when I convert a recent date, there is no issue with the offset (5:00 or 4:00), but when I convert a date such as 1900-01-01, the offset becomes something around 4:56 etc.
import pytz
import tzlocal
from datetime import datetime
usest=tzlocal.get_localzone()#My local zone is US/Eastern. I could directly use that here as pytz.timezone("US/Eastern")
dt=datetime(1900,1,1,0,0,0)
dt_aware=usest.localize(dt,is_dst=True)
utcdate=dt_aware.astimezone(pytz.utc)
print (utcdate)
1900-01-01 04:56:00+00:00
dt1=datetime(2016,1,1,0,0,0)
dt1_aware=usest.localize(dt1,is_dst=True)
utcdate1=dt1_aware.astimezone(pytz.utc)
print (utcdate1)
2016-01-01 05:00:00+00:00
I am expecting 1900-01-01 05:00:00+00:00 in case of the first date as well. Why is this happening? Is this correct?
It is important to note that when I convert the UTC Time "1900-01-01 04:56:00+00:00" back to US/Eastern time, it converts back to "1900-01-01 00:00:00". So, the difference of a few minutes must have some logic behind it.
I found this on Wikipedia site "https://en.wikipedia.org/wiki/Tz_database" under the section "Example zone and rule lines"
Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone America/New_York -4:56:02 - LMT 1883 Nov 18 12:03:58
I don't necessarily understand what they were talking about, but I see the offset 4:56 there. I feel that I am closer to an answer but need some help.
Update: I tried the zdump on my Mac book pro, and got the output from the year 1901. Could not, get the details for the years before that. I have researched the details provided in the tz database, but could not find a definitive answer. For the purpose of my current project, I used an alternative zone converter module (pendulum) that doesn't try to be truthful to the history but follows the current daylight savings cycle which resolved my issue. But, the question remains. Why is there a time offset different from 5:00/4:00 hours when converting dates before the year 1900 between Eastern time zone and UTC?