marshmallow-code/marshmallow

fields.DateTime - load/dump to timestamp

Open

#612 geöffnet am 16. Apr. 2017

Auf GitHub ansehen
 (21 Kommentare) (18 Reaktionen) (0 zugewiesene Personen)Python (640 Forks)batch import
datetimehelp wanted

Repository-Metriken

Stars
 (6.787 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 4h 13m) (6 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide