def is_workday(day: datetime) -> bool:
     """
     Helper method to show whether a day is weekday or weekend
     """
     if day.weekday() == 5 or day.weekday() == 6:
         return False
     return True
Ejemplo n.º 2
0
def different(date: datetime, weeks, weekday):
    print(date.weekday())
    days = weeks * 7 + date.weekday() - day_of_week_number[weekday]
    if days < 0:
        days += 7

    print(days)
    print(day_of_week[date.weekday()])
Ejemplo n.º 3
0
def write_clock_v2(disp: weh002004a.WEH002004A, tm: datetime):
    add_1 = tm.strftime(':%S')
    add_2 = '   '
    add_3 = tm.strftime('/%d')        
    add_4 = __week_name[tm.weekday()]

    st = tm.strftime('%H %M')

    line = [b'',b'',b'',b'']
    for i in range(0, 5):
        if st[i] == ' ':
            line[0] = line[0] + add_1.encode() + b'\x20'
            line[1] = line[1] + add_2.encode() + b'\x20'
            line[2] = line[2] + add_3.encode() + b'\x20'
            line[3] = line[3] + add_4.encode() + b'\x20'
        else:
            num = ord(st[i]) - 48
            line[0] = line[0] + __big_digit[num][0] + b'\x20'
            line[1] = line[1] + __big_digit[num][1] + b'\x20'
            line[2] = line[2] + __big_digit[num][2] + b'\x20'
            line[3] = line[3] + __big_digit[num][3] + b'\x20'

    disp.write_bytes(line[0], 0)
    disp.write_bytes(line[1], 1)
    disp.write_bytes(line[2], 2)
    disp.write_bytes(line[3], 3)
Ejemplo n.º 4
0
    def get_next_n_slots(self,
                         week_config: List[List[Dict]],
                         current_time: datetime,
                         n=10):
        """
        Returns `n` available slots from the `current_time` on the basis of `week_config`. returns empty list, 
        if any slot is not abailable.
        """
        next_n_slots = []
        week_day = current_time.weekday()
        idx_week = week_day

        while True:
            if idx_week == week_day + WEEK_LEN - 1 and len(next_n_slots) == 0:
                return []
            for slot in map(
                    lambda s: Slot(parse_time(s['start_time']),
                                   parse_time(s['end_time'])),
                    week_config[idx_week % WEEK_LEN]):
                if len(next_n_slots) >= n:
                    return [slot.to_dict for slot in next_n_slots]
                slot.make(current_time +
                          datetime.timedelta(days=idx_week - week_day))
                if slot.start >= current_time:
                    next_n_slots.append(slot)
            idx_week += 1
        return [slot.to_dict for slot in next_n_slots]
 def get_num_days_between(start: datetime, end: datetime,
                          week_day: int) -> int:
     num_weeks, remainder = divmod((end - start).days, 7)
     if (week_day - start.weekday()) % 7 <= remainder:
         return num_weeks + 1
     else:
         return num_weeks
Ejemplo n.º 6
0
def is_public_holiday(m_date: datetime):
    holidays = get_datetime_public_holidays()
    if m_date.weekday() in [5, 6]:
        return True
    elif m_date in holidays:
        return True
    else:
        return False
Ejemplo n.º 7
0
def is_working_day(date: datetime) -> bool:
    """ Is the given date a working day """
    weekday = date.weekday()
    if weekday in (5, 6):
        return False
    if is_bank_holiday(date):
        return False
    return True
Ejemplo n.º 8
0
 def _get_weekday_feature(self, ond_date: datetime):
     """
     获取周特征(一周中的某一天)
     :param ond_date:
     :return:
     """
     curWeekDay = ond_date.weekday()
     alpha = curWeekDay / 7 * 2 * PI
     return np.array([math.cos(alpha), math.sin(alpha)])
Ejemplo n.º 9
0
def get_capacity_and_value(shift_date: datetime, shift_time: str) -> tuple:
    if 0 <= shift_date.weekday() <= 4 or shift_date.weekday() == 6:
        if shift_time == SHIFT_OPTIONS[0]:
            return CAPACITY_OPTIONS['regular_day_morning'], VALUE_OPTIONS['regular_day_morning']
        if shift_time == SHIFT_OPTIONS[1]:
            return CAPACITY_OPTIONS['regular_day_noon'], VALUE_OPTIONS['regular_day_noon']
        if shift_time == SHIFT_OPTIONS[2]:
            return CAPACITY_OPTIONS['night'], VALUE_OPTIONS['regular_day_night']
    if shift_date.weekday() == 5:
        if shift_time == SHIFT_OPTIONS[0]:
            return CAPACITY_OPTIONS['friday_morning'], VALUE_OPTIONS['regular_day_morning']
        if shift_time == SHIFT_OPTIONS[1]:
            return CAPACITY_OPTIONS['special_day'], VALUE_OPTIONS['friday_noon']
        if shift_time == SHIFT_OPTIONS[2]:
            return CAPACITY_OPTIONS['night'], VALUE_OPTIONS['special_day']
    else:
        if shift_time == SHIFT_OPTIONS[2]:
            return CAPACITY_OPTIONS['night'], VALUE_OPTIONS['special_day']
        else:
            return CAPACITY_OPTIONS['special_day'], VALUE_OPTIONS['special_day']
Ejemplo n.º 10
0
    def get_response_for_day(self, datetime_object: datetime, week=None):
        if week is None:
            week = self._get_week_number(datetime_object)

        week_days = self._get_week_days(week)

        weekday = datetime_object.weekday()

        for day in week_days:
            if day.weekday == weekday:
                return self._group_label + self._get_response_for_day(
                    day, week == 0)

        return self._group_label + 'На *%s* нет пар' % WEEKDAYS_RU[weekday]
Ejemplo n.º 11
0
def whoSelect(guestStartTime: datetime):
    '''

    :param guestStartTime:
    :return: 周几
    '''
    weekDay = guestStartTime.weekday()
    # print("weekDay", weekDay)
    if weekDay <= 4:
        sWorkTime = "workTime14"
    elif weekDay == 5:
        #     todo1
        sWorkTime = "workTime5"
    else:
        sWorkTime = "workTime67"
    return sWorkTime
Ejemplo n.º 12
0
def is_date_in_busines_day(date_to_check: datetime) -> bool:
    """"
    Checks if a date is part of a business day. Weekends and ZA public holidays are not business days.
    @param date_to_check: The date to check
    @return: Whether to exclude the date or not
    """
    previous_day = date_to_check - datetime.timedelta(days=1)
    current_day_tuple = (date_to_check.day, date_to_check.month)
    previous_day_tuple = (previous_day.day, previous_day.month)
    if current_day_tuple in ZA_HOLIDAYS or (previous_day.weekday() == SUNDAY
                                            and previous_day_tuple
                                            in ZA_HOLIDAYS):
        return False
    if date_to_check.weekday() in (SATURDAY, SUNDAY):
        return False
    if date_to_check.date() in EASTER_HOLIDAYS:
        return False
    return True
Ejemplo n.º 13
0
    def __getDayText(self, date_today: datetime, date_requested: datetime):

        date_requested = date_requested.replace(hour=0,
                                                minute=0,
                                                second=0,
                                                microsecond=0)
        date_today = date_today.replace(hour=0,
                                        minute=0,
                                        second=0,
                                        microsecond=0)

        diff_in_days = (date_requested - date_today).days

        if (diff_in_days <= 0):
            return "heute"
        elif (diff_in_days == 1):
            return "morgen"
        else:
            weekDays = ("Montag", "Dienstag", "Mittwoch", "Donnerstag",
                        "Freitag", "Samstag", "Sonntag")

            weekday_name = weekDays[date_requested.weekday()]
            return "am {}".format(weekday_name)
Ejemplo n.º 14
0
 def fillTrainDay(self, departureTime: datetime):
     self.trainX[self.trainRowsIndex][self.columns[str(
         departureTime.weekday())]] = 1
Ejemplo n.º 15
0
 def next_weekday(d: datetime, weekday: int):
     days_ahead = weekday - d.weekday()
     if days_ahead <= 0:  # Target day already happened this week
         days_ahead += 7
     return d + datetime.timedelta(days_ahead)
Ejemplo n.º 16
0
    def get_response_for_near(self, datetime_object: datetime):
        weekday = datetime_object.weekday()
        week = self._get_week_number(datetime_object)

        week_days = self._get_week_days(week)

        next_week = 1 if week == 2 else 2
        next_week_days = self._get_week_days(next_week)

        for day in next_week_days:
            day.weekday += 7

        week_days += next_week_days

        next_days = []
        for offset in range(6):
            for day in week_days:
                if next_days:
                    next_days.append(day)

                elif day.weekday == weekday + offset:
                    next_days.append(day)

            if next_days:
                break

        if next_days:
            for day in next_days:
                for lesson in day.lessons:
                    start, _ = [
                        list(map(int, time.split(':')))
                        for time in lesson.time.split('-')
                    ]

                    date = datetime_object + datetime.timedelta(day.weekday -
                                                                weekday)

                    lesson_start = datetime.datetime(year=date.year,
                                                     month=date.month,
                                                     day=date.day,
                                                     hour=start[0],
                                                     minute=start[1])

                    if datetime_object > lesson_start:
                        continue

                    if datetime_object.date() == lesson_start.date():
                        minutes = (lesson_start -
                                   datetime_object).seconds // 60
                        hours = minutes // 60
                        minutes -= hours * 60

                        hours = '%s ч. ' % hours if hours else ''
                        minutes = '%s мин.' % minutes

                        added = 'сегодня через %s%s' % (hours, minutes)

                    else:
                        days = (lesson_start - datetime_object).days
                        added = 'через %s дн.' % days

                    response = 'Ближайшая пара *%s*\n\n' % added
                    response += self._get_response_for_lesson(lesson)
                    return self._group_label + response

        sad_emoji = EMOJI['sad']
        return self._group_label + 'Ближайшой пары найти *не удалось* %s' % sad_emoji
Ejemplo n.º 17
0
def get_day_name_from_datetime(my_datetime: datetime) -> "day Name":
    try:
        return calendar.day_name[my_datetime.weekday()]
    except KeyError as error:
        log.error(error.__str__())
Ejemplo n.º 18
0
 def weekday_of(day: datetime):
     return DayOfTheWeek((day.weekday() + 1) % 7)
Ejemplo n.º 19
0
 def is_workday(day: datetime):
     if day.weekday() == 5 or day.weekday() == 6:
         return False
     return True
Ejemplo n.º 20
0
 def _get_weekday_feature_one_hot(one_date: datetime):
     one_hot_vector = np.zeros(7)
     one_hot_vector[one_date.weekday()] = 1
     return one_hot_vector