www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get date at compile time

reply Andrew <aabrown24 hotmail.com> writes:
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
Oct 01 2016
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
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
Oct 01 2016
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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
Oct 01 2016
next sibling parent Andrew <aabrown24 hotmail.com> writes:
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
Oct 01 2016
prev sibling parent reply pineapple <meapineapple gmail.com> writes:
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.
Oct 01 2016
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
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/
Oct 01 2016
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
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
Oct 02 2016
prev sibling parent kdevel <kdevel vogtner.de> writes:
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)
May 26 2017