]> jfr.im git - yt-dlp.git/commitdiff
[utils] `strftime_or_none`: Workaround Python bug on Windows
authorpukkandan <redacted>
Sat, 8 Oct 2022 22:48:28 +0000 (04:18 +0530)
committerpukkandan <redacted>
Tue, 11 Oct 2022 02:32:23 +0000 (08:02 +0530)
CLoses #5185

yt_dlp/utils.py

index c2327ae1d03d624799fc93d3c0911fccafe6e011..6cfbcdb8dbc3d1121eeda27aa5e24c694b0e61a0 100644 (file)
@@ -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