__TIMESTAMP_UNIXEPOCH__ instead of useless __TIMESTAMP__?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Jan 25 07:07:14 UTC 2018


On Wednesday, January 24, 2018 18:25:21 Timothee Cour via Digitalmars-d 
wrote:
> On Wed, Jan 24, 2018 at 5:50 PM, rikki cattermole via Digitalmars-d
>
> <digitalmars-d at puremagic.com> wrote:
> > On 24/01/2018 7:18 PM, Timothee Cour wrote:
> >> __TIMESTAMP__ is pretty useless:
> >> `string literal of the date and time of compilation "www mmm dd
> >> hh:mm:ss
> >> yyyy"`
> >> eg:Wed Jan 24 11:03:56 2018
> >> which is a weird non-standard format not understood by std.datetime.
> >> __DATE__ and __TIME__ are also pretty useless.
> >>
> >> Could we have __TIMESTAMP_UNIXEPOCH__ (or perhaps
> >> __TIMESTAMP_SYSTIME__ to get a SysTime) ?
> >
> > That can be a library solution from __TIMESTAMP__.
>
> no, there's missing time zone information, so we can't reconstruct
> unix epoch nor utc time

Yeah, and since getting that information requires calling C functions that
can't be called during CTFE, you can't interpret the value at compile time -
which is the only time that you're guaranteed that the system running the
code has the same timezone as when __TIMESTAMP__ was intepreted. Either
__TIMESTAMP__ would need to be changed (which I doubt Walter would allow for
fear of something relying on the format), or we'd need something like
__TIMESTAMP_UNIXTIME__ or whatever.

The only viable alternative that I can think of at the moment is to pass the
information to the program as part of the build. But all in all, I think
that __TIMESTAMP__ is pretty useless as-is unless you just want a ballpark
date and time for when the build was generated and don't care what format
it's in.

In most cases, I'd argue that it's better not to have anything like
__TIMESTAMP__, because then the build is guaranteed to not be reproducible,
but presumably you found some use for it, since you're looking for a version
of __TIMESTAMP__ that's in a more standard format.

- Jonathan M Davis



More information about the Digitalmars-d mailing list