vfs: torrent - fix date/time handling

Especially with overflow d/t; esp on w32.

Closes MidnightCommander/mc#213 .

Signed-off-by: Oleg Broytman <phd@phdru.name>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
Oleg Broytman 2025-02-16 18:06:58 +03:00 committed by Yury V. Zaytsev
parent 621c303df1
commit bc213f6ffb

19
src/vfs/extfs/helpers/torrent.in Normal file → Executable file
View File

@ -425,18 +425,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)