Python Time classes

phil hunt philh at vision25.demon.co.uk
Wed Apr 26 18:12:17 CEST 2000


Is there a high-level Time class for Python?

I'm aware of the 'time' module in the standard library. But I'm
looking for something more high-level (I can't find anything
relevant on Parnassus or Freshmeat). What I want is roughly the
ability to say things like:

   t1 = Time.now()   
   # (t1) is an instance of Time containing the time now

   t2 = Time(2000, 4, 26, 17, 4, 0) 
   # (t2) is 2000-Apr-26 17:04:00

   sec = t1 - t2   
   # (sec) is the number of seconds between (t1) and (t2)

   str = t1.format("%H:%M:%S")
   # (str) is a string containing the hours minutes and seconds of (t1)
   # in a form like 23:59:06

It'd also be nice if there was a similar Date class which stored
a date (this would behave like a Time except that (i) the hh:mm:ss
would always be 00:00:00, and (ii) subtracting two dates would return
the number of days difference). Obviously times and dates would be
easily convertable to each other:

   aTime = Time(aDate)
   aDate = Date(aTime)

(or similar).


Does this exist, or shall I write one?

-- 
***** Phil Hunt ***** send email to phil at comuno.com *****
Moore's Law: hardware speed doubles every 18 months
Gates' Law: software speed halves every 18 months 



More information about the Python-list mailing list