From 4e2eaeeb0879d314dd91affece352052ce76cc6b94a5eaeb3f497ff368b371af Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 4 Dec 2024 16:17:07 +0300 Subject: [PATCH] Simpler and more robust datetime overflow check --- pyac/pyac.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyac/pyac.py b/pyac/pyac.py index 4cb9c53..5502d16 100755 --- a/pyac/pyac.py +++ b/pyac/pyac.py @@ -317,10 +317,13 @@ def loads(v, sets=False, leapsecUTCAllow=False): secs = tai2utc(secs - TAI64Base, leapsecUTCAllow) if secs is None: return Raw(v[0], v[1:1+l]), v[1+l:] - if (abs(secs) > (1 << 60)) or (asecs > 0) or ((nsecs % 1000) > 0): - # Python can represent neither big values, nor nanoseconds + if (asecs > 0) or ((nsecs % 1000) > 0): + # Python can represent neither attoseconds, nor nanoseconds + return Raw(v[0], v[1:1+l]), v[1+l:] + try: + dt = datetime(1970, 1, 1) + timedelta(seconds=secs) + except OverflowError: return Raw(v[0], v[1:1+l]), v[1+l:] - dt = datetime(1970, 1, 1) + timedelta(seconds=secs) dt += timedelta(microseconds=nsecs // 1000) return dt, v[1+l:] if (v[0] & TagStr) > 0: -- 2.50.0