diff --git a/arrow/constants.py b/arrow/constants.py index 532e9596..e75f3832 100644 --- a/arrow/constants.py +++ b/arrow/constants.py @@ -1,7 +1,7 @@ """Constants used internally in arrow.""" import sys -from datetime import datetime +from datetime import datetime, timezone from typing import Final # datetime.max.timestamp() errors on Windows, so we must hardcode @@ -11,7 +11,7 @@ try: # Get max timestamp. Works on POSIX-based systems like Linux and macOS, # but will trigger an OverflowError, ValueError, or OSError on Windows - _MAX_TIMESTAMP = datetime.max.timestamp() + _MAX_TIMESTAMP = datetime.max.replace(tzinfo=timezone.utc).timestamp() except (OverflowError, ValueError, OSError): # pragma: no cover # Fallback for Windows and 32-bit systems if initial max timestamp call fails # Must get max value of ctime on Windows based on architecture (x32 vs x64) @@ -19,9 +19,9 @@ # Note: this may occur on both 32-bit Linux systems (issue #930) along with Windows systems is_64bits = sys.maxsize > 2**32 _MAX_TIMESTAMP = ( - datetime(3000, 1, 1, 23, 59, 59, 999999).timestamp() + datetime(3000, 1, 1, 23, 59, 59, 999999, tzinfo=timezone.utc).timestamp() if is_64bits - else datetime(2038, 1, 1, 23, 59, 59, 999999).timestamp() + else datetime(2038, 1, 1, 23, 59, 59, 999999, tzinfo=timezone.utc).timestamp() ) MAX_TIMESTAMP: Final[float] = _MAX_TIMESTAMP diff --git a/tests/test_arrow.py b/tests/test_arrow.py index b595e4e2..e71ee905 100644 --- a/tests/test_arrow.py +++ b/tests/test_arrow.py @@ -3097,3 +3097,17 @@ def test_get_iteration_params(self): with pytest.raises(ValueError): arrow.Arrow._get_iteration_params(None, None) + + +class TestArrowConstants: + def test_max_timestamp_is_utc_based(self): + from arrow.constants import MAX_TIMESTAMP + + expected = datetime.max.replace(tzinfo=timezone.utc).timestamp() + assert MAX_TIMESTAMP == expected + + def test_max_timestamp_derived_constants(self): + from arrow.constants import MAX_TIMESTAMP, MAX_TIMESTAMP_MS, MAX_TIMESTAMP_US + + assert MAX_TIMESTAMP_MS == MAX_TIMESTAMP * 1000 + assert MAX_TIMESTAMP_US == MAX_TIMESTAMP * 1_000_000