Rant: Date and Time fall short of simplicity in D

Kagamin spam at here.lot
Sat Mar 30 11:10:43 PDT 2013


> unix time will need a wrapper for strong typing
>
> struct UnixTime { int value; }
> SysTime toSysTime(UnixTime fromValue, TimeZone zone=Utc)
> { return SysTime(unixTimeToStdTime(fromValue.value), zone); }
>
> so conversion is
>
> return UnixTime(d.when.time).toTime!DateTime;
>
> may be it can be reduced to
>
> return to!DateTime(UnixTime(d.when.time));

For primitive types one may have functions which convert directly 
to SysTime instead of wrappers, this will also enable overloading 
if someone uses wider types with the same semantics.

SysTime unixTime(time_t fromValue, TimeZone zone=Utc)
{ return SysTime(unixTimeToStdTime(fromValue), zone); }

return unixTime(d.when.time).toTime!DateTime;

strongly typed time formats with defined conversion method to and 
from SysTime will be just

FILETIME ft;
return ft.toTime!DateTime;


More information about the Digitalmars-d mailing list