def navigate(tp): start = PharaonicDateTime.from_time(curret_period.start_time) end = PharaonicDateTime.from_time(curret_period.end_time) start_months = start.year * 13 + start.month end_months = end.year * 13 + 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 > PharaonicTimeType().get_max_time(): raise ValueError() if start < PharaonicTimeType().get_min_time(): raise ValueError() except ValueError: if direction < 0: raise TimeOutOfRangeLeftError() else: raise TimeOutOfRangeRightError() return tp.update(start, end)
def _whole_number_of_months(period): """ >>> from timelinelib.test.utils import gregorian_period >>> _whole_number_of_months(gregorian_period("24 May 490", "23 Jun 490")) True >>> _whole_number_of_months(gregorian_period("16 Aug 1", "21 Aug 1 ")) True >>> _whole_number_of_months(gregorian_period("2 Jan 2013", "2 Mar 2014")) False >>> _whole_number_of_months(gregorian_period("1 Jan 2013 12:00", "1 Mar 2014")) False """ start, end = PharaonicDateTime.from_time(period.start_time), PharaonicDateTime.from_time(period.end_time) start_months = start.year * 13 + start.month end_months = end.year * 13 + end.month month_diff = end_months - start_months return (start.is_first_of_month() and end.is_first_of_month() and month_diff > 0)
def time_to_wx_date(self, time): year, month, day = PharaonicDateTime.from_time(time).to_date_tuple() try: return wx.DateTime.FromDMY(day, month - 1, year, 0, 0, 0) except OverflowError: if year < 0: year, month, day = PharaonicDateTime.from_time( PharaonicTime(0, 0)).to_date_tuple() return wx.DateTime.FromDMY(day, month - 1, year, 0, 0, 0)
def set_value(self, time): if time is None: time = self.now_fn() self.date_picker.SetPharaonicDate( PharaonicDateTime.from_time(time).to_date_tuple()) self.time_picker.SetPharaonicTime( PharaonicDateTime.from_time(time).to_time_tuple()) if self.on_change is not None: self.on_change()
def label(self, time, major=False): day_of_week = PharaonicTimeType().get_day_of_week(time) if major: time = PharaonicDateTime.from_time(time) return "%s %s %s %s" % ( abbreviated_name_of_weekday(day_of_week), time.day, abbreviated_name_of_month(time.month), format_year(time.year)) return (abbreviated_name_of_weekday(day_of_week) + " %s" % PharaonicDateTime.from_time(time).day)
def move_period_num_years(period, num): try: delta = num start_year = PharaonicDateTime.from_time(period.start_time).year end_year = PharaonicDateTime.from_time(period.end_time).year start_time = PharaonicDateTime.from_time(period.start_time).replace(year=start_year + delta) end_time = PharaonicDateTime.from_time(period.end_time).replace(year=end_year + delta) return TimePeriod(start_time.to_time(), end_time.to_time()) except ValueError: return None
def _time_range_string(self, start, end): start = PharaonicDateTime.from_time(start) end = PharaonicDateTime.from_time(end) if start.year == end.year: if start.month == end.month: return "%s-%s %s %s" % (start.day, end.day, abbreviated_name_of_month(start.month), format_year(start.year)) return "%s %s-%s %s %s" % ( start.day, abbreviated_name_of_month(start.month), end.day, abbreviated_name_of_month(end.month), format_year(start.year)) return "%s %s %s-%s %s %s" % ( start.day, abbreviated_name_of_month( start.month), format_year(start.year), end.day, abbreviated_name_of_month(end.month), format_year(end.year))
def label(self, time, major=False): time = PharaonicDateTime.from_time(time) if major: return "%s %s %s" % (time.day, abbreviated_name_of_month(time.month), format_year(time.year)) return str(time.day)
def start(self, time): pharaonic_time = PharaonicDateTime.from_time(time) return PharaonicDateTime.from_ymd( pharaonic_time.year, pharaonic_time.month, pharaonic_time.day ).to_time()
def increment_year(self, date): max_year = PharaonicDateTime.from_time( PharaonicTimeType().get_max_time()).year year, month, day = date if year < max_year - 1: return self._set_valid_day(year + 1, month, day) return date
def label_without_time(time): pharaonic_datetime = PharaonicDateTime.from_time(time) return "%s %s %s" % ( pharaonic_datetime.day, abbreviated_name_of_month(pharaonic_datetime.month), format_year(pharaonic_datetime.year) )
def increment_day(self, date): year, month, day = date time = PharaonicDateTime.from_ymd(year, month, day).to_time() if time < PharaonicTimeType().get_max_time( ) - PharaonicDelta.from_days(1): return PharaonicDateTime.from_time( time + PharaonicDelta.from_days(1)).to_date_tuple() return date
def decrement_month(self, date): year, month, day = date if month > 1: return self._set_valid_day(year, month - 1, day) elif year > PharaonicDateTime.from_time( PharaonicTimeType().get_min_time()).year: return self._set_valid_day(year - 1, 13, day) return date
def fit_week_fn(main_frame, current_period, navigation_fn): mean = PharaonicDateTime.from_time(current_period.mean_time()) start = PharaonicDateTime.from_ymd(mean.year, mean.month, mean.day).to_time() weekday = PharaonicTimeType().get_day_of_week(start) start = start - PharaonicDelta.from_days(weekday) if not main_frame.week_starts_on_monday(): start = start - PharaonicDelta.from_days(1) end = start + PharaonicDelta.from_days(10) navigation_fn(lambda tp: tp.update(start, end))
def fit_millennium_fn(main_frame, current_period, navigation_fn): mean = PharaonicDateTime.from_time(current_period.mean_time()) if mean.year > get_millenium_max_year(): year = get_millenium_max_year() else: year = max(get_min_year_containing_jan_1(), int(mean.year // 1000) * 1000) start = PharaonicDateTime.from_ymd(year, 1, 1).to_time() end = PharaonicDateTime.from_ymd(year + 1000, 1, 1).to_time() navigation_fn(lambda tp: tp.update(start, end))
def label(self, time, major=False): if major: pharaonic_time = PharaonicDateTime.from_time(time) return self._format_century( self._century_number( self._century_start_year(pharaonic_time.year)), pharaonic_time.is_bc()) else: return ""
def _whole_number_of_years(period): """ >>> from timelinelib.test.utils import gregorian_period >>> _whole_number_of_years(gregorian_period("13 Jun 287", "12 Jun 288")) True >>> _whole_number_of_years(gregorian_period("24 Apr 490", "24 Apr 491")) True >>> _whole_number_of_years(gregorian_period("8 Dec 1776", "8 Dec 1777")) False >>> _whole_number_of_years(gregorian_period("6 Sep 2013", "11 Sep 2014")) False """ return (PharaonicDateTime.from_time(period.start_time).is_first_day_in_year() and PharaonicDateTime.from_time(period.end_time).is_first_day_in_year() and _calculate_year_diff(period) > 0)
def navigate(tp): year_delta = direction * _calculate_year_diff(curret_period) pharaonic_start = PharaonicDateTime.from_time(curret_period.start_time) pharaonic_end = PharaonicDateTime.from_time(curret_period.end_time) new_start_year = pharaonic_start.year + year_delta new_end_year = pharaonic_end.year + year_delta try: new_start = pharaonic_start.replace(year=new_start_year).to_time() new_end = pharaonic_end.replace(year=new_end_year).to_time() if new_end > PharaonicTimeType().get_max_time(): raise ValueError() if new_start < PharaonicTimeType().get_min_time(): raise ValueError() except ValueError: if direction < 0: raise TimeOutOfRangeLeftError() else: raise TimeOutOfRangeRightError() return tp.update(new_start, new_end)
def move_time(time): pharaonic_time = PharaonicDateTime.from_time(time) new_month = pharaonic_time.month + num new_year = pharaonic_time.year while new_month < 1: new_month += 13 new_year -= 1 while new_month > 13: new_month -= 13 new_year += 1 return pharaonic_time.replace(year=new_year, month=new_month).to_time()
def navigate_month_step(current_period, navigation_fn, direction): # TODO: NEW-TIME: (year, month, day, hour, minute, second) -> int (days in # month) tm = current_period.mean_time() pt = PharaonicDateTime.from_time(tm) if pt.month == 13: d = 5 d = 30 mv = PharaonicDelta.from_days(d) navigation_fn(lambda tp: tp.move_delta(direction * mv))
def label(self, time, major=False): if major: first_weekday = self.start(time) next_first_weekday = self.increment(first_weekday) last_weekday = next_first_weekday - PharaonicDelta.from_days(1) range_string = self._time_range_string(first_weekday, last_weekday) if self.appearance.get_week_start() == "tkyriaka": return (_("Week") + " %s (%s)") % (PharaonicDateTime.from_time( time).week_number, range_string) else: # It is Psabbaton (don't know what to do about week numbers here) return range_string # This strip should never be used as minor return ""
def increment(self, time): return time + PharaonicDelta.from_days( PharaonicDateTime.from_time(time).days_in_month() )
def increment(self, time): pharaonic_time = PharaonicDateTime.from_time(time) return pharaonic_time.replace(year=pharaonic_time.year + 1).to_time()
def start(self, time): pharaonic_time = PharaonicDateTime.from_time(time) new_pharaonic = PharaonicDateTime.from_ymd(pharaonic_time.year, 1, 1) return new_pharaonic.to_time()
def increment(self, time): pharaonic_time = PharaonicDateTime.from_time(time) return pharaonic_time.replace( year=self._next_decacde_start_year(pharaonic_time.year) ).to_time()
def start(self, time): return PharaonicDateTime.from_ymd( self._decade_start_year(PharaonicDateTime.from_time(time).year), 1, 1 ).to_time()
def label(self, time, major=False): pharaonic_time = PharaonicDateTime.from_time(time) return self._format_decade( self._decade_number(self._decade_start_year(pharaonic_time.year)), pharaonic_time.is_bc() )
def time_string(self, time): return "%d-%02d-%02d %02d:%02d:%02d" % PharaonicDateTime.from_time(time).to_tuple()
def get_millenium_max_year(): return PharaonicDateTime.from_time(PharaonicTimeType().get_max_time()).year - 1000
def label(self, time, major=False): return format_year(PharaonicDateTime.from_time(time).year)