Skip to content
Snippets Groups Projects
Commit 71a4916a authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Fix: Consider daylight saving time in the forms. (Redmine issue: #6197)

parent 6a3f6d63
No related branches found
No related tags found
No related merge requests found
......@@ -432,8 +432,11 @@ class DateTimeLocalField(wtforms.DateTimeField):
"""
localtz = pytz.timezone(flask.session['timezone'])
if value:
dt_utc = pytz.utc.localize(value, is_dst=None)
self.data = dt_utc.astimezone(localtz) # pylint: disable=locally-disabled,attribute-defined-outside-init
try:
dt_utc = pytz.utc.localize(value, is_dst=None)
self.data = dt_utc.astimezone(localtz) # pylint: disable=locally-disabled,attribute-defined-outside-init
except (pytz.exceptions.AmbiguousTimeError, pytz.exceptions.NonExistentTimeError):
self.data = None # pylint: disable=locally-disabled,attribute-defined-outside-init
else:
self.data = None # pylint: disable=locally-disabled,attribute-defined-outside-init
......@@ -452,7 +455,7 @@ class DateTimeLocalField(wtforms.DateTimeField):
dt_local = localtz.localize(dt_naive, is_dst=None)
self.data = dt_local.astimezone(
pytz.utc) # pylint: disable=locally-disabled,attribute-defined-outside-init
except ValueError:
except (pytz.exceptions.AmbiguousTimeError, pytz.exceptions.NonExistentTimeError, ValueError):
self.data = None # pylint: disable=locally-disabled,attribute-defined-outside-init
raise ValueError(self.gettext('Not a valid datetime value'))
......@@ -499,10 +502,13 @@ class SmartDateTimeField(wtforms.Field):
:param value: The python object containing the value to process.
"""
if value:
self.data = pytz.utc.localize(
value,
is_dst=None
) # pylint: disable=locally-disabled,attribute-defined-outside-init
try:
self.data = pytz.utc.localize(
value,
is_dst=None
) # pylint: disable=locally-disabled,attribute-defined-outside-init
except (pytz.exceptions.NonExistentTimeError, pytz.exceptions.AmbiguousTimeError):
self.data = None # pylint: disable=locally-disabled,attribute-defined-outside-init
else:
self.data = None # pylint: disable=locally-disabled,attribute-defined-outside-init
......@@ -532,6 +538,12 @@ class SmartDateTimeField(wtforms.Field):
))
except ValueError:
self.data = None # pylint: disable=locally-disabled,attribute-defined-outside-init
except pytz.exceptions.AmbiguousTimeError:
self.data = localtz.localize(datetime.datetime.strptime(date_str, fmt), is_dst=False).astimezone(pytz.utc) # pylint: disable=locally-disabled,attribute-defined-outside-init
break
except pytz.exceptions.NonExistentTimeError:
self.data = localtz.localize(datetime.datetime.strptime(date_str, fmt), is_dst=True).astimezone(pytz.utc) # pylint: disable=locally-disabled,attribute-defined-outside-init
break
else:
break
# In case of failure try UTC ISO format (YYYY-MM-DDTHH:MM:SSZ).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment