[EMAIL PROTECTED] (Rick Measham) wrote:

> There are two time periods that do not change: Years (time the
> earth takes to travel around the sun) and Days (time the earth
> take to spin one complete revolution).  I'd suggest that these
> the the two values that DateTime keeps internally.  The 'year'
> would be an integer delta from some Epoch (BC/1970) and the
> 'day' would be a float representing how many days since the
> start of the year value.

Different calendars have very different ideas about what is a
year, but pretty much every calendar has the notion of a day, so
I'd go for using just the day and time of day.

An example:

Store the date as an array of two integers [N1, N2], where N1 is
the days since some fixed date and N2 is the time of day.  Then,
even if both N1 and N2 must be in the interval [-2^31, 2^31-1] (to
avoid overflow), you can let N2 be the nanoseconds, and thus one
can represent any point in time within more than +/-5 million
years with nanosecond precision using integers only!

This representation is much smaller than storing year, month, day,
hours, minutes, etc. as separate values, and this representation
can easily be converted to a Gregorian date (and back) with a few
lines of pure integer arithemtic.

Peter

PS. If you let N1 and N2 be IEEE doubles, which use 53 bits in the
mantissa, then one can represent any point in time within more
than +/- 9 million billion years with femtosecond (1e-15)
precision, just by using two integers.

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;

Reply via email to