Mailing List Archive

timezone stuff driving me bonkers!!!
Pretty obvious from the header I guess.

I want to convert from a UTC tuple to the time since the epoch. As far
as I can tell this should definitely be timezone, DST, etc. independent.
However, there is a notable absence of this functionality in the time
module (presumably due to C library absences ?)

Anyway, I keep seeing mention that

time.mktime(tpl)-time.timezone - (1)

should work if the timezone is working correctly,

but why isn't it

time.mktime(tpl)-time.altzone ? -
(2)

I merely observe that

time.mktime(time.localtime(time.time()))

is (near enough) time.time()

So, surely in the above example (1), tpl would have to be in localtime
for the above to make sense. Writing as somebody who is currently
observing DST (UK), this is clearly the case as time.timezone = 0.

So, entering a UTC tuple in (1) would not give me the equivalent of
time.time() !! (though (2) would)

Somebody must be able to point out a flaw in my logic ?

Cheers,

Steve.
timezone stuff driving me bonkers!!! [ In reply to ]
Stephen Crompton wrote:
>
> Pretty obvious from the header I guess.
>
> I want to convert from a UTC tuple to the time since the epoch. As far
> as I can tell this should definitely be timezone, DST, etc. independent.
> However, there is a notable absence of this functionality in the time
> module (presumably due to C library absences ?)

Try the utc2local() function in mxDateTime (an extension package
which can download from my Python Pages).

It will convert a DateTime instance using UTC values to a
DateTime instance using local time. The .ticks() method on
that instance will get you the time since epoch value.

Cheers,
--
Marc-Andre Lemburg Y2000: 260 days left
---------------------------------------------------------------------
: Python Pages >>> http://starship.skyport.net/~lemburg/ :
---------------------------------------------------------
timezone stuff driving me bonkers!!! [ In reply to ]
M.-A. Lemburg wrote:

> Try the utc2local() function in mxDateTime (an extension package
> which can download from my Python Pages).
>
> It will convert a DateTime instance using UTC values to a
> DateTime instance using local time. The .ticks() method on
> that instance will get you the time since epoch value.
>
> Cheers,
> --
> Marc-Andre Lemburg Y2000: 260 days left
> ---------------------------------------------------------------------
> : Python Pages >>> http://starship.skyport.net/~lemburg/ :
> ---------------------------------------------------------

Thanks Marc. But why is the logic wrong in the first place ?

Cheers,

Steve.

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

Business Collaborator : http://www.quantisci.co.uk/bc