Thread overview
Get date at compile time
Oct 01, 2016
Andrew
Oct 01, 2016
rikki cattermole
Oct 01, 2016
Adam D. Ruppe
Oct 01, 2016
Andrew
Oct 01, 2016
pineapple
Oct 01, 2016
Adam D. Ruppe
Oct 02, 2016
Jacob Carlborg
May 26, 2017
kdevel
October 01, 2016
Hi,

Is there any way to get the system date at compile time. I want something like:

static string compileDate = Clock.currTime.toString;

but that fails.

Thanks very much

Andrew
October 02, 2016
On 02/10/2016 3:41 AM, Andrew wrote:
> Hi,
>
> Is there any way to get the system date at compile time. I want
> something like:
>
> static string compileDate = Clock.currTime.toString;
>
> but that fails.
>
> Thanks very much
>
> Andrew

https://dlang.org/spec/lex.html#specialtokens
October 01, 2016
On Saturday, 1 October 2016 at 14:41:22 UTC, Andrew wrote:
> Is there any way to get the system date at compile time.

Not exactly, but the special symbol __TIMESTAMP__ gets a string out of the compiler at build time.

http://dlang.org/spec/lex.html#specialtokens
October 01, 2016
On Saturday, 1 October 2016 at 14:43:31 UTC, Adam D. Ruppe wrote:
> On Saturday, 1 October 2016 at 14:41:22 UTC, Andrew wrote:
>> Is there any way to get the system date at compile time.
>
> Not exactly, but the special symbol __TIMESTAMP__ gets a string out of the compiler at build time.
>
> http://dlang.org/spec/lex.html#specialtokens

perfect, works a treat.

Thanks both

Andrew
October 01, 2016
On Saturday, 1 October 2016 at 14:43:31 UTC, Adam D. Ruppe wrote:
> On Saturday, 1 October 2016 at 14:41:22 UTC, Andrew wrote:
>> Is there any way to get the system date at compile time.
>
> Not exactly, but the special symbol __TIMESTAMP__ gets a string out of the compiler at build time.
>
> http://dlang.org/spec/lex.html#specialtokens

Has there been consideration for adding separate integral tokens for day, month, year, etc?

The documentation there doesn't seem to specify but I assume currently the timestamps are for local time? Though I don't currently have any need for this feature I'd imagine that if I did I'd want the time in UTC, not locally, or if it was local that I'd at least want to be able to similarly retrieve the timezone info.

October 01, 2016
On Saturday, 1 October 2016 at 15:00:29 UTC, pineapple wrote:
> Has there been consideration for adding separate integral tokens for day, month, year, etc?

Not that I'm aware of.

The purpose of this is more for things like version and help strings (e.g. "MyApp built 1 Oct 2016") than for serious processing, but you can also slice the string up to do more with it.

> The documentation there doesn't seem to specify but I assume currently the timestamps are for local time?

yeah/
October 02, 2016
On 2016-10-01 17:00, pineapple wrote:

> Has there been consideration for adding separate integral tokens for
> day, month, year, etc?

I think it would be better to implement a parse function for std.datetime which works at compile time. We need a parse function anyway.

-- 
/Jacob Carlborg
May 26, 2017
On Saturday, 1 October 2016 at 15:00:29 UTC, pineapple wrote:
> Though I don't currently have any need for this feature I'd imagine that if I did I'd want the time in UTC, not locally

You may invoke the compiler with TZ= prepended. (Linux)