osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] PEP 410 (Decimal timestamp): the implementation is ready for a review


2012/2/15 "Martin v. L?wis" <martin at v.loewis.de>:
> I agree with Barry here (despite having voiced support for using Decimal
> before): datetime.datetime *is* the right data type to represent time
> stamps. If it means that it needs to be improved before it can be used
> in practice, then so be it - improve it.

Decimal and datetime.datetime are not necessary exclusive options.
Using the API proposed in the PEP, we can add the Decimal type today,
then improve datetime.datetime API, and finally add also
datetime.datetime type.

Such compromise would solve the unspecified starting date issue: an
exception would be raised if the timestamp has an unspecified
timestamp. In such case, you can still get the timestamp as a Decimal
object with nanosecond resolution. Or we may add support of datetime
and Decimal today, even if datetime only support microsecond, and
improve datetime later to support nanosecond.

It looks like there are use cases for Decimal and datetime, both are
useful. At least, datetime has a nice object API related to time,
whereas Decimal requires functions from other modules. I don't know
yet if one type is enough to handle all use cases.

I wrote a patch to demonstrate that my internal API can be extended
(store more information for new types like datetime.datetime) to add
new types later, without touching the public API
(func(timestamp=type)). See timestamp_datetime.patch attached to the
issue #13882 (the patch is now outside, I can update it if you would
like to).

For example:
 - time.time() would support float, Decimal and datetime
 - os.times() would support float and Decimal (but not datetime)

Victor