ebyhr commented on code in PR #4388:
URL: https://github.com/apache/iceberg-python/pull/4388#discussion_r4582959862


##########
tests/utils/test_datetime.py:
##########
@@ -220,3 +229,51 @@ def test_nanos_to_micros(nanos: int, micros: int) -> None:
 )
 def test_nanos_to_hours(nanos: int, hours: int) -> None:
     assert hours == nanos_to_hours(nanos)
+
+
+def test_micros_to_days() -> None:
+    for micros, days in [(0, 0), (86_400_000_000, 1), (-1, -1)]:
+        assert micros_to_days(micros) == days
+
+
+def test_days_to_date() -> None:
+    for days, expected in [(0, "1970-01-01"), (31, "1970-02-01"), (-1, 
"1969-12-31")]:
+        assert days_to_date(days).isoformat() == expected
+
+
+def test_to_human_year() -> None:
+    for ordinal, expected in [(0, "1970"), (1, "1971"), (-1, "1969"), (30, 
"2000")]:
+        assert to_human_year(ordinal) == expected
+
+
+def test_to_human_month() -> None:
+    for ordinal, expected in [(0, "1970-01"), (11, "1970-12"), (12, 
"1971-01"), (13, "1971-02"), (-1, "1969-12")]:
+        assert to_human_month(ordinal) == expected
+
+
+def test_to_human_day() -> None:
+    for ordinal, expected in [(0, "1970-01-01"), (31, "1970-02-01"), (-1, 
"1969-12-31")]:
+        assert to_human_day(ordinal) == expected
+
+
+def test_to_human_hour() -> None:
+    for ordinal, expected in [(0, "1970-01-01-00"), (1, "1970-01-01-01"), (24, 
"1970-01-02-00"), (-1, "1969-12-31-23")]:
+        assert to_human_hour(ordinal) == expected
+
+
+def test_to_human_time() -> None:
+    for micros, expected in [(0, "00:00:00"), (3_661_000_000, "01:01:01"), 
(73_304_375_612, "20:21:44.375612")]:
+        assert to_human_time(micros) == expected
+
+
+def test_to_human_timestamp() -> None:
+    for micros, expected in [(0, "1970-01-01T00:00:00"), 
(1_740_342_104_375_612, "2025-02-23T20:21:44.375612")]:

Review Comment:
   Both this test and `test_to_human_timestamptz` only use non-negative inputs. 
Could we add a pre-epoch case? For example `(-1, "1969-12-31T23:59:59.999999")` 
here and `(-1, "1969-12-31T23:59:59.999999+00:00")` in the timestamptz test.



##########
tests/utils/test_datetime.py:
##########
@@ -220,3 +229,51 @@ def test_nanos_to_micros(nanos: int, micros: int) -> None:
 )
 def test_nanos_to_hours(nanos: int, hours: int) -> None:
     assert hours == nanos_to_hours(nanos)
+
+
+def test_micros_to_days() -> None:
+    for micros, days in [(0, 0), (86_400_000_000, 1), (-1, -1)]:
+        assert micros_to_days(micros) == days
+
+
+def test_days_to_date() -> None:
+    for days, expected in [(0, "1970-01-01"), (31, "1970-02-01"), (-1, 
"1969-12-31")]:

Review Comment:
   Could we add cases around the 1582 Julian/Gregorian switch? `datetime.date` 
is proleptic Gregorian, which matches the Iceberg spec. These cases would guard 
against the hybrid calendar older Spark/Hive used for pre-1582 dates:
   
   ```python
   (-141438, "1582-10-04"), (-141437, "1582-10-05"), (-141427, "1582-10-15")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to