Skip to content

Commit b02643e

Browse files
authored
Tz update (#7234)
* TZ update Added the possibility to set the timezone without using NTP. This is helpful to have the timezone advantages when using an external RTC. * Update time.cpp
1 parent ea1fdb2 commit b02643e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

cores/esp8266/Arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ long secureRandom(long);
276276
long secureRandom(long, long);
277277
long map(long, long, long, long, long);
278278

279+
void setTZ(const char* tz);
280+
279281
void configTime(int timezone, int daylightOffset_sec, const char* server1,
280282
const char* server2 = nullptr, const char* server3 = nullptr);
281283

cores/esp8266/time.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,23 @@ void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, c
186186
/*** end of posix replacement ***/
187187
}
188188

189+
void setTZ(const char* tz){
190+
191+
char tzram[strlen_P(tz) + 1];
192+
memcpy_P(tzram, tz, sizeof(tzram));
193+
setenv("TZ", tzram, 1/*overwrite*/);
194+
tzset();
195+
}
196+
189197
void configTime(const char* tz, const char* server1, const char* server2, const char* server3)
190198
{
191199
sntp_stop();
192200

193201
setServer(0, server1);
194202
setServer(1, server2);
195203
setServer(2, server3);
196-
char tzram[strlen_P(tz) + 1];
197-
memcpy_P(tzram, tz, sizeof(tzram));
198-
setenv("TZ", tzram, 1/*overwrite*/);
199-
tzset();
200-
204+
setTZ(tz);
205+
201206
sntp_init();
202207
}
208+

0 commit comments

Comments
 (0)