473,232 Members | 1,546 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,232 software developers and data experts.

timezones and time_t

Hi,
I've got a Python application that (as well as lots of other stuff!)
has to translate time_t values into strings in the TZ of the users
choice. Looking at the Python Library Reference, I can see no platform
independent way of setting the TZ that time.localtime() returns -
tzset() is marked as only available on Unix and that is indeed the
case.

Is there really nothing "shipped as standard"? I'm using Python 2.4.3
on Windows XP.

If not, what's the de-facto standard... pytz?

Ta!

John

Aug 18 '06 #1
2 2899
MrBlueSky wrote:
Hi,
I've got a Python application that (as well as lots of other stuff!)
has to translate time_t values into strings in the TZ of the users
choice. Looking at the Python Library Reference, I can see no platform
independent way of setting the TZ that time.localtime() returns -
tzset() is marked as only available on Unix and that is indeed the
case.

Is there really nothing "shipped as standard"? I'm using Python 2.4.3
on Windows XP.

If not, what's the de-facto standard... pytz?

Ta!

John
All of the timezone stuff in the standard C/Python libraries is very badly
named and the use of implicit 'TZ' variables in various functions without a
hint in their __doc__ is also annoying.

Basically, I recommend just doing your own TZ translation:
time.asctime(time.gmtime(time.time() + TZOFFSET))
My name recommendations for alternative time interface (t=float-time_t,
tt=timetuple, local_ prefix=function converts via tz parameters):

time.time -time.gmt
Return the current GMT as a float time_t

time.local_t -time.
Return the current Local Time as a float time_t
If argument is given, convert it to local format.

time.asctime -time.str
Return the given time_t as a string. No conversions done.

time.ctime -time.local_str
Remove in favor of: time.str(time.local_t)

time.mktime -time.t_of_tt
time.gmtime -time.tt_of_t
time.localtime -Remove in favor of: time.tt_of_t(time.local_t)

These functions above will prevent a lot of confusion, because you are
forced to either use: time.local_t or time.gmt, and thus you are aware of
what the time_t you are using means. When you use time.str no implicit
conversion takes place as in time.ctime, and confusion is avoided.

Do you think this is worth a PEP?

Aug 19 '06 #2
Thanks for the reply. Unfortunately, a simple "+offset" type solution
isn't really accurate enough for the kind of scenario I'm looking at.
I'm often dealing with different timezones with DST changeovers on
different dates or even different times of day! So I need
industrial-strength timezone handling!

Wrt your naming conventions... sorry, I'm a newbie to Python so not
really qualified to comment. But what's a PEP?

Aug 19 '06 #3

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

Similar topics

6
by: j0mbolar | last post by:
i've read recently that time_t doesn't have to be in second resolution but if it isn't, then what resolution could it be in? microseconds, milliseconds, are all valid? also, does anyone know...
13
by: Michael | last post by:
I would like to set the timezone of a thread to allow me to calculate the UTC time for data sourced from a number of time zones. Although this can be done in C and C++, I annot find how to do...
0
by: Zwyatt | last post by:
I have the following code (simplified here): #include <time.h> class A { public: char *aString; int aNum; time_t aTime; }
0
by: Zwyatt | last post by:
having a really weird little bug w/ time_t...check it out: I have the following code (simplified here): #include <time.h> class A { public: char *aString; int aNum;
0
by: Robert Treat | last post by:
I am trying to figure out if there is a way to determine the timezones supported in postgresql from within the database. If you look at...
2
by: Ivan Novick | last post by:
Given a time_t value, if you wanted to print the time in a specific timezone, is there a better way then what I am currently doing which seems really bad? Currently I set the TZ system...
7
by: David T. Ashley | last post by:
In a web database (PHP), per user, I'd like to allow each user to specify their timezone (this would change how times are adjusted for display for that user). How do I enumerate all possible...
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...
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.