From a7b4259d195f715fb28ea5bfd326a2a4b98dd199 Mon Sep 17 00:00:00 2001 From: C Freeman Date: Fri, 21 Jul 2023 23:15:27 -0400 Subject: [PATCH] Fix for DST ValidStarting time not checked (#28188) Previous code didn't check the starting time for the DST and neither did the test. This adds the check to the code and the test, will need to add to the test plans as well. --- .../time-synchronization-server.cpp | 5 ++++- src/python_testing/TC_TIMESYNC_2_8.py | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp index f7a0c39919d168..9a1b2aa408bd59 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp @@ -571,7 +571,10 @@ CHIP_ERROR TimeSynchronizationServer::GetLocalTime(EndpointId ep, DataModel::Nul timeZoneOffset = static_cast(tzStore.timeZone.offset); VerifyOrReturnError(GetDSTOffset().size() != 0, CHIP_ERROR_INVALID_TIME); const auto & dst = GetDSTOffset()[0]; - dstOffset = static_cast(dst.offset); + if (dst.validStarting <= chipEpochTime) + { + dstOffset = static_cast(dst.offset); + } uint64_t usRemainder = chipEpochTime % chip::kMicrosecondsPerSecond; // microseconds part of chipEpochTime chipEpochTime = (chipEpochTime / chip::kMicrosecondsPerSecond); // make it safe to cast to int64 by converting to seconds diff --git a/src/python_testing/TC_TIMESYNC_2_8.py b/src/python_testing/TC_TIMESYNC_2_8.py index ce5ed2b4ec307c..f324a845ba22db 100644 --- a/src/python_testing/TC_TIMESYNC_2_8.py +++ b/src/python_testing/TC_TIMESYNC_2_8.py @@ -17,7 +17,7 @@ import time import typing -from datetime import timedelta +from datetime import datetime, timedelta, timezone import chip.clusters as Clusters from chip.clusters.Types import NullValue @@ -174,7 +174,23 @@ async def test_TC_TIMESYNC_2_8(self): local = await self.read_ts_attribute_expect_success(local_attr) compare_time(received=local, offset=timedelta(seconds=-3600), tolerance=timedelta(seconds=5)) - self.print_step(27, "Send SetDSTOffset command") + self.print_step(27, "Send SetDSTOffset command with DST starting in the future") + valid = utc_time_in_matter_epoch(datetime.now(tz=timezone.utc) + timedelta(seconds=10)) + dst = [dst_struct(offset=3600, validStarting=valid, validUntil=NullValue)] + await self.send_set_dst_cmd(dst) + + self.print_step(28, "Read Localtime") + local = await self.read_ts_attribute_expect_success(local_attr) + compare_time(received=local, offset=timedelta(seconds=0), tolerance=timedelta(seconds=5)) + + self.print_step(29, "Wait 15s") + time.sleep(15) + + self.print_step(30, "Read Localtime") + local = await self.read_ts_attribute_expect_success(local_attr) + compare_time(received=local, offset=timedelta(seconds=3600), tolerance=timedelta(seconds=5)) + + self.print_step(31, "Send SetDSTOffset command") dst = [dst_struct(offset=0, validStarting=0, validUntil=NullValue)] await self.send_set_dst_cmd(dst)