]> git.phdru.name Git - mc/extfs.d.git/commitdiff
Fix(torrent): Fix date/time handling
authorOleg Broytman <phd@phdru.name>
Sun, 2 Feb 2025 21:52:28 +0000 (00:52 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 2 Feb 2025 21:52:28 +0000 (00:52 +0300)
Especially with overflow d/t; esp on w32.

torrent

diff --git a/torrent b/torrent
index ca389358613eecc559c0f359c4e9b3e3433474ee..69b0fa7cfe0f4ef4d206a92da239d9512b2e0ff1 100755 (executable)
--- 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)