[Python-Dev] datetime module enhancements

skip at pobox.com skip at pobox.com
Fri Mar 9 17:31:17 CET 2007


    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?  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()

Skip


More information about the Python-Dev mailing list