[Python-Dev] time functions

Thomas Wouters thomas@xs4all.net
Tue, 16 Jan 2001 09:22:11 +0100

On Tue, Jan 16, 2001 at 08:18:38AM +0100, Thomas Wouters wrote:
> On Tue, Jan 16, 2001 at 08:11:38AM +0100, Fredrik Lundh wrote:

> > >   timestr = time.strftime("<format>")

> > since you're assuming a time zone, you could make it accept
> > an integer as well...

> Could, yes... 

Actually, on second thought, lets not, not just yet anyway. Doing that for
all functions in the time module would continue to pollute the already toxic
waters of a C API translated into Python :P Who knows what 'ctime' stands
for, anyway ? And 'asctime' ? How can we expect Python programmers who think
'C' is a high note or average grade, to understand how the time module is
supposed to be used ? :)

We now have:
time() -- return current time in seconds since the Epoch as a float
gmtime() -- convert seconds since Epoch to UTC tuple
localtime() -- convert seconds since Epoch to local time tuple
asctime() -- convert time tuple to string
ctime() -- convert time in seconds to string
mktime() -- convert local time tuple to seconds since Epoch
strftime() -- convert time tuple to string according to format specification

where asctime and ctime are basically wrappers around strftime, and would do
the exact same thing if they both accepted tuples and floats. 

I think we should have something like:
time() -- current time in float
timetuple() -- current (local) time in timetuple
tuple2time(tuple) -- tuple -> float
time2tuple(float, tz=local) -- float -> tuple using timezone tz
stringtime(time=now, format="ctimeformat") -- convert time value to string

Those are just working names, to make the point, I don't have time to think
up better ones :) I'm not sure if the timezone support in the above list is
extensive enough, mostly because I hardly use timezones myself. Also,
tuple2time() could be merged with time(), and likewise for time2tuple() and
timetuple(). I think keeping strftime() and maybe ctime() for ease-of-use is
a good idea, but the rest could eventually be deprecated.

Off-to-important-meetings-*cough*-ly y'rs
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!