From b4255e55fd28ca5b31f86876fe3f95f38f0f0838 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 29 Mar 2018 22:05:12 -0700 Subject: [PATCH 1/2] Use aniso8601 instead of iso8601 --- graphene/types/datetime.py | 17 ++++------------- setup.py | 1 + 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/graphene/types/datetime.py b/graphene/types/datetime.py index 3b0e3f13..5cc53258 100644 --- a/graphene/types/datetime.py +++ b/graphene/types/datetime.py @@ -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) diff --git a/setup.py b/setup.py index 52d7de0c..8b54d6d7 100644 --- a/setup.py +++ b/setup.py @@ -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={ From 50cd43c6e5c228439524f76338a9b75144d03b2c Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 29 Mar 2018 22:31:36 -0700 Subject: [PATCH 2/2] Added Date, DateTime and Time to global exports --- graphene/__init__.py | 4 ++++ graphene/types/__init__.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/graphene/__init__.py b/graphene/__init__.py index 0198043c..65253237 100644 --- a/graphene/__init__.py +++ b/graphene/__init__.py @@ -11,6 +11,7 @@ from .types import ( Schema, Scalar, String, ID, Int, Float, Boolean, + Date, DateTime, Time, JSONString, UUID, List, NonNull, @@ -54,6 +55,9 @@ __all__ = [ 'Float', 'Enum', 'Boolean', + 'Date', + 'DateTime', + 'Time', 'JSONString', 'UUID', 'List', diff --git a/graphene/types/__init__.py b/graphene/types/__init__.py index 2699740a..b5b9427c 100644 --- a/graphene/types/__init__.py +++ b/graphene/types/__init__.py @@ -5,6 +5,7 @@ from .objecttype import ObjectType from .interface import Interface from .mutation import Mutation from .scalars import Scalar, String, ID, Int, Float, Boolean +from .datetime import Date, DateTime, Time from .json import JSONString from .uuid import UUID from .schema import Schema @@ -36,6 +37,9 @@ __all__ = [ 'ID', 'Int', 'Float', + 'Date', + 'DateTime', + 'Time', 'JSONString', 'UUID', 'Boolean',