From 4f772974a7e0b1abb2fe11a00ab6b95c31dd9972 Mon Sep 17 00:00:00 2001 From: Alexander Shenshin Date: Fri, 21 Feb 2025 17:58:13 +0300 Subject: [PATCH] Use Timestamp class for consensus_timestamp conversions Signed-off-by: Alexander Shenshin --- src/hiero_sdk_python/consensus/topic_message.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/hiero_sdk_python/consensus/topic_message.py b/src/hiero_sdk_python/consensus/topic_message.py index 35f6196..c09072b 100644 --- a/src/hiero_sdk_python/consensus/topic_message.py +++ b/src/hiero_sdk_python/consensus/topic_message.py @@ -1,12 +1,8 @@ from datetime import datetime from typing import Optional, List, Union, Dict -from hiero_sdk_python.hapi.mirror import consensus_service_pb2 as mirror_proto -def _to_datetime(ts_proto) -> datetime: - """ - Convert a protobuf Timestamp to a Python datetime (UTC). - """ - return datetime.utcfromtimestamp(ts_proto.seconds + ts_proto.nanos / 1e9) +from hiero_sdk_python import Timestamp +from hiero_sdk_python.hapi.mirror import consensus_service_pb2 as mirror_proto class TopicMessageChunk: @@ -16,7 +12,7 @@ class TopicMessageChunk: """ def __init__(self, response: mirror_proto.ConsensusTopicResponse): - self.consensus_timestamp = _to_datetime(response.consensusTimestamp) + self.consensus_timestamp = Timestamp.from_protobuf(response.consensusTimestamp).to_date() self.content_size = len(response.message) self.running_hash = response.runningHash self.sequence_number = response.sequenceNumber @@ -118,7 +114,7 @@ def of_many(cls, responses: List[mirror_proto.ConsensusTopicResponse]) -> "Topic offset = end last_r = sorted_responses[-1] - consensus_timestamp = _to_datetime(last_r.consensusTimestamp) + consensus_timestamp = Timestamp.from_protobuf(last_r.consensusTimestamp).to_date() running_hash = last_r.runningHash sequence_number = last_r.sequenceNumber