Skip to content

Commit a1a197a

Browse files
committed
Enhance timestamp parsing: clarify local time handling and improve test robustness
1 parent f6c8853 commit a1a197a

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

ior_parser/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ def parse_datetime_to_timestamp(date_str: str) -> Optional[int]:
7979
return None
8080

8181
try:
82-
# Try to parse the IOR timestamp format
82+
# Try to parse the IOR timestamp format as local time
8383
dt = datetime.strptime(date_str.strip(), "%a %b %d %H:%M:%S %Y")
84+
# dt.timestamp() returns local time as Unix timestamp
8485
return int(dt.timestamp())
8586
except ValueError:
8687
# If parsing fails, return None

tests/test_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,14 @@ def test_different_months(self):
182182

183183
def test_whitespace_handling(self):
184184
"""Test that function handles whitespace correctly."""
185-
assert parse_datetime_to_timestamp(" Sun Jul 27 08:35:34 2025 ") == 1753630534
186-
assert parse_datetime_to_timestamp("\tSun Jul 27 08:35:34 2025\t") == 1753630534
187-
assert parse_datetime_to_timestamp(" Sun Jul 27 08:35:34 2025 ") == 1753630534
185+
# Compute expected timestamp using local time, so test is robust to environment
186+
from datetime import datetime
187+
188+
base_str = "Sun Jul 27 08:35:34 2025"
189+
expected = int(datetime.strptime(base_str, "%a %b %d %H:%M:%S %Y").timestamp())
190+
assert parse_datetime_to_timestamp(" Sun Jul 27 08:35:34 2025 ") == expected
191+
assert parse_datetime_to_timestamp("\tSun Jul 27 08:35:34 2025\t") == expected
192+
assert parse_datetime_to_timestamp(" Sun Jul 27 08:35:34 2025 ") == expected
188193

189194
def test_invalid_inputs(self):
190195
"""Test that function returns None for invalid inputs."""

0 commit comments

Comments
 (0)