# This Python file uses the following encoding: utf-8
from datetime import datetime
import jalali

def jalali_converter(gourg_date):
    str_gourg_date = "%s-%s-%s" % (gourg_date.year, gourg_date.month, gourg_date.day)
    jalai_date = jalali.Gregorian(str_gourg_date)
    persian_date = PersianDate(day=jalai_date.persian_day,
                               month=jalai_date.persian_month,
                               year=jalai_date.persian_year,
                               time=gourg_date.time())
    return persian_date


class PersianDate:
    def __init__(self, day, month, year, time):
        self.day = day
        self.month = month
        self.year = year
        self.time = time


def now():
    gourg_date = datetime.now()
    return jalali_converter(gourg_date)

def get_month_name(number):
    if number>12 or number<1:
        raise "not valid month!"

    persian_months = ['فروردین', 'اردیبهشت', 'خرداد',
                      'تیر', 'مرداد', 'شهریور',
                      'مهر', 'آبان', 'آذر',
                      'دی', 'بهمن', 'اسفند']
    return persian_months[number-1]


def get_time(date):
    try:
        hour = date.time.hour
        minute = date.time.minute
    except:
        raise "invalid date!"

    return '%s:%s' % (hour, minute)

def is_valid_time(time):
    try:
        index = time.find(':')
        hour = int(time[0:index])
        minute = int(time[index+1:])
        if isinstance(hour, int) and isinstance(minute, int) and 0 <= hour < 24 and 0 <= minute < 60:
            return True
        return False
    except:
        return False


print(is_valid_time('21:00'))