Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On load, create timezone-aware datetime objects if possible #113

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib3/yaml/constructor.py
Expand Up @@ -330,9 +330,15 @@ def construct_yaml_timestamp(self, node):
delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute)
if values['tz_sign'] == '-':
delta = -delta
data = datetime.datetime(year, month, day, hour, minute, second, fraction)
if delta:
data -= delta
data = None
# If we are correcting to UTC, we can make the datetime object
# timezone-aware
if delta is not None:
data = datetime.datetime(year, month, day, hour, minute, second, fraction, datetime.timezone.utc)
if delta:
data -= delta
else:
data = datetime.datetime(year, month, day, hour, minute, second, fraction)
return data

def construct_yaml_omap(self, node):
Expand Down