-
Notifications
You must be signed in to change notification settings - Fork 3k
[Core] Follow RFC 3339 datetime formatting for AzureJSONEncoder #20346
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,8 +105,11 @@ def default(self, o): # pylint: disable=too-many-return-statements | |
if hasattr(o, "year") and hasattr(o, "hour"): | ||
# astimezone() fails for naive times in Python 2.7, so make make sure o is aware (tzinfo is set) | ||
if not o.tzinfo: | ||
return o.replace(tzinfo=TZ_UTC).isoformat() | ||
return o.astimezone(TZ_UTC).isoformat() | ||
iso_formatted = o.replace(tzinfo=TZ_UTC).isoformat() | ||
else: | ||
iso_formatted = o.astimezone(TZ_UTC).isoformat() | ||
# Replace the trailing "+00:00" UTC offset with "Z" (RFC 3339: https://www.ietf.org/rfc/rfc3339.txt) | ||
return iso_formatted.replace("+00:00", "Z") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is I think tangential to this specific PR, but I was looking into the msrest rfc serialization and we don't currently support that. Is this something I want to add? msrest serialize rfc output: serialize_rfc(isodate.parse_datetime("0001-01-01T00:00:00Z")) == 'Mon, 01 Jan 0001 00:00:00 GMT' azure.core.serialization json.dumps(isodate.parse_datetime("0001-01-01T00:00:00Z"), cls=AzureJSONEncoder) == "0001-01-01T00:00:00Z" cc @lmazuel There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clear, your question has indeed mothing to do with @mccoyp 's PR :p . But yes, we could think about having a RFC HTTP header format serializer (not same RFC than here) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mccoyp i'm totally wrong here please ignore me |
||
# Next try datetime.date or datetime.time | ||
return o.isoformat() | ||
except AttributeError: | ||
|
Uh oh!
There was an error while loading. Please reload this page.