def is_to_be_reminded(self, date=DateHelper.get_today_short()): if isinstance(date, int): date = DateHelper.get_today_short(date) next_occurrence = self.get_next_occurrence_in_days_as_int(date) if next_occurrence <= self.reminder: return True return False
def __command_set(self, args): if args is None: return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Parameter not provided']) if int(args[0]) > 0: return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Value has to be <= 0']) self.start_date = DateHelper.get_today_short(args[0]) SharedPreferences().put(self.start_date_string, str(self.start_date)) return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Set to: ' + str(DateHelper.get_today_short(args[0]))])
def __get_plan_id(self, day_shift): current_index = 0 for plan in self.plans: if plan.date == DateHelper.get_today_short(day_shift): return current_index current_index += 1 return None
def __get_current_pompejanka_day(self): if self.start_date is None: return -1 day = int((DateHelper.get_today_short() - self.start_date).days) + 1 if day > 54: return 0 return day
def get_tasks(self, time_delta=0): return_tasks = [] target_day = DateHelper.get_today_short(time_delta) for periodic_task in self.task_loader.get(): if periodic_task.is_to_be_reminded(target_day): return_tasks.append(TaskFactory().get_task( name=periodic_task.name, date_to_finish=periodic_task.get_next_occurrence_as_date( time_delta), task_type=periodic_task.task_type, reminder=periodic_task.reminder, )) return return_tasks
def get_next_occurrence_in_days_as_int(self, date=0): # todo: add tests to check that int parameter works correctly return_value = None if isinstance(date, int): date = DateHelper.get_today_short(date) if not isinstance(date, datetime.date): logging.error("Date parameter type is not datetime.Date") return None if self.occurrence_type is PeriodicTaskOccurrenceType.year: delta_days = (self.start - date).days return delta_days else: wheel_date = self.start wheel_amount = self.occurrence if self.occurrence_type is PeriodicTaskOccurrenceType.day: pass if self.occurrence_type is PeriodicTaskOccurrenceType.week: wheel_amount *= 7 while wheel_date < date: wheel_date += datetime.timedelta(wheel_amount) return_value = (wheel_date - date).days return return_value
def __handle_date_progression(self): tasks = self.periodic_task_generator.get_tasks() for task_id, task in enumerate(tasks): saved_value = SharedPreferences().get(self.__generate_preference_string(task.name)) if saved_value is not None: if task.type is TaskType.event: if datetime.datetime.strptime(saved_value[:], '%Y-%m-%d').date().year < DateHelper.get_today_short().year: SharedPreferences().clear_key(self.__generate_preference_string(task.name)) else: if task.date_to_finish > datetime.datetime.strptime(saved_value[:], '%Y-%m-%d').date(): SharedPreferences().clear_key(self.__generate_preference_string(task.name))
def test_should_be_reminded_true_ok(self): date1 = DateHelper.get_today_short(3) task = TaskFactory.get_task(date_to_finish=DateHelper.get_today_short(5), reminder=2) self.assertTrue(TaskReminder.should_be_reminded(task, date1))
def test_should_be_reminded_default_date_false_ok(self): task = TaskFactory.get_task(date_to_finish=DateHelper.get_today_short(3), reminder=2) self.assertFalse(TaskReminder.should_be_reminded(task))
def should_be_reminded(task, date=DateHelper.get_today_short()): diff = task.date_to_finish - date if diff.days <= task.reminder: return True return False
def get_next_occurrence_as_date(self, date=0): return DateHelper.get_today_short( self.get_next_occurrence_in_days_as_int(date))