Skip to content

SOURCE_DATE_EPOCH parsing incorrectly affected by system timezone #22463

@ibuclaw

Description

@ibuclaw

Introduced in #11035

$ cat test.c
#include <stdio.h>
void main() { printf(__DATE__ " " __TIME__ "\n"); }

$ SOURCE_DATE_EPOCH=1 gcc test.c -o test-c
$ ./test-c
Jan  1 1970 00:00:01
$ cat test.d
import core.stdc.stdio;
void main() { printf(__DATE__ ~ " " ~ __TIME__ ~ "\n"); }

$ SOURCE_DATE_EPOCH=1 dmd test.d -oftest-d
$ ./test-d
Dec 31 1969 16:00:01

This is because implementation uses ctime.

// https://issues.dlang.org/show_bug.cgi?id=20444
if (auto p = getenv("SOURCE_DATE_EPOCH"))
{
if (!ct.parseDigits(p[0 .. strlen(p)]))
errorSink.error(Loc.initial, "value of environment variable `SOURCE_DATE_EPOCH` should be a valid UNIX timestamp, not: `%s`", p);
}
else
core.stdc.time.time(&ct);
const p = ctime(&ct);

The call ctime(t) is equivalent to asctime(localtime(t)).

Because explicitly setting SOURCE_DATE_EPOCH is asking for a fixed time, the implementation should instead be calling asctime(gmtime(t)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions