def is_in_office(self): now = utils.get_current_time() hours = self.hours todays_hours = hours.get(str(now.weekday())) if not todays_hours: return False todays_hours['start'] = utils.str_to_time(todays_hours['start']).time() todays_hours['end'] = utils.str_to_time(todays_hours['end']).time() return todays_hours['start'] <= now.time() <= todays_hours['end']
def next_hours(self): now = utils.get_current_time() hours = self.hours days = hours.keys() next_day = 0 while str((now.weekday() + next_day) % 7) not in days: next_day += 1 next_day_of_week = (now.weekday() + next_day) % 7 next_date = now + datetime.timedelta(days=next_day) hours = hours[str(next_day_of_week)] hours['start'] = utils.str_to_time(hours['start']) next_start = next_date.replace( hour=hours['start'].hour, minute=hours['start'].minute, second=0, ) return next_start