File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1
1
import datetime
2
2
import json
3
+ import iso8601
3
4
4
5
from graphql .core .language import ast
5
6
@@ -33,9 +34,8 @@ def serialize(dt):
33
34
@staticmethod
34
35
def parse_literal (node ):
35
36
if isinstance (node , ast .StringValue ):
36
- return datetime .datetime .strptime (
37
- node .value , "%Y-%m-%dT%H:%M:%S.%f" )
37
+ return iso8601 .parse_date (node .value )
38
38
39
39
@staticmethod
40
40
def parse_value (value ):
41
- return datetime . datetime . strptime (value , "%Y-%m-%dT%H:%M:%S.%f" )
41
+ 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
+ def test_date_time ():
8
+ test_iso_string = "2016-04-29T18:34:12.502Z"
9
+
10
+ def check_datetime (test_dt ):
11
+ assert test_dt .tzinfo == iso8601 .UTC
12
+ assert test_dt .year == 2016
13
+ assert test_dt .month == 04
14
+ assert test_dt .day == 29
15
+ assert test_dt .hour == 18
16
+ assert test_dt .minute == 34
17
+ assert test_dt .second == 12
18
+
19
+ test_dt = DateTime ().parse_value (test_iso_string )
20
+ check_datetime (test_dt )
21
+
22
+ assert DateTime .serialize (test_dt ) == "2016-04-29T18:34:12.502000+00:00"
23
+
24
+ node = StringValue (test_iso_string )
25
+ test_dt = DateTime .parse_literal (node )
26
+ check_datetime (test_dt )
27
+
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==0.1.11' ,
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