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

need help with timezone conversion (unexpected side effect oftime.mktime ??)

Hello,

Minimal example below - it gives me different output if I comment /
uncomment the extra time.mktime call - note that this call is not
related in any way to main logic flow.
When "problematicStamp = ..." is commented I get
gmtStamp: 1130634600.0

when I uncomment that line I get
gmtStamp: 1130631000.0

I have tried this on a couple of Linux machines and it was
reproducible everyewhere. One of those machines has the following
Python version (If needed I can provide more details)
Python 2.5 (r25:51908, Mar 26 2007, 23:34:03)
Any idea what' happening there ?
Ivan

---------------

import time, os

# to see the difference, uncomment this line
# problematicStamp = time.mktime((2004, 10, 30, 4, 10, 0, 6, 303, -1))

os.putenv("TZ", "Europe/Sofia")
time.tzset()

gmtStamp = time.mktime((2005, 10, 30, 3, 10, 0, 6, 303, -1))
print "gmtStamp:", gmtStamp
Jun 27 '08 #1
5 2080
On 3 Jun, 16:12, Ivan Velev <sir.hey...@gmail.comwrote:
>
Minimal example below - it gives me different output if I comment /
uncomment the extra time.mktime call - note that this call is not
related in any way to main logic flow.

When "problematicStamp = ..." is commented I get
gmtStamp: 1130634600.0

when I uncomment that line I get
gmtStamp: 1130631000.0
I've tried this with Python 2.3 and 2.4 on Red Hat Enterprise Linux 4
and can't reproduce the problem, even with other TZ values such as
"EEST3" (which appears to be a legal name and does change the
timestamp produced). I don't think much has changed in the time module
since 2.4, which means that there might be some kind of library or
configuration issue involved which causes the observed behaviour.

Paul
Jun 27 '08 #2
I've tried this with Python 2.3 and 2.4 on Red Hat Enterprise Linux 4
and can't reproduce the problem, even with other TZ values such as
Thanks for the quick reply.

Can you please let me know what value do you receive during your
tests ?
As far as I can see, Python timezone API is just a wrapper around
(shared ) native C libraries, but I really do not have any idea on how
to reproduce this issue in a non-Python environment :(

btw. problem exists for this particular datetime only, an hour or more
before / after that time givse identical results (this particular
datetime is near the "daylight saving time change" moment)
On Jun 3, 6:01*pm, Paul Boddie <p...@boddie.org.ukwrote:
On 3 Jun, 16:12, Ivan Velev <sir.hey...@gmail.comwrote:
Minimal example below - it gives me different output if I comment /
uncomment the extra time.mktime call - note that this call is not
related in any way to main logic flow.
When "problematicStamp = ..." is commented I get
gmtStamp: 1130634600.0
when I uncomment that line I get
gmtStamp: 1130631000.0

I've tried this with Python 2.3 and 2.4 on Red Hat Enterprise Linux 4
and can't reproduce the problem, even with other TZ values such as
"EEST3" (which appears to be a legal name and does change the
timestamp produced). I don't think much has changed in the time module
since 2.4, which means that there might be some kind of library or
configuration issue involved which causes the observed behaviour.

Paul
Jun 27 '08 #3
Thanks Paul,

I have identified the "problem" - because of daylight change this
particular timesamp was observed twice in Europe/Sofia. Here is the
GMT-to-local-time conversion:
+------------+---------------------+---------------------+
| gmt_stamp | gmt_time | local_time |
+------------+---------------------+---------------------+
| 1130631000 | 2005-10-30 00:10:00 | 2005-10-30 03:10:00 |
+------------+---------------------+---------------------+
| 1130634600 | 2005-10-30 01:10:00 | 2005-10-30 03:10:00 |
+------------+---------------------+---------------------+
| 1130638200 | 2005-10-30 02:10:00 | 2005-10-30 04:10:00 |
+------------+---------------------+---------------------+
| 1130641800 | 2005-10-30 03:10:00 | 2005-10-30 05:10:00 |
+------------+---------------------+---------------------+

When you do local-time-to-GMT conversion you can expect any of those
two timestamps. I missed that initially :( (I was sure that local time
has "one hour gap" and not "one hour of overlapping time")
and I'd recommend the datetime module for any serious work with dates and times.
Last time when I was playing with TZ conversions, I was not able to do
anything using datetime module - it seems that one needs to define his
own set of timezones (+ all the details) to get it working ... Am I
wrong ? Can you show me how do accomplish the same conversion using
datetime module ?

Thanks again,
Ivan
Jun 27 '08 #4
On 9 Jun, 07:40, Ivan Velev <sir.hey...@gmail.comwrote:
Thanks Paul,

I have identified the "problem" - because of daylight change this
particular timesamp was observed twice in Europe/Sofia. Here is the
GMT-to-local-time conversion:

+------------+---------------------+---------------------+
| gmt_stamp | gmt_time | local_time |
+------------+---------------------+---------------------+
| 1130631000 | 2005-10-30 00:10:00 | 2005-10-30 03:10:00 |
+------------+---------------------+---------------------+
| 1130634600 | 2005-10-30 01:10:00 | 2005-10-30 03:10:00 |
+------------+---------------------+---------------------+
| 1130638200 | 2005-10-30 02:10:00 | 2005-10-30 04:10:00 |
+------------+---------------------+---------------------+
| 1130641800 | 2005-10-30 03:10:00 | 2005-10-30 05:10:00 |
+------------+---------------------+---------------------+
I still don't understand why the "problematic" timestamp would affect
the latter operation, though. I can see that both timestamps could be
valid depending on which time zone is supposed to be in operation -
have the dates for daylight saving (summer vs. winter) time changed in
Bulgaria in the last few years? Maybe asking for a conversion for a
date in 2004 invokes some old rules which then affect a conversion for
a date in 2005, even though that would be really bad behaviour (which
I don't see on this machine here).
When you do local-time-to-GMT conversion you can expect any of those
two timestamps. I missed that initially :( (I was sure that local time
has "one hour gap" and not "one hour of overlapping time")
Well, it really isn't overlapping as such: you're in different zones,
of course. ;-)
and I'd recommend the datetime module for any serious work with dates and times.

Last time when I was playing with TZ conversions, I was not able to do
anything using datetime module - it seems that one needs to define his
own set of timezones (+ all the details) to get it working ... Am I
wrong ? Can you show me how do accomplish the same conversion using
datetime module ?
I think it's easiest to install one of the libraries which provides
the zone data. The first one that comes to mind is python-dateutil,
but I think there are others.

Paul
Jun 27 '08 #5
I still don't understand why the "problematic" timestamp would affect
the latter operation, though. I can see that both timestamps could be
valid depending on which time zone is supposed to be in operation -
have the dates for daylight saving (summer vs. winter) time changed in
Bulgaria in the last few years? Maybe asking for a conversion for a
date in 2004 invokes some old rules which then affect a conversion for
a date in 2005, even though that would be really bad behaviour (which
I don't see on this machine here).
According to this page:

http://www.timeanddate.com/worldcloc...one.html?n=238

In 2004 daylight change was done on October 31, while in 2005 it was
done on October 30. Maybe this fact cause the difference in "guess
what is the current daylight offset" behavior ??

Well, it really isn't overlapping as such: you're in different zones,
of course. ;-)
Heh, got it ... apparently "Europe/Sofia" is not a single timezone, it
is an alias for two timezones :)
I think it's easiest to install one of the libraries which provides
the zone data. The first one that comes to mind is python-dateutil,
but I think there are others.
Thanks I will try it.

Once again, thanks for your helpfull responses !
Ivan

On Jun 9, 12:11*pm, Paul Boddie <p...@boddie.org.ukwrote:
On 9 Jun, 07:40, Ivan Velev <sir.hey...@gmail.comwrote:
Thanks Paul,
I have identified the "problem" - because of daylight change this
particular timesamp was observed twice in Europe/Sofia. Here is the
GMT-to-local-time conversion:
+------------+---------------------+---------------------+
| gmt_stamp *| gmt_time * * * * * *| local_time * * * * *|
+------------+---------------------+---------------------+
| 1130631000 | 2005-10-30 00:10:00 | 2005-10-30 03:10:00 |
+------------+---------------------+---------------------+
| 1130634600 | 2005-10-30 01:10:00 | 2005-10-30 03:10:00 |
+------------+---------------------+---------------------+
| 1130638200 | 2005-10-30 02:10:00 | 2005-10-30 04:10:00 |
+------------+---------------------+---------------------+
| 1130641800 | 2005-10-30 03:10:00 | 2005-10-30 05:10:00 |
+------------+---------------------+---------------------+

I still don't understand why the "problematic" timestamp would affect
the latter operation, though. I can see that both timestamps could be
valid depending on which time zone is supposed to be in operation -
have the dates for daylight saving (summer vs. winter) time changed in
Bulgaria in the last few years? Maybe asking for a conversion for a
date in 2004 invokes some old rules which then affect a conversion for
a date in 2005, even though that would be really bad behaviour (which
I don't see on this machine here).
When you do local-time-to-GMT conversion you can expect any of those
two timestamps. I missed that initially :( (I was sure that local time
has "one hour gap" and not "one hour of overlapping time")

Well, it really isn't overlapping as such: you're in different zones,
of course. ;-)
*and I'd recommend the datetime module for any serious work with dates and times.
Last time when I was playing with TZ conversions, I was not able to do
anything using datetime module - it seems that one needs to define his
own set of timezones (+ all the details) to get it working ... Am I
wrong ? Can you show me how do accomplish the same conversion using
datetime module ?

I think it's easiest to install one of the libraries which provides
the zone data. The first one that comes to mind is python-dateutil,
but I think there are others.

Paul
Jun 27 '08 #6

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

Similar topics

1
by: a_geek | last post by:
Hello, I'm writing a small program that needs to check Unix timestamps for falling into an interval (typical usage: ./program 2005-03, you get the idea). Now, I create two time stamps from the...
3
by: fastwings | last post by:
mm the code //////makemenu.h//// class menu { public: int op; pmenu(int op,int sub = 0) { switch op {
1
by: mimmo | last post by:
I have a problem while calculating timezone (from Europe/Rome to Brazil/East). Can someone help me ?? Thank you, Mimmo. On this site http://www.timezoneconverter.com/cgi-bin/tzc.tzc I have...
6
by: sugaray | last post by:
hi, below is my program for doing exercise with library time functions, something is not right with it, and for the time being i couldn't figure out what's wrong and where, thanx for your help. ...
5
by: Bill | last post by:
(I forgot to mention that I'm using C#) ------------------- When communicating with a server via webservices, I need to view and set the timezone information for a simple object (it contains one...
18
by: moni | last post by:
I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using
2
by: John Hanley | last post by:
I am getting some inconsistencies with mktime(). I allocate memory for my struct tm early in my program, and assign only *some* of the member variables. t->tm_sec=s; t->tm_min=m;...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
4
by: reach2raziq | last post by:
Hi All, I have one web site and server that is hosted on "Pacific Standard Time" Zone . When a user from different contries creat blogs the displayed time for respective blog will be a server...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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:
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.