Skip to content

Commit 78cf590

Browse files
authored
Merge pull request #99 from domenkozar/date-time-rfc3339
openapi 3.0 defines date-time format to be rfc3339
2 parents 2e6f2de + 114ab79 commit 78cf590

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

openapi_core/schema/schemas/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from distutils.util import strtobool
44
from json import dumps
55
from six import string_types
6+
import strict_rfc3339
67

78

89
def forcebool(val):
@@ -21,4 +22,5 @@ def format_date(value):
2122

2223

2324
def format_datetime(value):
24-
return datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S')
25+
timestamp = strict_rfc3339.rfc3339_to_timestamp(value)
26+
return datetime.datetime.fromtimestamp(timestamp)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
openapi-spec-validator
22
six
33
lazy-object-proxy
4+
strict_rfc3339
45
attrs

requirements_2.7.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ lazy-object-proxy
44
backports.functools-lru-cache
55
backports.functools-partialmethod
66
enum34
7+
strict_rfc3339
78
attrs

tests/unit/schema/test_schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ def test_string_format_date(self):
8181

8282
def test_string_format_datetime(self):
8383
schema = Schema('string', schema_format='date-time')
84-
value = '2018-01-02T00:00:00'
84+
value = '2018-01-02T00:00:00Z'
8585

8686
result = schema.unmarshal(value)
8787

88-
assert result == datetime.datetime(2018, 1, 2, 0, 0, 0)
88+
assert result == datetime.datetime(2018, 1, 2, 0, 0)
8989

9090
@pytest.mark.xfail(reason="No custom formats support atm")
9191
def test_string_format_custom(self):

0 commit comments

Comments
 (0)