Skip to content

Commit

Permalink
JSONEncoder增加timedelta类型
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Jul 31, 2018
1 parent 41461df commit 843fb61
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sql/extend_json_encoder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: UTF-8 -*-
import simplejson as json

from datetime import datetime, date
from datetime import datetime, date, timedelta
from decimal import Decimal
from functools import singledispatch

Expand Down Expand Up @@ -36,6 +36,10 @@ def _(o):
return o.strftime('%Y-%m-%d')


@convert.register(timedelta)
def _(o):
return o.total_seconds()

# @convert.register(Decimal)
# def _(o):
# return float(o)
Expand All @@ -59,7 +63,9 @@ def default(self, obj):
'dm': dm,
'dt': dt,
'dat': dat,
'tl': timedelta(minutes=30),
'bigint': 988983860501598208
}

#print(json.dumps(data, cls=ExtendJSONEncoder, bigint_as_string=True))
# print(json.dumps(data, cls=ExtendJSONEncoder, bigint_as_string=True))
# print(json.dumps(data, cls=ExtendJSONEncoder, bigint_as_string=True, default=str))

0 comments on commit 843fb61

Please sign in to comment.