[phobos] datetime review
Jonathan M Davis
jmdavisProg at gmx.com
Tue Oct 12 11:08:59 PDT 2010
On Tuesday, October 12, 2010 06:26:16 Michel Fortin wrote:
> I disagree.
>
> A date can be expressed using different calendars, but can also be stored
> as an interval since a reference date (like the UNIX epoch). With your
> main storage format calendar-agnostic you can easily convert back and
> forth to different calendars-specific formats.
Except that most of the logic is going to be calendar-specific such that you
really don't gain much by trying to separate out the calendar-specific logic.
Date, DateTime, and SysTime all have a property to give you the Xth day since
the beginning of the Proleptic Gregorian Calendar (dayOfGregorianCal IIRC), and
SysTime has the stdTime property which gives you its internal representation of
hecto-nanoseconds (100 ns) since midnight January 1st, 1 AD UTC, so all of the
information necessary to convert to other calendar systems is there. But since
most of the operations on Date, DateTime, and SysTime are specific to the
Gregorian Calendar, I don't see much - if any - gain in trying to refactor out
the non-calendar-specific stuff.
If I do anything to make it easier to handle other calendars, it should be to
make sure that the duration, interval, and range code is fairly calendar
agnostic. And for the most part, I think that it is. Having removed
MonthDuration and JointDuration, it's even more so.
> Also, if you're dealing only with time -- like calculating the time elapsed
> between two time points -- then you don't need any calendar unless you
> plan to display that elapsed time in months or years.
>
> And of course I never meant that Phobos should provide more calendars than
> gregorian. That said, it'd be good if it its gregorian implementation
> could be used as a base to implement other calendars.
Well, if the duration, interval, and range stuff is reasonably calendar agnostic,
then the portions that are really of much use to someone wanting to use datetime
with their own, non-Gregorian Calendar code would be useable with that code. But
I don't think that it makes much sense to try and make the time point types
calendar agnostic. The only one that is is TimeOfDay, since it doesn't deal with
dates at all, and that's quite re-usable in other calendar code.
- Jonathan M Davis
More information about the phobos
mailing list