@@ -103,7 +103,7 @@ TimeServiceClass::TimeServiceClass()
103103: _con_hdl(nullptr )
104104, _is_rtc_configured(false )
105105, _is_tz_configured(false )
106- , _timezone_offset(0 )
106+ , _timezone_offset(24 * 60 * 60 )
107107, _timezone_dst_until(0 )
108108, _last_sync_tick(0 )
109109, _sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
@@ -184,11 +184,13 @@ void TimeServiceClass::setSyncFunction(syncTimeFunctionPtr sync_func)
184184
185185void TimeServiceClass::setTimeZoneData (long offset, unsigned long dst_until)
186186{
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+ }
192194 }
193195}
194196
@@ -312,6 +314,12 @@ bool TimeServiceClass::isTimeValid(unsigned long const time)
312314 return (time > EPOCH_AT_COMPILE_TIME);
313315}
314316
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+
315323void TimeServiceClass::initRTC ()
316324{
317325#if defined (ARDUINO_ARCH_SAMD)
0 commit comments