# Path: graphene_django_extras/directives/base.py
# class BaseExtraGraphQLDirective(GraphQLDirective):
#     def __init__(self):
#         registry = get_global_registry()
#         super(BaseExtraGraphQLDirective, self).__init__(
#             name=self.get_name(),
#             description=self.__doc__,
#             args=self.get_args(),
#             locations=[
#                 DirectiveLocation.FIELD,
#                 DirectiveLocation.FRAGMENT_SPREAD,
#                 DirectiveLocation.INLINE_FRAGMENT,
#             ],
#         )
#         registry.register_directive(self.get_name(), self)
# 
#     @classmethod
#     def get_name(cls):
#         return to_snake_case(cls.__name__.replace("GraphQLDirective", ""))
# 
#     @staticmethod
#     def get_args():
#         return {}
# 
# Path: graphene_django_extras/base_types.py
# class CustomDateFormat(object):
#     def __init__(self, date):
#         self.date_str = date


import time as t
import six
from datetime import date, datetime, timedelta, time
from dateutil import parser, relativedelta
from django.utils import timezone
from graphql import GraphQLArgument, GraphQLString
from .base import BaseExtraGraphQLDirective
from ..base_types import CustomDateFormat


class DateGraphQLDirective(BaseExtraGraphQLDirective):
    """
    Format the date from resolving the field by dateutil module.
    """

    @staticmethod
    def get_args():
        return {
            "format": GraphQLArgument(
                GraphQLString, description="A format given by dateutil module"
            )
        }

    @staticmethod
    def resolve(value, directive, root, info, **kwargs):
        format_argument = [
            arg for arg in directive.arguments if arg.name.value == "format"
        ]
        format_argument = format_argument[0] if len(format_argument) > 0 else None

        custom_format = format_argument.value.value if format_argument else "default"
        dt = _parse(value)
        try:
            result = _format_dt(dt, custom_format)
            if isinstance(value, six.string_types):
                return result or value
            return CustomDateFormat(result or "INVALID FORMAT STRING")
        except ValueError:

# Path: graphene_django_extras/directives/base.py
# class BaseExtraGraphQLDirective(GraphQLDirective):
#     def __init__(self):
#         registry = get_global_registry()
#         super(BaseExtraGraphQLDirective, self).__init__(
#             name=self.get_name(),
#             description=self.__doc__,
#             args=self.get_args(),
#             locations=[
#                 DirectiveLocation.FIELD,
#                 DirectiveLocation.FRAGMENT_SPREAD,
#                 DirectiveLocation.INLINE_FRAGMENT,
#             ],
#         )
#         registry.register_directive(self.get_name(), self)
# 
#     @classmethod
#     def get_name(cls):
#         return to_snake_case(cls.__name__.replace("GraphQLDirective", ""))
# 
#     @staticmethod
#     def get_args():
#         return {}
# 
# Path: graphene_django_extras/base_types.py
# class CustomDateFormat(object):
#     def __init__(self, date):
#         self.date_str = date


# Path: graphene_django_extras/directives/date.py
import time as t
import six
from datetime import date, datetime, timedelta, time
from dateutil import parser, relativedelta
from django.utils import timezone
from graphql import GraphQLArgument, GraphQLString
from .base import BaseExtraGraphQLDirective
from ..base_types import CustomDateFormat



class DateGraphQLDirective(BaseExtraGraphQLDirective):
    """
    Format the date from resolving the field by dateutil module.
    """

    @staticmethod
    def get_args():
        return {
            "format": GraphQLArgument(
                GraphQLString, description="A format given by dateutil module"
            )
        }

    @staticmethod
    def resolve(value, directive, root, info, **kwargs):
        format_argument = [
            arg for arg in directive.arguments if arg.name.value == "format"
        ]
        format_argument = format_argument[0] if len(format_argument) > 0 else None

        custom_format = format_argument.value.value if format_argument else "default"
        dt = _parse(value)
        try:
            result = _format_dt(dt, custom_format)
            if isinstance(value, six.string_types):
                return result or value
            return CustomDateFormat(result or "INVALID FORMAT STRING")
        except ValueError:

            return CustomDateFormat("INVALID FORMAT STRING")