def __init__(self, *args): super(FinanceQuarter, self).__init__() self.quarter = None self.quarter_str = None # import pdb; pdb.set_trace() try: if len(args) == 1: if isinstance(args[0], str): mobj = CMN_FUNC.check_quarter_str_format(args[0]) self.setup_year_value(mobj.group(1)) # self.year = mobj.group(1) self.quarter = int(mobj.group(2)) elif isinstance(args[0], datetime): self.setup_year_value(args[0].year) # self.year = args[0].year self.quarter = (int)(math.ceil(args[0].month / 3.0)) else: raise elif len(args) == 2: for index in range(2): if type(args[index]) is not int: raise self.year = args[0] self.quarter = args[1] else: raise except Exception: raise ValueError("Unknown argument in FormatQuarter format: %s" % args) # Check value Range FinanceQuarter.check_value_range(self.year, self.quarter)
def from_string(time_string): if CMN_FUNC.check_date_str_format(time_string): return FinanceDate.from_string(time_string) elif CMN_FUNC.check_month_str_format(time_string): return FinanceMonth.from_string(time_string) elif CMN_FUNC.check_quarter_str_format(time_string): return FinanceQuarter.from_string(time_string) else: ValueError("Unknown time format: %s" % time_string)