[Python-Dev] Store timestamps as decimal.Decimal objects

Nick Coghlan ncoghlan at gmail.com
Tue Jan 31 08:16:06 CET 2012

On Tue, Jan 31, 2012 at 9:31 AM, Victor Stinner
<victor.stinner at haypocalc.com> wrote:
> Hi,
> In issues #13882 and #11457, I propose to add an argument to functions
> returning timestamps to choose the timestamp format. Python uses float
> in most cases whereas float is not enough to store a timestamp with a
> resolution of 1 nanosecond. I added recently time.clock_gettime() to
> Python 3.3 which has a resolution of a nanosecond. The (first?) new
> timestamp format will be decimal.Decimal because it is able to store
> any timestamp in any resolution without loosing bits. Instead of
> adding a boolean argument, I would prefer to support more formats.

I think this is definitely worth elaborating in a PEP (to recap the
long discussion in #11457 if nothing else). In particular, I'd want to
see a very strong case being made for supporting multiple formats over
standardising on a *single* new higher precision format (for example,
using decimal.Decimal in conjunction with integration of Stefan's
cdecimal work) that can then be converted to other formats (like
datetime) via the appropriate APIs.

"There are lots of alternatives, so let's choose not to choose!" is a
bad way to design an API. Helping to make decisions like this by
laying out the alternatives and weighing up their costs and benefits
is one of the major reasons the PEP process exists.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list