From 60136bf33796d47df34086fe1dc28e13e14623ac Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 27 Feb 2025 22:32:19 +0000 Subject: [PATCH] Slightly simplify SOURCE_DATE_EPOCH handling Subtracting 30 years' worth of seconds from the date and then adding 2000 years is unnecessary when we can just add 1970 years instead. --- bedstead.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bedstead.c b/bedstead.c index 218523a..fe87a1a 100644 --- a/bedstead.c +++ b/bedstead.c @@ -3155,19 +3155,18 @@ time_for_ttx(void) if (!isdigit((unsigned char)epochstr[0]) || endptr == epochstr || *endptr != '\0' || errno == ERANGE || - /* Limit ourselves to 2000 to 10000. */ - epochumax < 946684800 || epochumax >= 253402300800) { + /* Allow years up to 9999. */ + epochumax >= 253402300800) { fprintf(stderr, "Invalid SOURCE_DATE_EPOCH\n"); return NULL; } - epochumax -= 946684800; /* Rebase to 2000. */ tm.tm_isdst = -1; tm.tm_sec = epochumax % 60; tm.tm_min = epochumax / 60 % 60; tm.tm_hour = epochumax / 3600 % 24; long day = epochumax / 86400; - tm.tm_wday = (day - 1) % 7; - int y = 2000 + (day / 146097) * 400; + tm.tm_wday = (day + 4) % 7; /* 1970-01-01 was a Thursday. */ + int y = 1970 + (day / 146097) * 400; day = day % 146097; bool ly; for (;;) { -- 2.30.2