Skip to content

Commit

Permalink
vfs: torrent - fix date/time handling
Browse files Browse the repository at this point in the history
Especially with overflow d/t; esp on w32.

Closes #213 .

Signed-off-by: Oleg Broytman <[email protected]>
Signed-off-by: Yury V. Zaytsev <[email protected]>
  • Loading branch information
phdru authored and zyv committed Feb 16, 2025
1 parent 621c303 commit bc213f6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/vfs/extfs/helpers/torrent.in
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit bc213f6

Please sign in to comment.