Representing ambiguity in datetime?

Steve Holden steve at holdenweb.com
Tue May 17 18:40:17 EDT 2005


Terry Hancock wrote:
> What do you do when a date or time is
> incompletely specified?  ISTM, that as it is, there is no
> formal way to store this --- you have to guess, and there's
> no way to indicate that the guess is different from solid
> information.  As a result, I have sometimes had to abandon
> datetime, even though it seemed like the logical choice for
> representing data.
> 
> E.g. I might have information like "this paper was published
> in May 1997".  There's no way to write that with datetime,
> is there?  Even if I just use the "date" object instead of 
> datetime, I still have to actually specify something like 
> May 1, 1997 --- fabricating data, which is frequently
> undesireable (later on, I might find information saying that
> it was actually published May 23, 1997 and I might want
> to update the earlier one, or simply evaluate them as 
> "equal" since they are, to within the precision given --- 
> for example, I might be trying to decide that two database
> entries are really duplicate references to the same paper).
> 
> I know that this is somewhat theoretically stated, but I 
> have run into to concrete problems along the lines of
> the above.
> 
> I'd say this is analogous to how you might use "None"
> rather than "0" to represent an integer if you don't know
> it's value (rather than knowing that it is zero).  ISTM, you
> ought to be able to specify a date as, e.g.:
> 
> d = datetime.date(2005, 5, None)
> 
> I realize there might be some complexity with deciding
> how to handle datestamp math, but as this situation
> occurs frequently in real life, it seems like it shouldn't
> be avoided.
> 
> How do other people deal with this kind of problem?
> 
It's not a problem I've had to deal with, but it seems that the simplest 
way to handle it would be to store the value as a datetime and a format. 
That way you can explicitly use 1 or 0 as a default (as appropriate) to 
create the datetime and then ensure it's represented only to the 
required degree of precision by using the supplied format.

Don't know whether this will work for you, just a thought.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list