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

This commit is contained in:
pukkandan 2022-09-17 11:34:04 +05:30
parent 2b24afa6d7
commit 9665f15a96
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39

View file

@ -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