marshmallow-code/marshmallow

fields.DateTime - load/dump to timestamp

Open

#612 ouverte le 16 avr. 2017

Voir sur GitHub
 (21 commentaires) (18 réactions) (0 assignés)Python (640 forks)batch import
datetimehelp wanted

Métriques du dépôt

Stars
 (6 787 stars)
Métriques de merge PR
 (Merge moyen 4h 13m) (6 PRs mergées en 30 j)

Description

I'm currently using this code to parse/dump timestamp, but I believe this should be in standard library. Should I create pull request, or have I missed another way to work with datetime/timestamp format?

class DateTime(ma.fields.DateTime):
    """
    Class extends marshmallow standart DateTime with "timestamp" format.
    """

    DATEFORMAT_SERIALIZATION_FUNCS = \
        ma.fields.DateTime.DATEFORMAT_SERIALIZATION_FUNCS.copy()
    DATEFORMAT_DESERIALIZATION_FUNCS = \
        ma.fields.DateTime.DATEFORMAT_DESERIALIZATION_FUNCS.copy()

    DATEFORMAT_SERIALIZATION_FUNCS['timestamp'] = lambda x: x.timestamp()
    DATEFORMAT_DESERIALIZATION_FUNCS['timestamp'] = datetime.fromtimestamp

Guide contributeur