def fit_decade_fn(main_frame, current_period, navigation_fn): mean = BosparanianUtils.from_time(current_period.mean_time()) start = BosparanianUtils.from_date(int(mean.year / 10) * 10, 1, 1).to_time() end = BosparanianUtils.from_date(int(mean.year / 10) * 10 + 10, 1, 1).to_time() navigation_fn(lambda tp: tp.update(start, end))
def fit_month_fn(main_frame, current_period, navigation_fn): mean = BosparanianUtils.from_time(current_period.mean_time()) start = BosparanianUtils.from_date(mean.year, mean.month, 1).to_time() if mean.month == 13: end = BosparanianUtils.from_date(mean.year + 1, 1, 1).to_time() else: end = BosparanianUtils.from_date(mean.year, mean.month + 1, 1).to_time() navigation_fn(lambda tp: tp.update(start, end))
def fit_century_fn(main_frame, current_period, navigation_fn): mean = BosparanianUtils.from_time(current_period.mean_time()) if mean.year > get_century_max_year(): year = get_century_max_year() else: year = max(get_min_year_containing_praios_1(), int(mean.year / 100) * 100) start = BosparanianUtils.from_date(year, 1, 1).to_time() end = BosparanianUtils.from_date(year + 100, 1, 1).to_time() navigation_fn(lambda tp: tp.update(start, end))
def on_down(self): def decrement_year(date): year, month, day = date if year > BosparanianUtils.from_time( BosparanianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, month, day) return date def decrement_month(date): year, month, day = date if month > 1: return self._set_valid_day(year, month - 1, day) elif year > BosparanianUtils.from_time( BosparanianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 13, day) return date def decrement_day(date): year, month, day = date if day > 1: return self._set_valid_day(year, month, day - 1) elif month > 1: return self._set_valid_day(year, month - 1, 30) elif year > BosparanianUtils.from_time( BosparanianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 13, 5) return date if not self._current_date_is_valid(): return selection = self.date_picker.GetSelection() current_date = self.get_value() if self._insertion_point_in_region(self.region_year): new_date = decrement_year(current_date) elif self._insertion_point_in_region(self.region_month): new_date = decrement_month(current_date) else: year, month, day = current_date BosparanianUtils.from_date(year, month, day) if BosparanianUtils.from_date( year, month, day).to_time() == BosparanianTimeType().get_min_time()[0]: return new_date = decrement_day(current_date) self._save_preferred_day(new_date) if current_date != new_date: self._set_new_date_and_restore_selection(new_date, selection) self._on_change()
def start(self, time): q = self.get_quarter(time) if q == 0: m = 13 else: m = (q - 1) * 3 + 1 return BosparanianUtils.from_date( BosparanianUtils.from_time(time).year, m, 1).to_time()
def increment_day(date): year, month, day = date time = BosparanianUtils.from_date(year, month, day).to_time() if time < BosparanianTimeType().get_max_time( )[0] - delta_from_days(1): return BosparanianUtils.from_time( time + delta_from_days(1)).to_date_tuple() return date
def _set_valid_day(self, new_year, new_month, new_day): done = False while not done: try: date = BosparanianUtils.from_date(new_year, new_month, new_day) done = True except Exception: new_day -= 1 return date.to_date_tuple()
def _set_valid_day(self, new_year, new_month, new_day): done = False while not done: try: date = BosparanianUtils.from_date(new_year, new_month, new_day) done = True except Exception: new_day -= 1 return date.to_date_tuple()
def fit_week_fn(main_frame, current_period, navigation_fn): mean = BosparanianUtils.from_time(current_period.mean_time()) start = BosparanianUtils.from_date(mean.year, mean.month, mean.day).to_time() weekday = start.get_day_of_week() start = start - delta_from_days(weekday) if not main_frame.week_starts_on_monday(): start = start - delta_from_days(1) end = start + delta_from_days(7) navigation_fn(lambda tp: tp.update(start, end))
def on_down(self): def decrement_year(date): year, month, day = date if year > BosparanianUtils.from_time(BosparanianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, month, day) return date def decrement_month(date): year, month, day = date if month > 1: return self._set_valid_day(year, month - 1, day) elif year > BosparanianUtils.from_time(BosparanianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 13, day) return date def decrement_day(date): year, month, day = date if day > 1: return self._set_valid_day(year, month, day - 1) elif month > 1: return self._set_valid_day(year, month - 1, 30) elif year > BosparanianUtils.from_time(BosparanianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 13, 5) return date if not self._current_date_is_valid(): return selection = self.date_picker.GetSelection() current_date = self.get_value() if self._insertion_point_in_region(self.region_year): new_date = decrement_year(current_date) elif self._insertion_point_in_region(self.region_month): new_date = decrement_month(current_date) else: year, month, day = current_date BosparanianUtils.from_date(year, month, day) if BosparanianUtils.from_date(year, month, day).to_time() == BosparanianTimeType().get_min_time()[0]: return new_date = decrement_day(current_date) self._save_preferred_day(new_date) if current_date != new_date: self._set_new_date_and_restore_selection(new_date, selection) self._on_change()
def start(self, time): bosparanian_time = BosparanianUtils.from_time(time) new_bosparanian = BosparanianUtils.from_date(bosparanian_time.year, bosparanian_time.month, bosparanian_time.day) return new_bosparanian.to_time()
def start(self, time): bosparanian_time = BosparanianUtils.from_time(time) new_bosparanian = BosparanianUtils.from_date( self._decade_start_year(bosparanian_time.year), 1, 1) return new_bosparanian.to_time()
def start(self, time): time = BosparanianUtils.from_time(time) return BosparanianUtils.from_date(self._century_start_year(time.year), 1, 1).to_time()
def fit_day_fn(main_frame, current_period, navigation_fn): mean = BosparanianUtils.from_time(current_period.mean_time()) start = BosparanianUtils.from_date(mean.year, mean.month, mean.day).to_time() end = start + delta_from_days(1) navigation_fn(lambda tp: tp.update(start, end))
def increment_day(date): year, month, day = date time = BosparanianUtils.from_date(year, month, day).to_time() if time < BosparanianTimeType().get_max_time()[0] - delta_from_days(1): return BosparanianUtils.from_time(time + delta_from_days(1)).to_date_tuple() return date