marshmallow-code/marshmallow

fields.DateTime - load/dump to timestamp

Fechada

#612 aberto em 16 de abr. de 2017

 (21 comentários) (18 reações) (0 responsável)Python (640 forks)batch import
datetimehelp wanted

Métricas do repositório

Stars
 (6.787 estrelas)
Métricas de merge de PR
 (Mesclagem média 10h 55m) (7 fundiu PRs em 30d)

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

Guia do colaborador