commit 98f4b5fba82c6fc1d7b110c84dbaf3dd0cf171d5
parent 7fff983b4e096b79c6923852afed8f01ba6b7e3d
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sun, 19 Apr 2026 21:55:48 +0200
libc/time: Correct negative week days
When a negative time value is passed to gmtime() we can have
a negative week number that would generate wrong results in
strftime().
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/libc/time/gmtime.c b/src/libc/time/gmtime.c
@@ -22,14 +22,14 @@ gmtime(const time_t *tim)
d = div(tday, 60);
tm.tm_sec = d.rem;
-
d = div(d.quot, 60);
tm.tm_min = d.rem;
-
tm.tm_hour = d.quot;
/* 1/1/1970 was Thursday */
tm.tm_wday = (day + THU) % 7;
+ if (tm.tm_wday < 0)
+ tm.tm_wday += 7;
year = EPOCH;
if (day >= 0) {