Skip to content

Commit 4047bb6

Browse files
committed
Add edge cases for pre-epoch and 1582 calendar switch
Cover the Julian/Gregorian boundary (proleptic Gregorian, per spec) in days_to_date, and negative pre-1970 inputs in the human-readable timestamp formatters, per review feedback.
1 parent b77ad2a commit 4047bb6

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎tests/utils/test_datetime.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,15 @@ def test_micros_to_days() -> None:
237237

238238

239239
def test_days_to_date() -> None:
240-
for days, expected in [(0, "1970-01-01"), (31, "1970-02-01"), (-1, "1969-12-31")]:
240+
for days, expected in [
241+
(0, "1970-01-01"),
242+
(31, "1970-02-01"),
243+
(-1, "1969-12-31"),
244+
# Proleptic Gregorian (per the Iceberg spec) has no gap at the 1582 Julian/Gregorian switch.
245+
(-141438, "1582-10-04"),
246+
(-141437, "1582-10-05"),
247+
(-141427, "1582-10-15"),
248+
]:
241249
assert days_to_date(days).isoformat() == expected
242250

243251

@@ -267,13 +275,18 @@ def test_to_human_time() -> None:
267275

268276

269277
def test_to_human_timestamp() -> None:
270-
for micros, expected in [(0, "1970-01-01T00:00:00"), (1_740_342_104_375_612, "2025-02-23T20:21:44.375612")]:
278+
for micros, expected in [
279+
(0, "1970-01-01T00:00:00"),
280+
(-1, "1969-12-31T23:59:59.999999"),
281+
(1_740_342_104_375_612, "2025-02-23T20:21:44.375612"),
282+
]:
271283
assert to_human_timestamp(micros) == expected
272284

273285

274286
def test_to_human_timestamptz() -> None:
275287
for micros, expected in [
276288
(0, "1970-01-01T00:00:00+00:00"),
289+
(-1, "1969-12-31T23:59:59.999999+00:00"),
277290
(1_740_342_104_375_612, "2025-02-23T20:21:44.375612+00:00"),
278291
]:
279292
assert to_human_timestamptz(micros) == expected

0 commit comments

Comments
 (0)