[Python-Dev] Supporting precision in a DateTime type

Steve Alexander steve@cat-box.net
Wed, 27 Feb 2002 17:44:28 +0000

Hi folks,

On #zope3-dev, we were discussing how best to implement a DateTime type 
in Python.

Leaving aside arguments of whether to store it as a packed C tuple, or 
as ms since an epoch, I'd like to think about the concept of precision 
as it relates to dates and times.

As a writer of software applications that people use in people settings, 
I like to use types that reflect the elements of reality that people 
find important.

One aspect of time that is important is its precision. Here's an example

   How long is it between 1992 and March 15, 1993 ?

There isn't a sensible answer. Or, rather, there are many answers, some 
more sensible than others. The correct answer might be "1 year", a date 
range, or an error (perhaps a ValueError). In any case, the correct 
answer depends on the nature of the application.

Thus, if I'm only interested in using dates, such as in an application 
where I'm interested in birthdays, I want to be able to describe a date 
without reference to a particular time. It isn't just a default time, it 
is a "no time specified".
So, I won't get caught later on if I compare that datetime instance with 
another that has a different precision.

It is often possible to resolve differing precisions in an 
application-specific way.

Another way of thinking about precision is as a constraint on possible 
more precise values. So, I can play an April fool prank any time in the 
morning of April 1, in my local time-zone. The actual exact time of my 
pranks will fall within the less precise constraint. This makes dates 
with precision similar to durations.

Common precisions in applications include years, months, iso weeks of a 
year, days.
Any finer precision doesn't really matter; the max precision of time in 
C is ok for most human purposes.

Although you could catch some cases by having distinct types for dates 
and times, this only captures the precision of days. It doesn't help for 
other precisions.

Here's a paper I found via google, that discusses these issues:


ps. I'm not a regular reader of python-dev. Guido suggested I post this 
here for further discussion.
I'll catch up via the web eventually, but please cc me into any relevant 

Steve Alexander