marshmallow-code/marshmallow

fields.DateTime - load/dump to timestamp

已关闭

#612 创建于 2017年4月16日

 (21 条评论) (18 个反应) (0 位负责人)Python (640 个派生)batch import
datetimehelp wanted

仓库指标

星标
 (6,787 个星标)
PR 合并指标
 (平均合并 10小时 55分钟) (30 天内合并 7 个 PR)

描述

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

贡献者指南