[phobos] datetime review

Walter Bright walter at digitalmars.com
Fri Oct 8 23:26:36 PDT 2010



Jonathan M Davis wrote:
>
>
> Sure, a MonthDuration holds the number of months internally as an integral 
> value, but if you have an int floating around by itself, it doesn't have any 
> units, and the programmer has to worry about what the int actually means. They'd 
> then have to worry about the conversions between various units of time (month, 
> day, hour, etc.). The duration structs deal with that for you.
>
> Even worse, what would it mean to add a naked number to a time point? If you add 
> 7 to a date, what does that mean? And even if everyone agreed that it was clear 
> that adding 7 to a date meant adding 7 days to it, adding 7 to a time of day 
> wouldn't mean the same thing, so that naked number could mean very different 
> things when added to two different types of time point. By having a duration type 
> which includes the units, it's taken care of for you. You won't try and add 
> months to time of day, because it won't compile. And if you try and add days to 
> it, it will mean exactly the same thing as if you added days to a date (much as 
> adding days to a time of day is relatively pointless). Overall, it should make 
> the programmer's life easier rather than harder.
>   

Ok, I can see that.

>
> Which is why PosixTimeZone and WindowsTimeZone will be getting that information 
> from the OS, but the OS does not make it easy. On Posix, you have to actually 
> read in the time zone files from disk, and on Windows, you have to read the 
> registry. No system calls are provided to properly deal with time zones. 
> Honestly, time zone support for anything other than the local time zone is very 
> poor on both Posix and Windows systems. And Windows won't even let you set the 
> time zone for your program without setting for the whole OS. It's not a pleasant 
> situation really, but I hope to be able to overcome it well enough that D 
> programmers won't have to worry about it.
>
>   

I know it's a miserable job (I failed at it, despite spending a great 
deal of time on it), and since the OS falls down on it, it's a great 
service to have it in the standard library.


More information about the phobos mailing list