@@ -103,7 +103,7 @@ TimeServiceClass::TimeServiceClass()
103
103
: _con_hdl(nullptr )
104
104
, _is_rtc_configured(false )
105
105
, _is_tz_configured(false )
106
- , _timezone_offset(0 )
106
+ , _timezone_offset(24 * 60 * 60 )
107
107
, _timezone_dst_until(0 )
108
108
, _last_sync_tick(0 )
109
109
, _sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
@@ -184,11 +184,13 @@ void TimeServiceClass::setSyncFunction(syncTimeFunctionPtr sync_func)
184
184
185
185
void TimeServiceClass::setTimeZoneData (long offset, unsigned long dst_until)
186
186
{
187
- if (_timezone_offset != offset || _timezone_dst_until != dst_until) {
188
- DEBUG_DEBUG (" TimeServiceClass::%s offset: %d dst_unitl %ul" , __FUNCTION__, offset, dst_until);
189
- _timezone_offset = offset;
190
- _timezone_dst_until = dst_until;
191
- _is_tz_configured = true ;
187
+ if (isTimeZoneOffsetValid (offset) && isTimeValid (dst_until)) {
188
+ if (_timezone_offset != offset || _timezone_dst_until != dst_until) {
189
+ DEBUG_DEBUG (" TimeServiceClass::%s offset: %d dst_unitl %u" , __FUNCTION__, offset, dst_until);
190
+ _timezone_offset = offset;
191
+ _timezone_dst_until = dst_until;
192
+ _is_tz_configured = true ;
193
+ }
192
194
}
193
195
}
194
196
@@ -312,6 +314,12 @@ bool TimeServiceClass::isTimeValid(unsigned long const time)
312
314
return (time > EPOCH_AT_COMPILE_TIME);
313
315
}
314
316
317
+ bool TimeServiceClass::isTimeZoneOffsetValid (long const offset)
318
+ {
319
+ /* UTC offset can go from +14 to -12 hours */
320
+ return ((offset < (14 * 60 * 60 )) && (offset > (-12 * 60 * 60 )));
321
+ }
322
+
315
323
void TimeServiceClass::initRTC ()
316
324
{
317
325
#if defined (ARDUINO_ARCH_SAMD)
0 commit comments