Skip to content

Commit 0a9ff9b

Browse files
authored
Ensure tz-aware timestamps in response (frequenz-floss#124)
The API response contains only tz-naive UTC timestamps, which are converted to tz-aware timestamps to avoid misinterpretation.
2 parents 42fcfec + bdf1d1e commit 0a9ff9b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## Upgrading
88

99
* Update repo-config and setuptools versions
10+
* Timestamps in the response are now timezone aware.
1011

1112
## New Features
1213

src/frequenz/client/reporting/_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections import namedtuple
77
from collections.abc import AsyncIterator, Iterable, Iterator
88
from dataclasses import dataclass
9-
from datetime import datetime, timedelta
9+
from datetime import datetime, timedelta, timezone
1010
from typing import cast
1111

1212
import grpc.aio as grpcaio
@@ -90,6 +90,9 @@ def __iter__(self) -> Iterator[MetricSample]:
9090
cid = cdata.component_id
9191
for msample in cdata.metric_samples:
9292
ts = msample.sampled_at.ToDatetime()
93+
# Ensure tz-aware timestamps,
94+
# as the API returns tz-naive UTC timestamps
95+
ts = ts.replace(tzinfo=timezone.utc)
9396
met = Metric.from_proto(msample.metric).name
9497
value = (
9598
msample.value.simple_metric.value

0 commit comments

Comments
 (0)