From: Oleg Broytman Date: Sun, 2 Feb 2025 21:52:28 +0000 (+0300) Subject: Fix(torrent): Fix date/time handling X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=908fee3bf286199e2664f13b9767be0152de161a;p=mc%2Fextfs.d.git Fix(torrent): Fix date/time handling Especially with overflow d/t; esp on w32. --- diff --git a/torrent b/torrent index ca38935..69b0fa7 100755 --- a/torrent +++ b/torrent @@ -411,18 +411,23 @@ def decode_torrent(): def decode_datetime_asc(dt): try: - return asctime(localtime(float(dt))) - except ValueError: + lt = localtime(float(dt)) + Y = lt[0] + if Y > 9999: + raise ValueError + except (OSError, ValueError): return datetime.max.ctime() + else: + return asctime(lt) def decode_datetime(dt): try: - Y, m, d, H, M = localtime(float(dt))[0:5] - except ValueError: - return datetime.max.ctime() - if Y > 9999: - Y = 9999 + Y, m, d, H, M = localtime(float(dt))[:5] + if Y > 9999: + raise ValueError + except (OSError, ValueError): + Y, m, d, H, M = datetime.max.timetuple()[:5] return "%02d-%02d-%d %02d:%02d" % (m, d, Y, H, M)