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

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

commit 118840b0cabeda36c94e29f864a548430be47c62
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 20 17:04:06 2026 +0200

    libs/libc/time: Add the timezone and daylight variables.
    
    XSI <time.h> has two variables next to tzname: timezone, the seconds
    west of UTC of the local standard time, and daylight, nonzero if the
    time zone has daylight saving time.  tzset() sets them.  NuttX had only
    tzname; <time.h> said "not supported", and programs that read them do
    not compile.  OpenSSL's tests, for example, use timezone.
    
    Define both in libc.  With CONFIG_LIBC_LOCALTIME, settzname() sets them
    from the same zone types that give tzname (in a new helper
    update_tzname(), which localtime() uses too).  Without it, local time is
    UTC and both stay 0.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 include/time.h                 | 14 +++++++-------
 libs/libc/time/lib_localtime.c | 33 +++++++++++++++++++++++++++++----
 libs/libc/time/lib_tzset.c     |  9 +++++++++
 3 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/include/time.h b/include/time.h
index 325ebb49224..299fd54231b 100644
--- a/include/time.h
+++ b/include/time.h
@@ -160,15 +160,15 @@ extern "C"
 {
 #endif
 
-#ifdef CONFIG_LIBC_LOCALTIME
-
-/* daylight - Daylight savings time flag */
-
-/* extern int daylight; not supported */
+/* daylight - Nonzero if the time zone has daylight saving time.
+ * timezone - Seconds west of UTC of the local standard time.
+ * Set up by tzset(); 0 without CONFIG_LIBC_LOCALTIME (local time is UTC).
+ */
 
-/* timezone - Difference from UTC and local standard time */
+extern int daylight;
+extern long int timezone;
 
-/* extern long int timezone; not supported */
+#ifdef CONFIG_LIBC_LOCALTIME
 
 /* tzname[] - Timezone strings
  * Setup by tzset()
diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c
index 43903616d08..e2a6e8533c6 100644
--- a/libs/libc/time/lib_localtime.c
+++ b/libs/libc/time/lib_localtime.c
@@ -338,6 +338,9 @@ FAR char *tzname[2] =
   (FAR char *)g_wildabbr
 };
 
+int daylight;
+long int timezone;
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
@@ -367,6 +370,8 @@ static int  normalize_overflow32(FAR int_fast32_t *tensptr,
               FAR int *unitsptr, int base);
 static int  normalize_overflow(FAR int *tensptr, FAR int *unitsptr,
               int base);
+static void update_tzname(FAR struct state_s *sp,
+                          FAR const struct ttinfo_s *ttisp);
 static void settzname(void);
 static time_t time1(FAR struct tm *tmp,
               FAR struct tm *(*funcp)(FAR const time_t *, int_fast32_t,
@@ -526,6 +531,20 @@ static void scrub_abbrs(struct state_s *sp)
     }
 }
 
+static void update_tzname(FAR struct state_s *sp,
+                          FAR const struct ttinfo_s *ttisp)
+{
+  tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_desigidx];
+  if (ttisp->tt_isdst)
+    {
+      daylight = 1;
+    }
+  else
+    {
+      timezone = -ttisp->tt_utoff;
+    }
+}
+
 static void settzname(void)
 {
   FAR struct state_s * const sp = g_lcl_ptr;
@@ -538,20 +557,26 @@ static void settzname(void)
       return;
     }
 
-  /* And to get the latest zone names into tzname */
+  daylight = 0;
+  timezone = 0;
+
+  /* And to get the latest zone names into tzname, the offset of standard
+   * time into timezone, and whether there is daylight saving time into
+   * daylight (the last transition wins, as for the names)
+   */
 
   for (i = 0; i < sp->typecnt; ++i)
     {
       FAR const struct ttinfo_s * const ttisp = &sp->ttis[i];
 
-      tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_desigidx];
+      update_tzname(sp, ttisp);
     }
 
   for (i = 0; i < sp->timecnt; ++i)
     {
       FAR const struct ttinfo_s * const ttisp = &sp->ttis[sp->types[i]];
 
-      tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_desigidx];
+      update_tzname(sp, ttisp);
     }
 }
 
@@ -2054,7 +2079,7 @@ static FAR struct tm *localsub(FAR const time_t *timep,
   if (result != NULL)
     {
       result->tm_isdst = ttisp->tt_isdst;
-      tzname[result->tm_isdst] = &sp->chars[ttisp->tt_desigidx];
+      update_tzname(sp, ttisp);
       result->tm_zone = tzname[result->tm_isdst];
     }
 
diff --git a/libs/libc/time/lib_tzset.c b/libs/libc/time/lib_tzset.c
index 00f829111ee..59c567d4696 100644
--- a/libs/libc/time/lib_tzset.c
+++ b/libs/libc/time/lib_tzset.c
@@ -26,6 +26,15 @@
 
 #include <time.h>
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Local time is UTC: no daylight saving time, no offset */
+
+int daylight;
+long int timezone;
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/

Reply via email to