Magic number removal.

This commit is contained in:
Josh W 2024-04-10 13:13:07 -04:00
parent bd2cc20110
commit 392bba763b
2 changed files with 6 additions and 2 deletions

View file

@ -96,6 +96,10 @@ LEAP_MS_FROM_EPOCH = [
1483228800000, # 1 Jan 2017 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() # DniDate.max.to_ordinal()
# (For whatever reason, 5119863 was the former value and I can't figure why. # (For whatever reason, 5119863 was the former value and I can't figure why.
# Noting it here in case I need it for something.) # Noting it here in case I need it for something.)

View file

@ -4,7 +4,7 @@ from datetime import timedelta
from math import modf from math import modf
from typing import Any, Tuple, TYPE_CHECKING, Union 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 from .utils import cmp, divide_and_round
@ -112,7 +112,7 @@ class DniTimedelta:
assert isinstance(pahr, int) and 0 <= pahr < 25 assert isinstance(pahr, int) and 0 <= pahr < 25
assert isinstance(pro, int) and 0 <= pro < 3125 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}") raise OverflowError(f"DniTimedelta # of yahrtee is too large: {yahr}")
self = object.__new__(cls) self = object.__new__(cls)