#37108: DjangoJSONEncoder encodes time inconsistently depending on microseconds
-------------------------------------+-------------------------------------
Reporter: Roman Donchenko | Owner: (none)
Type: Uncategorized | Status: new
Component: Core | Version: 6.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Richard Autry):
To add some more information after looking into this, this behavior is due
to the truncation of microseconds which was added as part of the timezone
effort back in 2011:
https://github.com/django/django/commit/9b1cb755a28f020e27d4268c214b25315d4de42e
#diff-45e847dda304240b8c519e6b57aa635ae806341986b14e0f17367450f1cbe0e9R47
i.e.
{{{
>>> now.isoformat()[:23] + now.isoformat()[26:]
'2026-05-19T15:50:51.060'
}}}
When you specify a timestamp of 0.000001, it is be stepped down to the
logical ".000" you mentioned. However, whether or not microseconds is
included is a function of the standard `datetime` library and not the
actual `DjangoJSONEncoder`.
i.e.
{{{
>>> time().isoformat()
'00:00:00'
>>> time(microsecond=1).isoformat()
'00:00:00.000001'
}}}
I'm not sure `DjangoJSONEncoder` should be responsible for providing
default behavior that might override this.
--
Ticket URL: <https://code.djangoproject.com/ticket/37108#comment:1>
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/0107019e41d79ff3-4f6452ab-4485-4833-966d-3b8e9d34d630-000000%40eu-central-1.amazonses.com.