From 908fee3bf286199e2664f13b9767be0152de161a Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 3 Feb 2025 00:52:28 +0300 Subject: [PATCH] Fix(torrent): Fix date/time handling Especially with overflow d/t; esp on w32. --- torrent | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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) -- 2.39.5