[outtmpl] Make `%s` work in strfformat for all systems

pull/4947/head
pukkandan 2 years ago
parent 2b24afa6d7
commit 9665f15a96
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

@ -2567,6 +2567,8 @@ def strftime_or_none(timestamp, date_format, default=None):
datetime_object = datetime.datetime.utcfromtimestamp(timestamp)
elif isinstance(timestamp, str): # assume YYYYMMDD
datetime_object = datetime.datetime.strptime(timestamp, '%Y%m%d')
date_format = re.sub( # Support %s on windows
r'(?<!%)(%%)*%s', rf'\g<1>{int(datetime_object.timestamp())}', date_format)
return datetime_object.strftime(date_format)
except (ValueError, TypeError, AttributeError):
return default

Loading…
Cancel
Save