diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-06-21 05:18:03 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-06-21 06:10:39 +0530 |
commit | a35af4306d24c56c6358f89cdf204860d1cd62b4 (patch) | |
tree | 50e41987eafaa7ecbe4eb6ab7c11e8aac22d1ff4 | |
parent | 93b39cdbd9dcf351bfa0c4ee252805b4617fdca9 (diff) | |
download | hypervideo-pre-a35af4306d24c56c6358f89cdf204860d1cd62b4.tar.lz hypervideo-pre-a35af4306d24c56c6358f89cdf204860d1cd62b4.tar.xz hypervideo-pre-a35af4306d24c56c6358f89cdf204860d1cd62b4.zip |
[utils] `strftime_or_none`: Handle negative timestamps
Closes #6706
Authored by pukkandan, dirkf
-rw-r--r-- | yt_dlp/utils/_utils.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 1fd6f44af..256e2db5a 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -2452,7 +2452,10 @@ def strftime_or_none(timestamp, date_format, default=None): if isinstance(timestamp, (int, float)): # unix timestamp # Using naive datetime here can break timestamp() in Windows # Ref: https://github.com/yt-dlp/yt-dlp/issues/5185, https://github.com/python/cpython/issues/94414 - datetime_object = datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc) + # Also, datetime.datetime.fromtimestamp breaks for negative timestamps + # Ref: https://github.com/yt-dlp/yt-dlp/issues/6706#issuecomment-1496842642 + datetime_object = (datetime.datetime.fromtimestamp(0, datetime.timezone.utc) + + datetime.timedelta(seconds=timestamp)) elif isinstance(timestamp, str): # assume YYYYMMDD datetime_object = datetime.datetime.strptime(timestamp, '%Y%m%d') date_format = re.sub( # Support %s on windows |