def get_available_schedules(service_schedule: list,
                                check_date_local: arrow.Arrow):
        """Get available schedules from schedules."""
        week_dates: list = list()
        date_availables: list = list()

        check_date_only: arrow.Arrow = check_date_local.replace(hour=0,
                                                                minute=0,
                                                                second=0,
                                                                microsecond=0)
        for day_week in range(-1, 7):
            week_dates.append(check_date_only.shift(days=day_week))

        if 'available' in service_schedule[0]:
            for available_time in service_schedule[0]['available']:
                for day_week in week_dates:
                    if day_week.isoweekday() == int(
                            available_time['dayofweek']):
                        from_hours, from_minutes = map(
                            int, available_time['from'].split(':'))
                        to_hours, to_minutes = map(
                            int, available_time['to'].split(':'))
                        date_availables.append([
                            day_week.replace(hour=from_hours,
                                             minute=from_minutes),
                            day_week.replace(hour=to_hours, minute=to_minutes)
                        ])

        return date_availables
Beispiel #2
0
 def get_time_arrows(
         self) -> Tuple[Optional[Arrow], Optional[Arrow], Optional[Arrow]]:
     if not self.year:
         return None, None, None
     open_arrow, start_arrow, end_arrow = None, None, None
     if self.open_hour:
         open_arrow = Arrow(year=self.year,
                            month=self.month,
                            day=self.day,
                            tzinfo=pytz.timezone("Asia/Tokyo"),
                            hour=self.open_hour,
                            minute=self.open_minute)
     if self.start_hour:
         start_arrow = Arrow(year=self.year,
                             month=self.month,
                             day=self.day,
                             tzinfo=pytz.timezone("Asia/Tokyo"),
                             hour=self.start_hour,
                             minute=self.start_minute)
     if self.end_hour:
         end_arrow = Arrow(year=self.year,
                           month=self.month,
                           day=self.day,
                           tzinfo=pytz.timezone("Asia/Tokyo"),
                           hour=self.end_hour,
                           minute=self.end_minute)
         open_or_start_hour = self.open_hour or self.start_hour
         open_or_start_minute = self.open_minute or self.start_minute
         if open_or_start_hour and\
                 (open_or_start_hour > self.end_hour or
                  (open_or_start_hour == self.end_hour and open_or_start_minute >= self.end_minute)):
             end_arrow = end_arrow.replace(days=1)
     return open_arrow, start_arrow, end_arrow
Beispiel #3
0
 def norm_time_zone(basicdate: arrow.Arrow, tz_string: str = ""):
     # as far as I can see, all times comes with CDT abbrevian for
     # timezone, which can be several timezones.
     # I chose the us central, and used it throughout the process,
     # failing in case a new one is submitted
     if tz_string != "CDT":
         print("ERR: got unknown timezone: ", tz_string)
         exit(2)
     return basicdate.replace(tzinfo=dateutil.tz.gettz('US/Central'))
Beispiel #4
0
def midnight(reftime: arrow.Arrow = None) -> arrow.Arrow:
    '''
    Helper method to return the arrow object representing midnight.

    :param reftime: the day to get midnight, or use ``arrow.now()`` if not specified
    :returns: the arrow of ``reftime`` at midnight
    '''
    reftime = reftime or arrow.now()
    return reftime.replace(hour=0, minute=0, second=0, microsecond=0)