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
{
30
- // moved to the embui wifi management
31
- // eGotIPHandler = WiFi.onStationModeGotIP(std::bind(&TimeProcessor::onSTAGotIP, this, std::placeholders::_1));
32
- // eDisconnectHandler = WiFi.onStationModeDisconnected(std::bind(&TimeProcessor::onSTADisconnected, this, std::placeholders::_1));
33
31
// configTzTime(); for esp32 https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-time.c
34
32
35
33
#ifdef ESP8266
@@ -44,18 +42,10 @@ TimeProcessor::TimeProcessor()
44
42
*/
45
43
46
44
#ifdef TZONE
47
- #ifdef ESP8266
48
- configTime (TZONE, NTP1ADDRESS, NTP2ADDRESS);
49
- #elif defined ESP32
50
45
configTzTime (TZONE, NTP1ADDRESS, NTP2ADDRESS);
51
- #endif
52
46
LOG (print, F (" TIME: Time Zone set to: " )); LOG (print, TZONE);
53
47
#else
54
- #ifdef ESP8266
55
- configTime (TZ_DEFAULT, NTP1ADDRESS, NTP2ADDRESS);
56
- #elif defined ESP32
57
48
configTzTime (TZ_DEFAULT, NTP1ADDRESS, NTP2ADDRESS);
58
- #endif
59
49
#endif
60
50
61
51
sntp_stop (); // отключаем ntp пока нет подключения к AP
@@ -122,9 +112,31 @@ void TimeProcessor::setTime(const String ×tr){
122
112
void TimeProcessor::tzsetup (const char * tz){
123
113
// https://stackoverflow.com/questions/56412864/esp8266-timezone-issues
124
114
if (!tz || !*tz)
125
- return ;
115
+ return ;
116
+
117
+ /*
118
+ * newlib has issues with TZ strings with quoted <+-nn> names
119
+ * this has been fixed in https://github.com/esp8266/Arduino/pull/7702 for esp8266 (still not in stable as of Nov 16 2020)
120
+ * but it also affects ESP32 and who knows when to expect a fix there
121
+ * So let's fix such zones in-place untill core support for both platforms available
122
+ */
123
+ if (tz[0 ] == 0x3C ){ // check if first char is '<'
124
+ String _tz (tz);
125
+ String _tzfix ((char *)0 );
126
+ _tzfix.reserve (sizeof (tz)) ;
127
+ _tzfix += FPSTR (P_LOC);
128
+ if (_tz.indexOf (' <' ,1 ) > 0 ){ // there might be two <> quotes
129
+ // LOG(print, "2nd pos: "); LOG(println, _tz.indexOf('<',1));
130
+ _tzfix += _tz.substring (_tz.indexOf (' >' )+1 , _tz.indexOf (' <' ,1 ));
131
+ _tzfix += FPSTR (P_LOC);
132
+ }
133
+ _tzfix += _tz.substring (_tz.lastIndexOf (' >' )+1 , _tz.length ());
134
+ setenv (" TZ" , _tzfix.c_str (), 1 /* overwrite*/ );
135
+ LOG (printf_P, PSTR (" TIME: TZ fix applied: %s\n " ), _tzfix.c_str ());
136
+ } else {
137
+ setenv (" TZ" , tz, 1 /* overwrite*/ );
138
+ }
126
139
127
- setenv (" TZ" , tz, 1 /* overwrite*/ );
128
140
tzset ();
129
141
tzone = " " ; // сбрасываем костыльную зону
130
142
usehttpzone = false ; // запрещаем использование http
0 commit comments