2
0
Fork 0
forked from zynk/zynk

Fix !forecast showing all days as Sunday on musl libc

strptime on musl (Alpine Linux) does not compute tm_wday from the
parsed date, unlike glibc. Call mktime() after strptime to normalize
the struct tm and reliably compute the day of week on all platforms.
This commit is contained in:
Johannes Findeisen 2026-07-19 18:39:30 +02:00
commit 3727a5f72b
2 changed files with 2 additions and 1 deletions

2
zynk.c
View file

@ -1504,7 +1504,7 @@ static char *fetch_forecast(const char *city_url, const char *city_display) {
}
}
struct tm tm = {0};
if (strptime(date, "%Y-%m-%d", &tm)) strftime(fmt_date[ndays], sizeof fmt_date[ndays], "%a %d %b", &tm);
if (strptime(date, "%Y-%m-%d", &tm)) { mktime(&tm); strftime(fmt_date[ndays], sizeof fmt_date[ndays], "%a %d %b", &tm); }
else snprintf(fmt_date[ndays], sizeof fmt_date[ndays], "%s", date);
snprintf(line[ndays], sizeof line[ndays], "%s: %s\u00b0C %s", fmt_date[ndays], temp, cond);
ndays++;