def increment_day(self, date): year, month, day = date time = GregorianDateTime.from_ymd(year, month, day).to_time() if time < GregorianTimeType().get_max_time( ) - GregorianDelta.from_days(1): return GregorianDateTime.from_time( time + GregorianDelta.from_days(1)).to_date_tuple() return date
def fit_week_fn(main_frame, current_period, navigation_fn): mean = GregorianDateTime.from_time(current_period.mean_time()) start = GregorianDateTime.from_ymd(mean.year, mean.month, mean.day).to_time() weekday = GregorianTimeType().get_day_of_week(start) start = start - GregorianDelta.from_days(weekday) if not main_frame.week_starts_on_monday(): start = start - GregorianDelta.from_days(1) end = start + GregorianDelta.from_days(7) navigation_fn(lambda tp: tp.update(start, end))
def fit_week_fn(main_frame, current_period, navigation_fn): mean = GregorianDateTime.from_time(current_period.mean_time()) start = GregorianDateTime.from_ymd(mean.year, mean.month, mean.day).to_time() weekday = GregorianTimeType().get_day_of_week(start) start = start - GregorianDelta.from_days(weekday) if not main_frame.week_starts_on_monday(): start = start - GregorianDelta.from_days(1) end = start + GregorianDelta.from_days(7) navigation_fn(lambda tp: tp.update(start, end))
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 - GregorianDelta.from_days(1) range_string = self._time_range_string(first_weekday, last_weekday) if self.appearance.get_week_start() == "monday": return (_("Week") + " %s (%s)") % (GregorianDateTime.from_time( time).week_number, range_string) else: # It is sunday (don't know what to do about week numbers here) return range_string # This strip should never be used as minor return ""
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 - GregorianDelta.from_days(1) range_string = self._time_range_string(first_weekday, last_weekday) if self.appearance.get_week_start() == "monday": return (_("Week") + " %s (%s)") % ( GregorianDateTime.from_time(time).week_number, range_string ) else: # It is sunday (don't know what to do about week numbers here) return range_string # This strip should never be used as minor return ""
def navigate_month_step(current_period, navigation_fn, direction): """ Currently does notice leap years. """ # TODO: NEW-TIME: (year, month, day, hour, minute, second) -> int (days in # month) tm = current_period.mean_time() gt = GregorianDateTime.from_time(tm) if direction > 0: if gt.month == 2: d = 28 elif gt.month in (4, 6, 9, 11): d = 30 else: d = 31 else: if gt.month == 3: d = 28 elif gt.month in (5, 7, 10, 12): d = 30 else: d = 31 mv = GregorianDelta.from_days(d) navigation_fn(lambda tp: tp.move_delta(direction * mv))
def navigate_month_step(current_period, navigation_fn, direction): """ Currently does notice leap years. """ # TODO: NEW-TIME: (year, month, day, hour, minute, second) -> int (days in # month) tm = current_period.mean_time() gt = GregorianDateTime.from_time(tm) if direction > 0: if gt.month == 2: d = 28 elif gt.month in (4, 6, 9, 11): d = 30 else: d = 31 else: if gt.month == 3: d = 28 elif gt.month in (5, 7, 10, 12): d = 30 else: d = 31 mv = GregorianDelta.from_days(d) navigation_fn(lambda tp: tp.move_delta(direction * mv))
def get_default_time_period(self): return time_period_center(self.now(), GregorianDelta.from_days(30))
def move_period_num_weeks(period, num): delta = GregorianDelta.from_days(7) * num start_time = period.start_time + delta end_time = period.end_time + delta return TimePeriod(start_time, end_time)
def increment(self, time): return time + GregorianDelta.from_seconds(60)
def increment(self, time): return time + GregorianDelta.from_days(1)
def monday_week_1(year): from timelinelib.calendar.gregorian.timetype import GregorianTimeType jan_4 = GregorianDateTime.from_ymd(year, 1, 4).to_time() jan_4_day_of_week = GregorianTimeType().get_day_of_week(jan_4) return jan_4 - GregorianDelta.from_days(jan_4_day_of_week)
event.set_locked(True) else: event.set_ends_today(not event.get_ends_today()) return event EVENT_MODIFIERS = [ ("change fuzzy", lambda event: event.set_fuzzy(not event.get_fuzzy())), ("change locked", lambda event: event.set_locked(not event.get_locked())), ("change ends today", modifier_change_ends_today), ("change id", lambda event: event.set_id(inc(event.get_id()))), ("change time period", lambda event: event.set_time_period(event.get_time_period().move_delta(GregorianDelta.from_days(1)))), ("change text", lambda event: event.set_text("was: %s" % event.get_text())), ("change category", lambda event: event.set_category(new_cat(event))), ("change icon", lambda event: event.set_icon("was: %s" % event.get_icon())), ("change description", lambda event: event.set_description("was: %s" % event.get_description())), ("change hyperlink", lambda event: event.set_hyperlink("was: %s" % event.get_hyperlink())), ("change progress", lambda event: event.set_progress(new_progress(event))), ("change alert", lambda event: event.set_alert("was: %s" % event.get_alert())), ]
def backward_one_week_fn(main_frame, current_period, navigation_fn): wk = GregorianDelta.from_days(7) navigation_fn(lambda tp: tp.move_delta(-1 * wk))
if event.get_locked(): event.set_locked(False) event.set_ends_today(not event.get_ends_today()) event.set_locked(True) else: event.set_ends_today(not event.get_ends_today()) return event EVENT_MODIFIERS = [ ("change fuzzy", lambda event: event.set_fuzzy(not event.get_fuzzy())), ("change locked", lambda event: event.set_locked(not event.get_locked())), ("change ends today", modifier_change_ends_today), ("change id", lambda event: event.set_id(inc(event.get_id()))), ("change time period", lambda event: event.set_time_period( event.get_time_period().move_delta(GregorianDelta.from_days(1)))), ("change text", lambda event: event.set_text("was: %s" % event.get_text())), ("change category", lambda event: event.set_category(new_cat(event))), ("change icon", lambda event: event.set_icon("was: %s" % event.get_icon())), ("change description", lambda event: event.set_description("was: %s" % event.get_description())), ("change hyperlink", lambda event: event.set_hyperlink("was: %s" % event.get_hyperlink())), ("change progress", lambda event: event.set_progress(new_progress(event))), ("change alert", lambda event: event.set_alert("was: %s" % event.get_alert())), ] SUBEVENT_MODIFIERS = EVENT_MODIFIERS
def get_default_time_period(self): return time_period_center(self.now(), GregorianDelta.from_days(30))
def get_min_zoom_delta(self): return (GregorianDelta.from_seconds(60), _("Can't zoom deeper than 1 minute"))
def monday_week_1(year): from timelinelib.calendar.gregorian.timetype import GregorianTimeType jan_4 = GregorianDateTime.from_ymd(year, 1, 4).to_time() jan_4_day_of_week = GregorianTimeType().get_day_of_week(jan_4) return jan_4 - GregorianDelta.from_days(jan_4_day_of_week)
def get_delta(self, value): return GregorianDelta.from_days(value)
def _convert_to_timedelta(self, t): if isinstance(t, timedelta): return GregorianDelta(t.seconds) else: return GregorianDelta(0)
def get_min_zoom_delta(self): return (GregorianDelta.from_seconds(60), _("Can't zoom deeper than 1 minute"))
def increment(self, time): return time + GregorianDelta.from_seconds(60)
def backward_one_week_fn(main_frame, current_period, navigation_fn): wk = GregorianDelta.from_days(7) navigation_fn(lambda tp: tp.move_delta(-1 * wk))
def increment_day(self, date): year, month, day = date time = GregorianDateTime.from_ymd(year, month, day).to_time() if time < GregorianTimeType().get_max_time() - GregorianDelta.from_days(1): return GregorianDateTime.from_time(time + GregorianDelta.from_days(1)).to_date_tuple() return date
def backward_one_year_fn(main_frame, current_period, navigation_fn): yr = GregorianDelta.from_days(365) navigation_fn(lambda tp: tp.move_delta(-1 * yr))
event.set_locked(True) else: event.set_ends_today(not event.get_ends_today()) return event EVENT_MODIFIERS = [ ("change fuzzy", lambda event: event.set_fuzzy(not event.get_fuzzy())), ("change locked", lambda event: event.set_locked(not event.get_locked())), ("change ends today", modifier_change_ends_today), ("change id", lambda event: event.set_id(inc(event.get_id()))), ("change time period", lambda event: event.set_time_period(event.get_time_period().move_delta(GregorianDelta.from_days(1)))), ("change text", lambda event: event.set_text("was: %s" % event.get_text())), ("change category", lambda event: event.set_category(new_cat(event))), ("change icon", lambda event: event.set_icon("was: %s" % event.get_icon())), ("change description", lambda event: event.set_description("was: %s" % event.get_description())), ("change hyperlink", lambda event: event.set_hyperlink("was: %s" % event.get_hyperlink())), ("change progress", lambda event: event.set_progress(new_progress(event))), ("change alert", lambda event: event.set_alert("was: %s" % event.get_alert())), ]
def increment(self, time): return time + GregorianDelta.from_days( GregorianDateTime.from_time(time).days_in_month() )
def get_delta(self, value): return GregorianDelta.from_days(value)
def increment(self, time): return time + GregorianDelta.from_days(1)
def backward_one_year_fn(main_frame, current_period, navigation_fn): yr = GregorianDelta.from_days(365) navigation_fn(lambda tp: tp.move_delta(-1 * yr))
def move_period_num_weeks(period, num): delta = GregorianDelta.from_days(7) * num start_time = period.start_time + delta end_time = period.end_time + delta return TimePeriod(start_time, end_time)
def increment(self, time): return time + GregorianDelta.from_days( GregorianDateTime.from_time(time).days_in_month())