Use aniso8601 instead of iso8601

This commit is contained in:
Syrus Akbary 2018-03-29 22:05:12 -07:00
parent 3ee94131ae
commit b4255e55fd
2 changed files with 5 additions and 13 deletions

View File

@ -3,17 +3,10 @@ from __future__ import absolute_import
import datetime
from graphql.language import ast
from aniso8601 import parse_datetime, parse_date, parse_time
from .scalars import Scalar
try:
import iso8601
except ImportError:
raise ImportError(
"iso8601 package is required for DateTime Scalar.\n"
"You can install it using: pip install iso8601."
)
class Date(Scalar):
'''
@ -38,7 +31,7 @@ class Date(Scalar):
@staticmethod
def parse_value(value):
return iso8601.parse_date(value).date()
return parse_date(value)
class DateTime(Scalar):
@ -62,7 +55,7 @@ class DateTime(Scalar):
@staticmethod
def parse_value(value):
return iso8601.parse_date(value)
return parse_datetime(value)
class Time(Scalar):
@ -71,7 +64,6 @@ class Time(Scalar):
specified by
[iso8601](https://en.wikipedia.org/wiki/ISO_8601).
'''
epoch_date = '1970-01-01'
@staticmethod
def serialize(time):
@ -87,5 +79,4 @@ class Time(Scalar):
@classmethod
def parse_value(cls, value):
dt = iso8601.parse_date('{}T{}'.format(cls.epoch_date, value))
return datetime.time(dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
return parse_time(value)

View File

@ -90,6 +90,7 @@ setup(
'graphql-core>=2.0,<3',
'graphql-relay>=0.4.5,<1',
'promise>=2.1,<3',
'aniso8601>=3,<4',
],
tests_require=tests_require,
extras_require={