This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 191f2c7d1e9d1446498bdda7dd287b49a85d81ab
Author: yukangzhi <[email protected]>
AuthorDate: Thu Oct 15 09:46:58 2026 +0800

    libs/libc/time: fix POSIX TZ DST transitions without zoneinfo.
    
    When CONFIG_LIBC_ZONEINFO is not configured, tzparse() cannot load the
    posixrules base file, so atlo stays at TIME_T_MIN. The POSIX-rule
    transition generator then starts two transitions per year from
    EPOCH_YEAR - YEARSPERREPEAT/2 (~1770) and overflows TZ_MAX_TIMES around
    1954, long before the current era. As a result no DST transitions exist
    for modern timestamps and localtime()/mktime() silently ignore DST
    (tm_isdst always 0, tm_hour off by the DST offset).
    
    Clamp atlo to the Unix epoch when no base rules are loaded so transition
    generation covers EPOCH_YEAR forward, giving ~TZ_MAX_TIMES/2 years of
    correct DST rules.
    
    Assisted-by: Kiro
    Signed-off-by: yukangzhi <[email protected]>
---
 libs/libc/time/lib_localtime.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c
index 7f319df121e..3d6823ebbfb 100644
--- a/libs/libc/time/lib_localtime.c
+++ b/libs/libc/time/lib_localtime.c
@@ -1613,6 +1613,21 @@ static int tzparse(FAR const char *name, FAR struct 
state_s *sp,
       if (load_ok != 0)
         {
           sp->leapcnt = 0; /* so, we're off a little */
+
+          /* No zoneinfo base rules were available (common on embedded
+           * builds without CONFIG_LIBC_ZONEINFO). The POSIX-rule
+           * transition generator below starts two transitions per year
+           * from the lower bound "atlo" and stops once the table reaches
+           * TZ_MAX_TIMES.  With atlo == TIME_T_MIN the backward scan walks
+           * yearbeg down to EPOCH_YEAR - YEARSPERREPEAT / 2 and the table
+           * then fills with ancient years, overflowing TZ_MAX_TIMES long
+           * before reaching the current era, so modern DST transitions are
+           * never recorded and localtime()/mktime() silently ignore DST.
+           * Clamp atlo to the Unix epoch so generation covers EPOCH_YEAR
+           * forward, giving ~TZ_MAX_TIMES / 2 years of correct DST rules.
+           */
+
+          atlo = 0;
         }
     }
 

Reply via email to