misc: add support for serializing times to json (#76021)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-03-31 12:58:08 +02:00
parent 6d11417ae3
commit f7c49be99d
2 changed files with 5 additions and 0 deletions

View File

@ -2411,6 +2411,7 @@ def test_webservice_with_complex_data(http_requests, pub):
'none': '{{ form_var_none }}',
'bool': '{{ form_var_bool_raw }}',
'attachment': '{{ form_attachments_testfile }}',
'time': '{{ "13:12"|time }}',
}
pub.substitutions.feed(formdata)
with get_publisher().complex_data():
@ -2442,6 +2443,7 @@ def test_webservice_with_complex_data(http_requests, pub):
'content_type': 'application/octet-stream',
'content': base64.b64encode(attachment_content).decode(),
},
'time': '13:12:00',
}
# check an empty boolean field is sent as False

View File

@ -616,6 +616,9 @@ class JSONEncoder(json.JSONEncoder):
if isinstance(o, datetime.date):
return o.strftime('%Y-%m-%d')
if isinstance(o, datetime.time):
return o.strftime('%H:%M:%S')
if isinstance(o, decimal.Decimal):
return localize(o)