LdapServer: fix formating naive date/datetime

This commit is contained in:
Benjamin Renard 2021-03-24 12:37:03 +01:00
parent 6830447f96
commit 35187aebdf

View file

@ -365,7 +365,7 @@ def format_datetime(value, from_timezone=None, to_timezone=None, naive=None):
to_timezone = dateutil.tz.tzlocal() to_timezone = dateutil.tz.tzlocal()
elif isinstance(to_timezone, str): elif isinstance(to_timezone, str):
to_timezone = pytz.timezone(to_timezone) to_timezone = pytz.timezone(to_timezone)
to_value = from_value.astimezone(to_timezone) to_value = from_value.astimezone(to_timezone) if not naive else from_value
datestring = to_value.strftime('%Y%m%d%H%M%S%z') datestring = to_value.strftime('%Y%m%d%H%M%S%z')
if datestring.endswith('+0000'): if datestring.endswith('+0000'):
datestring = datestring.replace('+0000', 'Z') datestring = datestring.replace('+0000', 'Z')