import datetime


class GmtOffset:
    """The format of the GMT offset is - '(GMT<sign>hh:mm)'"""

    def __init__(self, sign = None, hour = None, minute=None):
        self.sign = sign
        self.hour = hour
        self.minutes = minute

    @staticmethod
    def parse_str(offset_str):
        returned_gmt_offset = GmtOffset()
        returned_gmt_offset.sign = offset_str[4:5]
        returned_gmt_offset.hour = offset_str[5:7]
        returned_gmt_offset.minutes = offset_str[8:10]
        returned_gmt_offset.validate_params()
        return  returned_gmt_offset

    def read_from_line(self, offset):
        self.sign = offset[4:5]
        self.hour = offset[5:7]
        self.minutes = offset[8:10]

        self.validate_params()

    def validate_params(self):
        # If no exception, time is valid.
        time = datetime.time(int(self.hour), int(self.minutes))
