Skip to content

Commit e7608da

Browse files
authored
fix: format TopicInfo expiration_time in UTC (hiero-ledger#1802)
Signed-off-by: Eugene Sim <jcseugene@gmail.com>
1 parent 50f17a5 commit e7608da

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Changelog
1+
# Changelog
22

33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org).
@@ -12,6 +12,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
1212
- Added CodeRabbit review instructions and path mapping for the schedule module (`src/hiero_sdk_python/schedule/`) in `.coderabbit.yaml` (#1698)
1313

1414
### Src
15+
- Fix `TopicInfo.__str__()` to format `expiration_time` in UTC so unit tests pass in non-UTC environments. (#1800)
1516
-
1617

1718
### Examples

src/hiero_sdk_python/consensus/topic_info.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
optional fields, and providing a readable string representation of the
77
topic state.
88
"""
9-
from datetime import datetime
9+
from datetime import datetime, timezone
1010
from typing import List, Optional
1111

1212
from hiero_sdk_python.crypto.public_key import PublicKey
@@ -138,9 +138,12 @@ def __str__(self) -> str:
138138
Returns:
139139
str: A nicely formatted string representation of the topic.
140140
"""
141-
exp_dt: Optional[datetime] = None
141+
exp_dt: Optional[str] = None
142142
if self.expiration_time and hasattr(self.expiration_time, "seconds"):
143-
exp_dt = datetime.fromtimestamp(self.expiration_time.seconds)
143+
utc_dt = datetime.fromtimestamp(
144+
self.expiration_time.seconds, tz=timezone.utc
145+
)
146+
exp_dt = utc_dt.strftime("%Y-%m-%d %H:%M:%S")
144147

145148
running_hash_str: Optional[str] = f"0x{self.running_hash.hex()}" if self.running_hash else "None"
146149

0 commit comments

Comments
 (0)