473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

pytz giving incorrect offset and timezone

Hi All,

Using pytz, I am facing a problem with Asia/Calcutta, described below.

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

Searching in this group, I saw a similar problem posted at
http://groups.google.co.in/group/com...496e85797ac890
without any solutions.

I mailed to Stuart and also posted it at the launchpad of pytz, but
did not get any response.

Unable to know how to proceed further. Any suggestion will be of vital
help.

thanks
Sanjay

Jul 12 '07 #1
2 11626
On Jul 12, 11:47 am, Sanjay <skpate...@gmail.comwrote:
Hi All,

Using pytz, I am facing a problem with Asia/Calcutta, described below.

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

Searching in this group, I saw a similar problem posted athttp://groups.google.co.in/group/comp.lang.python/browse_thread/threa...
without any solutions.

I mailed to Stuart and also posted it at the launchpad of pytz, but
did not get any response.

Unable to know how to proceed further. Any suggestion will be of vital
help.

thanks
Sanjay
I don't use pytz myself that often so I can't be sure, but I don't
think it's a bug in pytz.

The problem seems to be that the timezone has changed for the
location. Now, without a date as reference, pytz can't know what
timezone to use when constructing the tzinfo; you might want a date
from the 1800's.

When you're constructing the datetime with the tzinfo argument, you're
saying: use this timezone as the local timezone. datetime_new (the
constructor in C) never calls the tzinfo to verify that the timezone
is still valid, it just uses it.

On the other hand: When you construct a datetime with datetime.now()
and pass a timezone, datetime_now (again, in C) calls the method
fromutz() on the tzinfo object. Now the pytz tzinfo object has a
reference by which to choose the current timezone for the location,
and that's why it's correct when you use datetime.now() but not for a
manual construction.

A "workaround" (or maybe the proper way to do it) is to construct the
datetime without a tzinfo set, and then use the localize() method on
the tzinfo object, this will give you the correct result.
>>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

Jul 12 '07 #2
Hi Simon,

localize worked perfectly. Thanks a lot for the vital help! Your
elaboration on the concepts was also very nice and informative!

thanks
Sanjay

Jul 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: scott | last post by:
I am trying to convert a python app that uses matplotlib to a standalone executable using py2exe. After running py2exe and executing my app I get the following stack trace: Traceback (most...
3
by: yashgt | last post by:
In MS SQL 2000, I would like to obtain the timezone offset from UTC for a given date. For today's date, I can do DATEDIFF(ss,GETDATE(),GETUTCDATE()). However, the offset for a future date may not...
5
by: nicolas_riesch | last post by:
Does someone know if the module pytz (http://sourceforge.net/projects/pytz/) is thread-safe ? I have not seen it explicitely stated, and just wanted to be sure, as I want to use it. That's...
4
by: __jakal__ | last post by:
Hello, I need to find out the time difference between UTC and local time. I am doing it the following way #include <sys/timeb.h> #include <stdio.h> int main() { struct timeb tp; ftime(&tp);
0
by: David Pratt | last post by:
Hi. I am creating a couple of small methods to help me manage time from UTC as standard but I am getting strange results. If I start with a datetime of 2005-12-12 14:30:00 in timezone...
0
by: Sanjay | last post by:
Hi All, I am facing some strange problem in pytz. The timezone "Asia/Calcutta" is actually IST, which is GMT + 5:30. But while using pytz, it is being recognized as HMT (GMT + 5:53). While I...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
2
by: =?Utf-8?B?Sm9ubnk=?= | last post by:
I have an ASP.NET 2.0 C# web application that is contacting an Exchange server using WEBDAV. It allows the users to look up appointments for a future date. The problem I have is determining the...
1
by: _robby | last post by:
I am looking at using pytz in a scheduling application which will be used internationally. I would like to be able to update the definition files that pytz uses monthly or bi-monthly. As far as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.