Opened 8 years ago

Closed 8 years ago

#26656 closed New feature (fixed)

Add timedelta support to DjangoJSONEncoder

Reported by: Will Hardy Owned by: nobody
Component: Core (Serialization) Version: 1.9
Severity: Normal Keywords:
Cc: Chesco Igual Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently DjangoJSONEncoder supports datetime, date, time, Decimal and UUID objects.

But when the DurationField was added recently, no support for timedelta was added to the JSON encoder.

Change History (10)

comment:1 by Tim Graham, 8 years ago

Component: UncategorizedCore (Serialization)
Type: UncategorizedNew feature

comment:2 by Will Hardy, 8 years ago

See another PR, using a ISO 8601 string instead of a float.

comment:3 by Tim Graham, 8 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

comment:4 by Chesco Igual, 8 years ago

Cc: Chesco Igual added
Triage Stage: AcceptedReady for checkin

I gave a look at the code, and seems to solve the problem. Adds support for ISO durations. Includes new tests which seem to cover most of the cases (replicates previous duration tests, with the new ISO format).

Only thing is I am not able to tell if the format should be included anywhere in the official docs of the serializers or if it's not necessary.

comment:5 by Tom Offermann, 8 years ago

Looks good! Reviewed as part of the Django sprint at PyCon.

tests.serializers.test_json:test_timedelta passes with the patch. It fails without the patch.

The new TestParseISODurationRoundtrip tests look good.

Does this need docs?

comment:6 by Will Hardy, 8 years ago

DjangoJSONEncoder does not seem to be documented at all. I've added an entry to the release notes, and will open another ticket for the whole class to be documented.

comment:7 by Will Hardy, 8 years ago

See #26704 for the DjangoJSONEncoder documentation ticket.

Last edited 8 years ago by Tim Graham (previous) (diff)

comment:8 by Tim Graham, 8 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Now that #26704 is committed, we can update those docs for these changes.

comment:9 by Tim Graham, 8 years ago

Patch needs improvement: unset

comment:10 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 8ef78b8:

Fixed #26656 -- Added duration (timedelta) support to DjangoJSONEncoder.

Note: See TracTickets for help on using tickets.
Back to Top