Beispiel #1
0
 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
Beispiel #2
0
 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]))])
Beispiel #3
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
Beispiel #4
0
 def get_task(
     name='unknown',
     description='unknown',
     date_added=None,
     date_to_finish=None,
     date_finished=None,
     priority=TaskPriority.unknown,
     task_type=TaskType.unknown,
     status=TaskStatus.not_done,
     reminder=0,
 ):
     try:
         if isinstance(date_added, str):
             date_added = datetime.datetime.strptime(
                 date_added, '%Y-%m-%d %H:%M:%S')
         if isinstance(date_to_finish, str):
             date_to_finish = datetime.datetime.strptime(
                 date_to_finish, '%Y-%m-%d %H:%M:%S')
         if isinstance(date_finished, str):
             date_finished = datetime.datetime.strptime(
                 date_finished, '%Y-%m-%d %H:%M:%S')
     except ValueError:
         raise IncorrectDateFormatException
     if date_added is None:
         date_added = DateHelper.get_today_long()
     return Task(name, description, date_added, date_to_finish,
                 date_finished, priority, task_type, status, int(reminder))
Beispiel #5
0
 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 test_get_task_empty(self):
     t = TaskFactory.get_task()
     self.assertEqual(t.name, 'unknown')
     self.assertEqual(t.description, 'unknown')
     self.assertEqual(t.date_added, DateHelper.get_today_long())
     self.assertEqual(t.date_to_finish, None)
     self.assertEqual(t.date_finished, None)
     self.assertEqual(t.priority, TaskPriority['unknown'])
     self.assertEqual(t.type, TaskType['unknown'])
     self.assertEqual(t.status, TaskStatus['not_done'])
     self.assertEqual(t.reminder, 0)
 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
Beispiel #8
0
 def __command_add(self, args):
     if len(args) < 1:
         return MumjolandiaResponseObject(
             status=MumjolandiaReturnValue.task_name_not_given)
     else:
         name = ' '.join(args[0:])
         try:
             self.tasks.append(
                 TaskFactory.get_task(
                     name,
                     date_to_finish=str(DateHelper.get_today_long()),
                 ))
         except IncorrectDateFormatException:
             logging.warning("Task '" + name +
                             "' not added - incorrect date format")
             return MumjolandiaResponseObject(
                 status=MumjolandiaReturnValue.task_incorrect_date_format)
         logging.debug("Added task '" + name + "'")
         self.__save_if_allowed()
         return MumjolandiaResponseObject(
             status=MumjolandiaReturnValue.task_added,
             arguments=[name, len(self.tasks) - 1])
Beispiel #9
0
 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
Beispiel #10
0
 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))
Beispiel #13
0
 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
Beispiel #14
0
 def get_next_occurrence_as_date(self, date=0):
     return DateHelper.get_today_short(
         self.get_next_occurrence_in_days_as_int(date))