[phobos] datetime review

Jonathan M Davis jmdavisProg at gmx.com
Fri Oct 8 16:09:08 PDT 2010


On Friday, October 08, 2010 14:58:35 Walter Bright wrote:
> I know you've worked hard on this, and I apologize for coming off
> sounding a bit grumpy about things.
> 
> Jonathan M Davis wrote:
> > * datetime.core: Contains types and functions which are used by most of
> > the other modules in datetime (e.g. the enum TUnit which hold the
> > various units of time: year, hour, second, etc.).
> > 
> > * datetime.duration: Contains the various duration types.
> > 
> > * datetime.interval: Contains the various interval and range types.
> 
> [...]
> 
> > * datetime.timepoint: Contains the various time point types. It also
> > contains Clock, which will give you the current time.
> > 
> > * datetime.timezone: Contains the various time zone classes which SysTime
> > uses.
> 
> It bothers me that there are so many types, i.e. "various duration
> types", "various interval types", etc.
> 
> Now that I read that again, why is there both a "duration" and an
> "interval"?

A duration is a length of time with units while an interval is two time points 
(or a time point and a duration) which therefore designate a duration which is 
fixed in time. So, they are distinct (the concepts are from Boost). There are 
multiple duration types primarily because you can't convert between months and 
small units without a specific date, so you can't convert something like 5 months 
to days without knowing which months you're dealing with. However, I have 
definite worked on making it so that you don't have to worry about the multiple 
duration types in most cases. You'd do something like Dur.years(5) + Dur.days(2) 
to create a duration of 5 years and 2 days, and you don't have to know or care 
what the duration types are.

There are multiple interval types only to deal with infinity. You have Interval, 
with a definite begin and end, PosInfInterval which goes from a specific time 
point to infinity, and NegInfInterval which goes from negative infinity to a 
specific time point. The infinite intervals are primarily of interest in creating 
infinite ranges. A lot of user code could simpler ignore them.

> 
> Why are there multiple "various time zone classes" instead of "a" time
> zone class?

There are multiple time zone classes because it uses polymorphism to deal with 
the rules for a given time zone. The really basic LocalTime and UTC deal with 
most cases, but for anyone who really needs to deal with multiple time zones, 
PosixTimeZone and WindowsTimeZone will be invaluable (I'd love to only have one 
of those, but Windows just doesn't deal with time zones like the Posix world 
does).

> Does handling time really merit seven modules?

It was one until just the other day, but it was just too many lines of code for 
a single module. Ideally, you'd just import datetime.all and you wouldn't have 
to deal with importing individual modules (though unfortunately, there isn't 
presently any way to combine the documentation in that manner).

Overall, I don't think that it's all that complicated, but it's a lot of code, 
and it's definitely the case that some of it will not be needed in the average 
application, but having it would be extremely useful. The generic nature of much 
of the code reduces how much you really have to worry about too.

However, the proper dealing of dates and times can get pretty complicated (the C 
API can't even dream of coming close to covering what a real date/time library 
should cover), so any serious date/time library is not going to be a small, 
simple module. I have done my best to make what I've done both simple and 
flexible, but there is a lot of it.

The real question is whether I've managed to make something which is both easily 
useable for the average application which doesn't care about much beyond getting 
the current time and yet still gives applications which really care about 
manipulating dates and times the features and capabilities that they need.

> 
> > The code:
> > https://docs.google.com/leaf?id=0B-f1J0HiG2ovYmMzYWVkODMtODRiYi00NTg4LWI
> > 4MDctOTQ0MjE4YTI5Y2U1&sort=name&layout=list&num=50
> 
> Argh, I have to create Yet Another Account just to look at the code. I
> apologize if my comments are answered in the code source.

You shouldn't need to create an account. It should be accessible without any 
type of account. If you need an account, I screwed up. The short URL is 
http://is.gd/fS35q . I originally just attached the code to the e-mail, but Brad  
asked me to just post a link to it. Google docs was the best that I could come 
up with.

- Jonathan M Davis


More information about the phobos mailing list