Md. Tanvir Raihan
Md. Tanvir Raihan

Reputation: 4285

how to check a given string is a timezone instance

how can i check a given string is a timezone instance , say i have argument value namely 'date' in a method, i want check it as a timezone instance or timezone aware instance before return it, i have trid the following, but it failed

def get_date(date=None):
   if not isinstance(date, timezone):
       raise ValidationError('please provide timezone aware date type value')

it shows the error,

TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types  

how can check a string value as timezone aware date instance?

Upvotes: 0

Views: 53

Answers (1)

Sergey Gornostaev
Sergey Gornostaev

Reputation: 7797

You can use is_aware or is_naive

from django.utils.timezone import is_aware
if not is_aware(date):
    raise ValidationError('please provide timezone aware date type value')

Upvotes: 1

Related Questions