Skip to content

Commit 1799b42

Browse files
committed
work arond zephyr localtime() always having 0 offset
1 parent 1c4a00a commit 1799b42

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

xs/platforms/zephyr/xsHost.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2025 Moddable Tech, Inc.
2+
* Copyright (c) 2016-2026 Moddable Tech, Inc.
33
*
44
* This file is part of the Moddable SDK Runtime.
55
*
@@ -765,8 +765,6 @@ uint32_t espRead32be(const void *addr)
765765
static int32_t gTimeZoneOffset = -8 * 60 * 60; // Menlo Park
766766
static int16_t gDaylightSavings = 60 * 60; // summer time
767767

768-
static uint32_t gTimeOfDayOffset = 0; // seconds to add to gMS to get TOD
769-
770768
static modTm gTM; //@@ eliminate with _r calls
771769

772770
static const uint8_t gDaysInMonth[] ICACHE_XS6RO2_ATTR = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@@ -820,10 +818,10 @@ struct modTm *modGmTime(const modTime_t *timep)
820818
return &gTM;
821819
}
822820

823-
struct modTm *modLocalTime(const modTime_t *timep)
821+
c_tm *modLocalTime(const c_time_t *timep)
824822
{
825-
modTime_t t = *timep + gTimeZoneOffset + gDaylightSavings;
826-
return modGmTime(&t);
823+
c_time_t t = *timep + gTimeZoneOffset + gDaylightSavings;
824+
return c_gmtime(&t);
827825
}
828826

829827
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_15

xs/platforms/zephyr/xsHost.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ typedef struct modTm modTm;
158158

159159
void modGetTimeOfDay(struct modTimeVal *tv, struct modTimeZone *tz);
160160
struct modTm *modGmTime(const modTime_t *timep);
161-
struct modTm *modLocalTime(const modTime_t *timep);
162161
modTime_t modMkTime(struct modTm *tm);
163162
void modStrfTime(char *s, size_t max, const char *format, const struct modTm *tm);
164163

@@ -285,7 +284,8 @@ extern int gettimeofday(void *tv, void *unusedTZ);
285284

286285
#define c_gettimeofday modGetTimeOfDay
287286
#define c_gmtime gmtime
288-
#define c_localtime localtime
287+
c_tm *modLocalTime(const c_time_t *timep);
288+
#define c_localtime modLocalTime
289289
#define c_mktime mktime
290290
#define c_strftime strftime
291291
#define c_time time

0 commit comments

Comments
 (0)