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

貢獻者指南