Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for DST ValidStarting time not checked #28188

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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