[Python-Dev] datetime module enhancements (original) (raw)
Guido van Rossum guido at python.org
Fri Mar 9 18:13:12 CET 2007
- Previous message: [Python-Dev] datetime module enhancements
- Next message: [Python-Dev] datetime module enhancements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 3/9/07, skip at pobox.com <skip at pobox.com> wrote:
Christian> I'm proposing some small additions to the datetime module:
>>> td = timedelta(minutes=1, seconds=7, microseconds=500) >>> int(td) 67 >>> long(td) 67L >>> float(td) 67.5 >>> round(td) 68.0 Casting to the number of seconds seems a bit arbitrary. Why not cast to the number of days or number of microseconds?
Because seconds are what's used everywhere else when Python represents time as a number (time.time(), time.sleep(), select, socket timeout, etc.)
If you allow interpretation of timedeltas as int, long or float I'd argue that round not be included. Instead, just round the output of float.
Christian> datetime.datetime has a method (class factory) Christian> fromtimestamp() but its instances are missing a totimestamp() Christian> method that return the Unix timestamp for a date (seconds Christian> since 1970-01-01 00:00:00 UTC). The range of datetime objects far exceeds that of the current Unix timestamp. Given that the range of current (32-bit) Unix timestamps is approximately 1970 to 2038, What would the output of this be? dt = datetime.datetime(3000, 1, 1, 0, 0, 0) print dt.totimestamp() dt = datetime.datetime(1900, 1, 1, 0, 0, 0) print dt.totimestamp()
If you extend the range to 64 bits there's no problem: the first should print 32503680000, the second -2208988800.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] datetime module enhancements
- Next message: [Python-Dev] datetime module enhancements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]