Skip to content

Commit

Permalink
Use ISO8601 format for dates #2714
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Jun 20, 2022
1 parent c3ab176 commit 1009920
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from flask import Flask, request
from . import CaseController, MongoStore
from reusable_data_service.util.iso_json_encoder import ISOJSONEncoder

import os
import logging

app = Flask(__name__)
app.json_encoder = ISOJSONEncoder

case_controller = None # Will be set up in main()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import flask.json
import datetime

class ISOJSONEncoder(flask.json.JSONEncoder):
def default(self, obj):
try:
if isinstance(obj, datetime.date):
return obj.isoformat()
iterable = iter(obj)
except TypeError:
pass
else:
return list(iterable)
return flask.json.JSONEncoder.default(self, obj)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_get_case_with_known_id(client_with_patched_mongo):
result = response.get_json()
assert response.status_code == 200
assert result is not None
assert result["confirmation_date"] == "Fri, 31 Dec 2021 00:00:00 GMT"
assert result["confirmation_date"] == "2021-12-31"


def test_get_case_with_poorly_formatted_id(client_with_patched_mongo):
Expand Down

0 comments on commit 1009920

Please sign in to comment.