File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 1
- import datetime
2
1
import json
2
+ import iso8601
3
3
4
4
from graphql .core .language import ast
5
5
@@ -33,9 +33,8 @@ def serialize(dt):
33
33
@staticmethod
34
34
def parse_literal (node ):
35
35
if isinstance (node , ast .StringValue ):
36
- return datetime .datetime .strptime (
37
- node .value , "%Y-%m-%dT%H:%M:%S.%f" )
36
+ return iso8601 .parse_date (node .value )
38
37
39
38
@staticmethod
40
39
def parse_value (value ):
41
- return datetime . datetime . strptime (value , "%Y-%m-%dT%H:%M:%S.%f" )
40
+ return iso8601 . parse_date (value )
Original file line number Diff line number Diff line change
1
+ import iso8601
2
+
3
+ from graphql .core .language .ast import StringValue
4
+
5
+ from ..custom_scalars import DateTime
6
+
7
+
8
+ def test_date_time ():
9
+ test_iso_string = "2016-04-29T18:34:12.502Z"
10
+
11
+ def check_datetime (test_dt ):
12
+ assert test_dt .tzinfo == iso8601 .UTC
13
+ assert test_dt .year == 2016
14
+ assert test_dt .month == 4
15
+ assert test_dt .day == 29
16
+ assert test_dt .hour == 18
17
+ assert test_dt .minute == 34
18
+ assert test_dt .second == 12
19
+
20
+ test_dt = DateTime ().parse_value (test_iso_string )
21
+ check_datetime (test_dt )
22
+
23
+ assert DateTime .serialize (test_dt ) == "2016-04-29T18:34:12.502000+00:00"
24
+
25
+ node = StringValue (test_iso_string )
26
+ test_dt = DateTime .parse_literal (node )
27
+ check_datetime (test_dt )
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ def run_tests(self):
57
57
'six>=1.10.0' ,
58
58
'graphql-core>=0.4.9' ,
59
59
'graphql-relay==0.3.3' ,
60
+ 'iso8601' ,
60
61
],
61
62
tests_require = [
62
63
'django-filter>=0.10.0' ,
You can’t perform that action at this time.
0 commit comments