Skip to content

Serialization of timedeltas should be consistent #4665

Closed as not planned
Closed as not planned
@nip3o

Description

@nip3o

When serializing a datetime.timedelta()as part of a JSON-object, it is serialized as the total number of seconds. Support for this was introduced in #584. When using a serializers.DurationField, it is serialized as a HH:MM:DD-like string, as introduced in #2989.

This can be quite troublesome on the client, since different API:s will have different behaviour depending on their implementation. In my specific use-case we transform the data from the API into moment.js duration objects, and depending on API implementation this currently has to be done in different ways.

I realize this would be a breaking change, but I think it is worth to discuss.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions