Skip to content

Commit cbdd743

Browse files
authored
Merge pull request #57 from AlexanderShenshin/fix/consensus-timestamp
Use Timestamp class for consensus_timestamp conversions
2 parents 363c77c + 4f77297 commit cbdd743

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/hiero_sdk_python/consensus/topic_message.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
from datetime import datetime
22
from typing import Optional, List, Union, Dict
3-
from hiero_sdk_python.hapi.mirror import consensus_service_pb2 as mirror_proto
43

5-
def _to_datetime(ts_proto) -> datetime:
6-
"""
7-
Convert a protobuf Timestamp to a Python datetime (UTC).
8-
"""
9-
return datetime.utcfromtimestamp(ts_proto.seconds + ts_proto.nanos / 1e9)
4+
from hiero_sdk_python import Timestamp
5+
from hiero_sdk_python.hapi.mirror import consensus_service_pb2 as mirror_proto
106

117

128
class TopicMessageChunk:
@@ -16,7 +12,7 @@ class TopicMessageChunk:
1612
"""
1713

1814
def __init__(self, response: mirror_proto.ConsensusTopicResponse):
19-
self.consensus_timestamp = _to_datetime(response.consensusTimestamp)
15+
self.consensus_timestamp = Timestamp.from_protobuf(response.consensusTimestamp).to_date()
2016
self.content_size = len(response.message)
2117
self.running_hash = response.runningHash
2218
self.sequence_number = response.sequenceNumber
@@ -118,7 +114,7 @@ def of_many(cls, responses: List[mirror_proto.ConsensusTopicResponse]) -> "Topic
118114
offset = end
119115

120116
last_r = sorted_responses[-1]
121-
consensus_timestamp = _to_datetime(last_r.consensusTimestamp)
117+
consensus_timestamp = Timestamp.from_protobuf(last_r.consensusTimestamp).to_date()
122118
running_hash = last_r.runningHash
123119
sequence_number = last_r.sequenceNumber
124120

0 commit comments

Comments
 (0)