Skip to content

Commit

Permalink
Fix for DST ValidStarting time not checked (#28188)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cecille authored and pull[bot] committed Feb 13, 2024
1 parent dae083e commit a7b4259
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@ CHIP_ERROR TimeSynchronizationServer::GetLocalTime(EndpointId ep, DataModel::Nul
timeZoneOffset = static_cast<int64_t>(tzStore.timeZone.offset);
VerifyOrReturnError(GetDSTOffset().size() != 0, CHIP_ERROR_INVALID_TIME);
const auto & dst = GetDSTOffset()[0];
dstOffset = static_cast<int64_t>(dst.offset);
if (dst.validStarting <= chipEpochTime)
{
dstOffset = static_cast<int64_t>(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
Expand Down
20 changes: 18 additions & 2 deletions src/python_testing/TC_TIMESYNC_2_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a7b4259

Please sign in to comment.