예제 #1
0
    def contains_due_date_range(self, task, min_date_string, max_date_string):
        assert isinstance(task, Task)
        assert type(min_date_string) and type(max_date_string) is str

        min_day = Day(
            datetime.strptime(min_date_string, self.__vars.date_format))
        max_day = Day(
            datetime.strptime(max_date_string, self.__vars.date_format))
        if len(task.due_date.date_string) > 0:
            day = Day(
                datetime.strptime(task.due_date.date_string,
                                  self.__vars.date_format))

            if min_day.to_date_time() < day.to_date_time(
            ) < max_day.to_date_time():
                return task
예제 #2
0
    def get_day(today: Day, weekday_number: int) -> Day:
        """
        Gets the next calendar day in current week, next week, or next month that
        matches the provided weekday_number.
        :param today: Day object
        :param weekday_number: integer (ie. 0-6) m=0, su=6
        :return: Day object
        """
        assert type(today) is Day
        assert type(weekday_number) is int

        today = today.to_date_time()
        date_list = list(rrule(DAILY, count=1, wkst=MO, byweekday=weekday_number, dtstart=today))
        if date_list:
            return Day(date_list[0])
예제 #3
0
    def get_work_week_days(start_day: Day, month_count: int) -> List[Day]:
        """
        Gets all days within a work week from today until the end of the month
        :param start_day: Day object
        :param month_count: number of months
        :return: list of date strings
        """
        assert type(start_day) is Day
        assert type(month_count) is int

        start = start_day.to_date_time()
        end = start + relativedelta(months=month_count)
        days = list(rrule(DAILY, wkst=MO, byweekday=(MO, TU, WE, TH, FR), dtstart=start, until=end))

        return [Day(dt) for dt in days]
예제 #4
0
    def get_week_days(start_day: Day, weekday_number: int, month_count: int) -> List[Day]:
        """
        Returns all the days for the provided week day in a month.
        :param start_day: Day object
        :param weekday_number: integer (ie. 0-6) m=0 and su=6
        :param month_count: number of months
        :return: list of Days
        """
        assert type(start_day) is Day
        assert type(weekday_number) is int
        assert type(month_count) is int

        start = start_day.to_date_time()
        end = start + relativedelta(months=month_count)
        days = list(rrule(DAILY, wkst=MO, byweekday=weekday_number, dtstart=start, until=end))

        return [Day(dt) for dt in days]
예제 #5
0
    def get_closest_due_date(self, due_dates: List[DueDate], current_day=None) -> DueDate:
        """
        Returns a future date string that is the closest to the current day
        :param due_dates: list of due_date objects with the format yyyy-mm-dd
        :param current_day: Day object
        :return:
        Date string
        """
        if current_day is None:
            current_day = Today()

        diff_list = []
        # calculate the difference between current day and date string
        for due_date in due_dates:
            if len(due_date.date_string) > 0:
                day = Day(datetime.strptime(due_date.date_string, self.vars.date_format))
                timedelta1 = day.to_date_time() - current_day.to_date_time()
                diff_list.append(timedelta1.days)

        # return the date string using the smallest difference
        for index, diff_num in enumerate(diff_list):
            if diff_num >= 0:
                return due_dates[index]
예제 #6
0
 def get_next_week(self, day: Day) -> List[Day]:
     future_day = Day(day.to_date_time() + timedelta(days=7))
     return self.fill(self.get_first_day_in_week(deepcopy(future_day)), self.get_last_day_in_week(deepcopy(future_day)))
예제 #7
0
 def fill(start_day: Day, end_day: Day) -> List[Day]:
     days = list(rrule(freq=DAILY, dtstart=start_day.to_date_time(), until=end_day.to_date_time()))
     return [Day(dt) for dt in days]
예제 #8
0
 def get_tomorrow(day: Day) -> Day:
     return Day(day.to_date_time() + timedelta(days=1))
예제 #9
0
 def get_yesterday(day: Day) -> Day:
     return Day(day.to_date_time() - timedelta(days=1))
예제 #10
0
 def get_last_day_in_week(day: Day) -> Day:
     return Day(day.to_date_time() + timedelta(days=(6 - day.weekday_number)))
예제 #11
0
 def get_first_day_in_week(day: Day) -> Day:
     return Day(day.to_date_time() - timedelta(days=day.weekday_number))