scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 4c18ab2794cd222bbbf8067b2e15e1ab7e9a1c45
parent 317c2fdd2a4f7a4818936ca2afb0626d4c580f75
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Fri, 17 Apr 2026 10:10:50 +0200

libc/time: Obey tm_isdst in mktime()

Due to daylight time saving changes a break down calendar date
can be translated to 2 different time_t representations in
some cases. For this reason the input value of tm_isdst is used
to solve this ambiguety allowing to decide if using dst or not
for the calculation or let to localtime to decide if dst was
in active in that specific date. In any case, the correct value
for tm_zone must set to a valid string always.

Diffstat:
Msrc/libc/arch/posix/_tzone.c | 2+-
Msrc/libc/time/mktime.c | 8+++++++-
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/libc/arch/posix/_tzone.c b/src/libc/arch/posix/_tzone.c @@ -20,7 +20,7 @@ enum { static char st[TOKENSIZ], ds[TOKENSIZ], tokstr[TOKENSIZ]; static int tok; -char *_tzname[2] = { st, ds }; +char *_tzname[2]; time_t _tzstdoff, _tzdstoff; time_t _tzstart, _tzend; int _tzjulian; diff --git a/src/libc/time/mktime.c b/src/libc/time/mktime.c @@ -124,7 +124,13 @@ mktime(struct tm *tm) if (tm->tm_isdst == -1) tm->tm_isdst = aux->tm_isdst; - tm->tm_gmtoff = (tm->tm_isdst == 1) ? _tzdstoff : _tzstdoff; + if (tm->tm_isdst == 1) { + tm->tm_zone =_tzname[1]; + tm->tm_gmtoff = _tzstdoff; + } else { + tm->tm_zone =_tzname[0]; + tm->tm_gmtoff = _tzdstoff; + } t += tm->tm_gmtoff; return t;