[Zope-Coders] test failures in DateTime

Matthew T. Kromer matt@zope.com
Thu, 04 Oct 2001 11:33:14 -0400


Shane Hathaway wrote

>
> Hmm, that might be a fun project.  Here's one way to pack the bits:
>
> 15 bits   (signed) year (16383 BC to 16383 AD; 0 means 0 BC)
>  4 bits   month (0 to 11)
>  5 bits   day (0 to 30 or perhaps 1 to 31)
> 17 bits   second (0 to 86401 including leap seconds)
> 10 bits   millisecond (0 to 999)
> 11 bits   (signed) timezone offset in minutes (-720 to 840)
>  2 bits   unused
>
> The year set to -16384 would mean no date is set.  The second set to 
> 131071 would mean no time is set.  Or maybe the two unused bits would 
> be flags indicating whether the date and time are set.
>
> Note that the second contains the minute and hour.  In my own 
> experience with writing date/time handlers I have found that it's 
> easier to work with times this way than it is to work with hours and 
> minutes separately.
>

Actually, you might instead use those extra two bits as a 
format-indicator.  It's much easier to do math ops based on an offset 
from an epoch -- you dont have to worry about calendar formatting when 
doing the math then.
So your two extra bits could indicate a format; e.g. 00 = bitfield, 01 = 
milliseconds offset from some epcoch (which I dont have the background 
to know how to compute right now -- with the extra precision though, 
using Jan 1, 1970 UTC seems pretty reasonable, rather than a 
straightforward unsigned approach from some epoch 18,000 years ago -- 
and would facilitate quick conversion to time_t formats).