SysTime at compile time

Jonathan M Davis jmdavisProg at gmx.com
Fri Aug 23 15:51:09 PDT 2013


On Friday, August 23, 2013 22:46:34 Paolo Invernizzi wrote:
> Thank you Jonathan, in reality I'm not interested in obtaining
> the current time ('Clock.currTIme' et similia), but only in
> checking some basic behaviour involving already forged times.
> 
> Something works, in a limited and constrained way, but it seems
> that there's a problem with 'Rebindable' in CTFE:
> 
> ---
> enum t = SysTime(0, UTC());
> pragma(msg, t); // SysTime(0L, Rebindable(, (UTC("UTC", "UTC",
> "UTC"))))
> // enum t2 = t + msecs(1000); // typecons.d(956): Error: cannot
> read uninitialized variable this.original in ctfe
> enum d = SysTime(1000, UTC()) - SysTime(10, UTC());
> pragma(msg, d); // Duration(990L)
> ---

Rebindable should work in CTFE eventually:

http://d.puremagic.com/issues/show_bug.cgi?id=10035

However, LocalTime will never work in CTFE, because it has to call tzset. So, 
it may work eventually to create a SysTime with UTC or a SimpleTimeZone but 
not LocalTime, and unfortunately, that means that I can never make 
SysTime.init valid without adding a bunch of null checks to SysTime (which I 
don't want to do) or making it so that LocalTime always has to check whether 
tzset has been called and call it if it hasn't instead of calling it when you 
get the singleton (which I don't really want to do either). So, you might be 
able to get some of what you want eventually, but SysTime will never fully 
work at compile time with the local time zone or with getting the current 
time.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list