Asia/Calcutta is IST (GMT+5:30) but I get HMT(GMT+5:53)

Asked by Sanjay

Asia/Calcutta is actually IST, which is GMT + 5:30. But while using pytz, it was recognized as HMT (GMT + 5:53). While I digged into the oslan database, I see the following:

# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Calcutta 5:53:28 - LMT 1880 # Kolkata
               5:53:20 - HMT 1941 Oct # Howrah Mean Time?
               6:30 - BURT 1942 May 15 # Burma Time
               5:30 - IST 1942 Sep
               5:30 1:00 IST 1945 Oct 15
               5:30 - IST

Need help

Question information

Language:
English Edit question
Status:
Solved
For:
pytz Edit question
Assignee:
No assignee Edit question
Solved by:
Stuart Bishop
Solved:
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Stuart Bishop (stub) said :
#2

As per the responses on the python mailing list, you need to construct localized timestamps using the method described in the README.txt.

>>> tz = pytz.timezone("Asia/Calcutta")
>>> mydate = datetime.datetime(2007, 2, 18, 15, 35)
>>> print tz.localize(mydate)
2007-02-18 15:35:00+05:30

Yes, it sucks that the API is different to that described in the Python manuals, but was the best that could be done while achieving the goal of being able to do non-ambiguous localized timestamp arithmetic.

Revision history for this message
Best Stuart Bishop (stub) said :
#3

Localized timestamps need to be created as described in the README.txt, which is different to the method described in the Python manuals.

>>> tz = pytz.timezone("Asia/Calcutta")
>>> mydate = datetime.datetime(2007, 2, 18, 15, 35)
>>> print tz.localize(mydate)
2007-02-18 15:35:00+05:30

Yes, it sucks that the API is different to that described in the Python manuals, but was the best that could be done while achieving the goal of being able to do non-ambiguous localized timestamp arithmetic.
FAQ #1: “pytz is giving me incorrect timezone information”.

Revision history for this message
Amit Mendapara (cristatus) said :
#4

I have a similar problem:

[code]
>>> import datetime as DT
>>> import pytz
>>> now = DT.datetime.utcnow()
>>> zone = pytz.timezone('Asia/Calcutta')
>>> zone.tzname(now)
'HMT'
[/code]

while it should be 'IST'.

[code]
>>> time.tzname[0]
'IST'
[/code]

Revision history for this message
Sanjay (skpatel20) said :
#5
Revision history for this message
Sanjay (skpatel20) said :
#6

Thanks Stuart Bishop, that solved my question.