|
24 | 24 | #endif
|
25 | 25 |
|
26 | 26 | #define TZ_DEFAULT PSTR("GMT0") // default Time-Zone
|
| 27 | +static const char P_LOC[] PROGMEM = "LOC"; |
27 | 28 |
|
28 | 29 | TimeProcessor::TimeProcessor()
|
29 | 30 | {
|
@@ -122,9 +123,31 @@ void TimeProcessor::setTime(const String ×tr){
|
122 | 123 | void TimeProcessor::tzsetup(const char* tz){
|
123 | 124 | // https://stackoverflow.com/questions/56412864/esp8266-timezone-issues
|
124 | 125 | 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 | + } |
126 | 150 |
|
127 |
| - setenv("TZ", tz, 1/*overwrite*/); |
128 | 151 | tzset();
|
129 | 152 | tzone = ""; // сбрасываем костыльную зону
|
130 | 153 | usehttpzone = false; // запрещаем использование http
|
|
0 commit comments