Exemplo n.º 1
0
 def within(self, date):
     tmp_date = copy.copy(date)
     if self.holidays.is_holiday(tmp_date):
         day = self.get_day(tmp_date.isoweekday())
         if day is not None:
             return day.is_time_within_opening_hours(Time.fromDate(tmp_date), tmp_date)
     return False
Exemplo n.º 2
0
    def timedelta(self, start, end):
        """
        Returns a datetime.timedelta with the number of full business days
        and business time between d1 and d2
        """
        time = datetime.timedelta()
        if start >= end:
            return time

        # within the same day
        if start.date() == end.date():
            if self.holidays.is_holiday(start):
                return time

            day_of_week = start.isoweekday()
            day = self.get_day(day_of_week)
            # we doesn't work at `start` date (may be it's Sat or Sun)
            if day is None:
                return time
            start_time = Time.fromDate(start)
            end_time = Time.fromDate(end)
            time = day.timedelta(start_time, end_time)
        else:
            dates = []
            if end.date() - start.date() == datetime.timedelta(days=1):
                start_day = self.get_day(start.isoweekday())
                end_day = self.get_day(end.isoweekday())
                dates = [
                    [start, Time.fromDate(start), start_day.get_closing_time(start)],
                    [end, end_day.get_opening_time(end), Time.fromDate(end)],
                ]
            else:
                start_day = self.get_day(start.isoweekday())
                end_day = self.get_day(end.isoweekday())
                dates = [
                    [start, Time.fromDate(start), start_day.get_closing_time(start)],
                    [end, end_day.get_opening_time(end), Time.fromDate(end)],
                ]
                last_date = start
                while True:
                    date = self.get_closest_date_after(last_date)
                    if date.date() >= end.date():
                        break
                    day = self.get_day(date.isoweekday())
                    dates.append([date, day.get_opening_time(date), day.get_closing_time(date)])
                    last_date += datetime.timedelta(days=1)

            for date, start_time, end_time in dates:
                if self.holidays.is_holiday(date):
                    continue
                day_of_week = date.isoweekday()
                day = self.get_day(day_of_week)
                # we doesn't work at `date` day (may be it's Sat or Sun)
                if day is None:
                    continue
                time += day.timedelta(start_time, end_time)

        return time
Exemplo n.º 3
0
 def get_closest_date_after(self, date):
     tmp_date = copy.copy(date)
     day_of_week = tmp_date.isoweekday()
     time = Time.fromDate(tmp_date)
     if self.holidays.is_holiday(tmp_date):
         day = self.get_day(day_of_week)
         if day is not None:
             closest_time = day.get_closest_opening_time_after(time, tmp_date)
             if closest_time is not None:
                 return tmp_date.replace(hour=closest_time.get_hours(), minute=closest_time.get_minutes())
     tmp_date = self.get_date_after(tmp_date)
     while self.holidays.is_holiday(tmp_date):
         tmp_date = self.get_date_after(tmp_date)
     closest_day = self.get_closest_day_before(tmp_date.isoweekday())
     closing_time = closest_day.get_opening_time(tmp_date)
     return tmp_date.replace(hour=closing_time.get_hours(), minute=closing_time.get_minutes())
Exemplo n.º 4
0
 def fromString(cls, start_time, end_time):
     return cls(Time.fromString(start_time), Time.fromString(end_time))
Exemplo n.º 5
0
 def fromString(cls, start_time, end_time):
     return cls(Time.fromString(start_time), Time.fromString(end_time))