[phobos] datetime review
Michel Fortin
michel.fortin at michelf.com
Tue Oct 12 12:19:51 PDT 2010
Le 2010-10-12 à 10:21, Andrei Alexandrescu a écrit :
> On 10/12/2010 08:26 AM, Michel Fortin wrote:
>> 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.
>
> Interesting point. I wonder what Boost does.
Boost has posix_time::ptime which is basically a UNIX timestamp, then it has gregorian::date with fields year, month, and day. It's a little mixed-up, since posix_time depends on gregorian for some things, but beyond that if someone wanted to implement a different calendar, posix_time::ptime could easily serve as the common format between them.
Jonathan's datetime is pretty much a mirror of boost, with Date being the gregorian date, and SysTime being timestamp based, and they interact pretty much the same. Since you (Andrei) asked for Phobos datetime to be a port of boost::datetime, I'll have to say he has done a pretty good job at it. That said, I was never impressed much by boost::datetime for a couple of reasons (too many data types, coupling of calendar and time stuff), but doing things as I'd like them would probably be a major redesign and need more thinking; I don't want to force this on anyone.
For a date system that does support multiple calendars very well, take look at the Cocoa dates. Cocoa has NSDate which is basically a timestamp, NSDateComponents which contains a list of components for calendar dates and time of day, and the NSCalendar class that converts between the two.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the phobos
mailing list