472,990 Members | 3,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,990 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 11324
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.