Example #1
0
 def navigate(tp):
     start = GregorianDateTime.from_time(curret_period.start_time)
     end = GregorianDateTime.from_time(curret_period.end_time)
     start_months = start.year * 12 + start.month
     end_months = end.year * 12 + end.month
     month_diff = end_months - start_months
     month_delta = month_diff * direction
     new_start_year, new_start_month = _months_to_year_and_month(
         start_months + month_delta)
     new_end_year, new_end_month = _months_to_year_and_month(end_months +
                                                             month_delta)
     try:
         new_start = start.replace(year=new_start_year,
                                   month=new_start_month)
         new_end = end.replace(year=new_end_year, month=new_end_month)
         start = new_start.to_time()
         end = new_end.to_time()
         if end > GregorianTimeType().get_max_time():
             raise ValueError()
         if start < GregorianTimeType().get_min_time():
             raise ValueError()
     except ValueError:
         if direction < 0:
             raise TimeOutOfRangeLeftError()
         else:
             raise TimeOutOfRangeRightError()
     return tp.update(start, end)
Example #2
0
 def navigate(tp):
     year_delta = direction * _calculate_year_diff(curret_period)
     gregorian_start = GregorianDateTime.from_time(curret_period.start_time)
     gregorian_end = GregorianDateTime.from_time(curret_period.end_time)
     new_start_year = gregorian_start.year + year_delta
     new_end_year = gregorian_end.year + year_delta
     try:
         new_start = gregorian_start.replace(year=new_start_year).to_time()
         new_end = gregorian_end.replace(year=new_end_year).to_time()
         if new_end > GregorianTimeType().get_max_time():
             raise ValueError()
         if new_start < GregorianTimeType().get_min_time():
             raise ValueError()
     except ValueError:
         if direction < 0:
             raise TimeOutOfRangeLeftError()
         else:
             raise TimeOutOfRangeRightError()
     return tp.update(new_start, new_end)