#37108: DjangoJSONEncoder encodes time inconsistently depending on microseconds
--------------------------------------+------------------------------------
Reporter: Roman Donchenko | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):
* stage: Unreviewed => Accepted
* type: Uncategorized => Cleanup/optimization
Comment:
I think we should always omit `.000`, something like:
{{{#!diff
diff --git a/django/core/serializers/json.py
b/django/core/serializers/json.py
index b955939e0d..1cf24a1211 100644
--- a/django/core/serializers/json.py
+++ b/django/core/serializers/json.py
@@ -90,9 +90,8 @@ class DjangoJSONEncoder(json.JSONEncoder):
def default(self, o):
# See "Date Time String Format" in the ECMA-262 specification.
if isinstance(o, datetime.datetime):
- r = o.isoformat()
- if o.microsecond:
- r = r[:23] + r[26:]
+ r = o.isoformat(sep="T", timespec="milliseconds")
+ r = r.replace(".000", "")
if r.endswith("+00:00"):
r = r.removesuffix("+00:00") + "Z"
}}}
This is a slight breaking change and so I would recommend a release note
--
Ticket URL: <https://code.djangoproject.com/ticket/37108#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019e4a36119c-c716b0f3-84e5-4503-b0b6-d3160a6f583b-000000%40eu-central-1.amazonses.com.