Skip to content

Commit 86dc340

Browse files
committed
TimeLib: Workaround for newlib bug with <+-nn> timezone names
local WA for both esp8266 and esp32 'till fixed in both core's Fix for 8266 already in master esp8266/Arduino#7702 Signed-off-by: Emil Muratov <gpm@hotplug.ru>
1 parent a31bd32 commit 86dc340

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

EmbUI/timeProcessor.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif
2525

2626
#define TZ_DEFAULT PSTR("GMT0") // default Time-Zone
27+
static const char P_LOC[] PROGMEM = "LOC";
2728

2829
TimeProcessor::TimeProcessor()
2930
{
@@ -122,9 +123,31 @@ void TimeProcessor::setTime(const String &timestr){
122123
void TimeProcessor::tzsetup(const char* tz){
123124
// https://stackoverflow.com/questions/56412864/esp8266-timezone-issues
124125
if (!tz || !*tz)
125-
return;
126+
return;
127+
128+
/*
129+
* newlib has issues with TZ strings with quoted <+-nn> names
130+
* this has been fixed in https://github.com/esp8266/Arduino/pull/7702 for esp8266 (still not in stable as of Nov 16 2020)
131+
* but it also affects ESP32 and who knows when to expect a fix there
132+
* So let's fix such zones in-place untill core support for both platforms available
133+
*/
134+
if (tz[0] == 0x3C){ // check if first char is '<'
135+
String _tz(tz);
136+
String _tzfix((char *)0);
137+
_tzfix.reserve(sizeof(tz)) ;
138+
_tzfix += FPSTR(P_LOC);
139+
if (_tz.indexOf('<',1) > 0){ // there might be two <> quotes
140+
LOG(print, "2nd pos: "); LOG(println, _tz.indexOf('<',1));
141+
_tzfix += _tz.substring(_tz.indexOf('>')+1, _tz.indexOf('<',1));
142+
_tzfix += FPSTR(P_LOC);
143+
}
144+
_tzfix += _tz.substring(_tz.lastIndexOf('>')+1, _tz.length());
145+
setenv("TZ", _tzfix.c_str(), 1/*overwrite*/);
146+
LOG(printf_P, PSTR("TIME: TZ fix applied: %s\n"), _tzfix.c_str());
147+
} else {
148+
setenv("TZ", tz, 1/*overwrite*/);
149+
}
126150

127-
setenv("TZ", tz, 1/*overwrite*/);
128151
tzset();
129152
tzone = ""; // сбрасываем костыльную зону
130153
usehttpzone = false; // запрещаем использование http

0 commit comments

Comments
 (0)