marshmallow-code/marshmallow

fields.DateTime - load/dump to timestamp

クローズ

#612 opened on 2017/04/16

 (21 件のコメント) (18 件のリアクション) (0 人の担当者)Python (640 件のフォーク)batch import
datetimehelp wanted

Repository metrics

Stars
 (6,787 個のスター)
PR merge metrics
 (平均マージ 10h 55m) (30d で 7 merged PRs)

説明

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

コントリビューターガイド