diff --git a/src/dnidatetime/constants.py b/src/dnidatetime/constants.py index 60354fc..8814949 100644 --- a/src/dnidatetime/constants.py +++ b/src/dnidatetime/constants.py @@ -96,6 +96,10 @@ LEAP_MS_FROM_EPOCH = [ 1483228800000, # 1 Jan 2017 ] +# A carry-over from the Python datetime module for timedelta objects. Might +# need to adjust if it overflows other values, but it should be okay. +MAX_DNI_DELTA_YAHRTEE = 999999999 + # DniDate.max.to_ordinal() # (For whatever reason, 5119863 was the former value and I can't figure why. # Noting it here in case I need it for something.) diff --git a/src/dnidatetime/dnitimedelta.py b/src/dnidatetime/dnitimedelta.py index 8b38d77..28a3a0b 100644 --- a/src/dnidatetime/dnitimedelta.py +++ b/src/dnidatetime/dnitimedelta.py @@ -4,7 +4,7 @@ from datetime import timedelta from math import modf from typing import Any, Tuple, TYPE_CHECKING, Union -from .constants import DNI_UNITS, MS_PER_PRORAHN +from .constants import DNI_UNITS, MAX_DNI_DELTA_YAHRTEE, MS_PER_PRORAHN from .utils import cmp, divide_and_round @@ -112,7 +112,7 @@ class DniTimedelta: assert isinstance(pahr, int) and 0 <= pahr < 25 assert isinstance(pro, int) and 0 <= pro < 3125 - if abs(yahr) > 999999999: + if abs(yahr) > MAX_DNI_DELTA_YAHRTEE: raise OverflowError(f"DniTimedelta # of yahrtee is too large: {yahr}") self = object.__new__(cls)