diff --git a/pyiceberg/utils/datetime.py b/pyiceberg/utils/datetime.py index 46bbb32dcd..b5cde34f26 100644 --- a/pyiceberg/utils/datetime.py +++ b/pyiceberg/utils/datetime.py @@ -273,7 +273,7 @@ def nanos_to_time(nanos: int) -> time: def nanos_to_hours(nanos: int) -> int: """Convert a timestamp in nanoseconds to hours from 1970-01-01T00:00.""" - return nanos // 3_600_000_000_0000 + return nanos // 3_600_000_000_000 def nanos_to_micros(nanos: int) -> int: diff --git a/tests/utils/test_datetime.py b/tests/utils/test_datetime.py index 6f6f4a9114..673908e19f 100644 --- a/tests/utils/test_datetime.py +++ b/tests/utils/test_datetime.py @@ -23,6 +23,7 @@ datetime_to_millis, datetime_to_nanos, millis_to_datetime, + nanos_to_hours, nanos_to_micros, time_str_to_nanos, time_to_nanos, @@ -132,3 +133,14 @@ def test_timestamptz_to_nanos(timestamp: str, nanos: int) -> None: @pytest.mark.parametrize("nanos, micros", [(1510871468000001001, 1510871468000001), (-1510871468000001001, -1510871468000002)]) def test_nanos_to_micros(nanos: int, micros: int) -> None: assert micros == nanos_to_micros(nanos) + + +@pytest.mark.parametrize( + "nanos, hours", + [ + (1510871468000001001, 419686), + (-1510871468000001001, -419687), + ], +) +def test_nanos_to_hours(nanos: int, hours: int) -> None: + assert hours == nanos_to_hours(nanos)