aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-10-09 04:18:28 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-10-11 08:02:23 +0530
commitd509c1f5a347d0247593f116fa5cad2ff4f9a3de (patch)
tree417ea32d9f858a8892f9893f53d2ae4893bd8223
parent2c98d998181c81ee49908be03c031204fd66d03d (diff)
downloadhypervideo-pre-d509c1f5a347d0247593f116fa5cad2ff4f9a3de.tar.lz
hypervideo-pre-d509c1f5a347d0247593f116fa5cad2ff4f9a3de.tar.xz
hypervideo-pre-d509c1f5a347d0247593f116fa5cad2ff4f9a3de.zip
[utils] `strftime_or_none`: Workaround Python bug on Windows
CLoses #5185
-rw-r--r--yt_dlp/utils.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index c2327ae1d..6cfbcdb8d 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -2574,7 +2574,9 @@ def strftime_or_none(timestamp, date_format, default=None):
datetime_object = None
try:
if isinstance(timestamp, (int, float)): # unix timestamp
- datetime_object = datetime.datetime.utcfromtimestamp(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)
elif isinstance(timestamp, str): # assume YYYYMMDD
datetime_object = datetime.datetime.strptime(timestamp, '%Y%m%d')
date_format = re.sub( # Support %s on windows