Adding unknown variables to time.mktime()

Roman Suzi rnd at onego.ru
Tue Jun 26 08:23:14 EDT 2001


On Tue, 26 Jun 2001, Gustaf Liljegren wrote:

> "Roman Suzi" <rnd at onego.ru> wrote:
> 
> > >to be able to give only the 6 first values, since I've never heard of
> > >Julian days, and week day is not significant in this case.
> 
> > try with all 9 integers.
> > RTFM time module docs.
> 
> Read before you post. I always check the library reference, but it doesn't
> give any hints on what I asked for. If mktime() can't do it, maybe there's
> anyother way that you could suggest?

In the docs it is said what those 3 last parameters are about
and how you can specify them if you do not know their values.


   Index  Field                 Values
       0  year                  (e.g. 1993)
       1  month                 range [1,12]
       2  day                   range [1,31]
       3  hour                  range [0,23]
       4  minute                range [0,59]
       5  second                range [0,61]; see (1) in
strftime() description
       6  weekday               range [0,6], Monday is 0
       7  Julian day            range [1,366]
       8  daylight savings flag 0, 1 or -1; see below
       Note that unlike the C structure, the month value is a range of
       1-12, not 0-11. A year value will be handled as described under
       ``Year 2000 (Y2K) issues'' above. A -1 argument as daylight
       savings flag, passed to mktime() will usually result in the
       correct daylight savings state to be filled in.
  
...

   mktime(tuple)
          This is the inverse function of localtime(). Its argument is
          the full 9-tuple (since the dst flag is needed; use -1 as the
          dst flag if it is unknown) which expresses the time in local
          time, not UTC. It returns a floating point number, for
          compatibility with time(). If the input value cannot be
          represented as a valid time, OverflowError is raised.


time.mktime((2001,6,23, 18,0,23, -1, -1, -1))

Works just fine in absolutely most cases (except that 1 hour in the year,
when time makes loops due to daytime savings ;-) and it is not possible to
know DST flag for sure. At those moments system must rely on UTC time.

It's very important to read manual when dealing with such delicate topic
as time.

Maybe you also want to use mxDateTime (not in the standard Python
distribution)
 
> Gustaf

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 







More information about the Python-list mailing list