def deal_confirm_out(account_id, create_time, callback): pos = callback.find("time=") str_time = callback[pos+5:] user_time = int(str_time) end_time = local_date_time(user_time) current_date = datetime.strftime(end_time, '%Y-%m-%d') info = get_schedule_by_user(account_id, current_date) if info is None: raise HTTPError(500, "Internal data error") schedule_id = info[0] begin_time_st = info[1] cur_time = local_date_time(create_time) begin_time = local_date_time(begin_time_st) modify_schedule(schedule_id, cur_time, end_time, begin_time, account_id) modify_schedule_by_user(schedule_id, user_time) if user_time < begin_time_st: yield asyncio.sleep(1) set_status_by_user_date(account_id, current_date, status="wait_out") return number_message(), False hours = int((user_time - begin_time_st)/3600) min = int(((user_time - begin_time_st) % 3600)/60) return [confirm_out_message(user_time, hours, min)], True
def deal_confirm_in(account_id, create_time, callback): """ will be linked with the calendar internally, Check in time of registered user. Check also: calendar_bot/externals/calendar_req.py :param account_id: user account id. :param create_time: current date by local time. :param callback: The message content of the callback, include the user's check-in time :return: Prompt message of successful check in. """ pos = callback.find("time=") str_time = callback[pos + 5:] user_time = int(str_time) my_end_time = user_time + 60 begin_time = local_date_time(user_time) current_date = datetime.strftime(begin_time, '%Y-%m-%d') info = get_schedule_by_user(account_id, current_date) if info is not None: raise HTTPError(500, "Internal data error") end_time = begin_time + timedelta(minutes=1) cur_time = local_date_time(create_time) title = "[{account}]'s clock-in time on {date}".\ format(account=account_id, date=datetime.strftime(begin_time, '%A, %B %d')) schedule_uid = create_schedule(cur_time, end_time, begin_time, account_id, title) set_schedule_by_user(schedule_uid, account_id, current_date, user_time, my_end_time) return make_text("Clock-in time has been registered.")
def __init__(self, sign_time): """ Convert timestamp time to datetime time in a specific time zone. And assign it to the corresponding member variable. :param sign_time: A user time of timestamp value. """ self.date_time = local_date_time(sign_time) self.month = str(self.date_time.month) self.date = str(self.date_time.day) self.min = str(self.date_time.minute) self.interval_en = "AM" self.hours = str(self.date_time.hour) if self.date_time.hour > 12: self.interval_en = "PM" self.hours = str(self.date_time.hour - 12) self.str_current_time_tick = str(sign_time) pos = self.str_current_time_tick.find(".") if pos != -1: self.str_current_time_tick = self.str_current_time_tick[:pos]
def deal_confirm_out(account_id, create_time, callback): """ will be linked with the calendar internally, Check out time of registered user. Check also: calendar_bot/externals/calendar_req.py :param account_id: user account id. :param create_time: current date by local time. :param callback: The message content of the callback, include the user's check-out time :return: Prompt message of successful check out. """ pos = callback.find("time=") str_time = callback[pos+5:] user_time = int(str_time) end_time = local_date_time(user_time) current_date = datetime.strftime(end_time, '%Y-%m-%d') info = get_schedule_by_user(account_id, current_date) if info is None: raise HTTPError(500, "Internal data error") schedule_id = info[0] begin_time_st = info[1] cur_time = local_date_time(create_time) begin_time = local_date_time(begin_time_st) title = "[{account}]'s working hours on {date}".\ format(account=account_id, date=datetime.strftime(end_time, '%A, %B %d')) modify_schedule(schedule_id, cur_time, end_time, begin_time, account_id, title) modify_schedule_by_user(schedule_id, user_time) if user_time < begin_time_st: yield asyncio.sleep(1) set_status_by_user_date(account_id, current_date, status="wait_out") return number_message(), False hours = int((user_time - begin_time_st)/3600) min = int(((user_time - begin_time_st) % 3600)/60) return [confirm_out_message(user_time, hours, min)], True
def deal_confirm_in(account_id, create_time, callback): pos = callback.find("time=") str_time = callback[pos + 5:] user_time = int(str_time) my_end_time = user_time + 60 begin_time = local_date_time(user_time) current_date = datetime.strftime(begin_time, '%Y-%m-%d') info = get_schedule_by_user(account_id, current_date) if info is not None: raise HTTPError(500, "Internal data error") end_time = begin_time + timedelta(minutes=1) cur_time = local_date_time(create_time) schedule_uid = create_schedule(cur_time, end_time, begin_time, account_id) set_schedule_by_user(schedule_uid, account_id, current_date, user_time, my_end_time) return make_text("Clock-in time has been registered.")
def __init__(self, sign_time): self.date_time = local_date_time(sign_time) self.month = str(self.date_time.month) self.date = str(self.date_time.day) self.min = str(self.date_time.minute) self.interval_en = "AM" self.hours = str(self.date_time.hour) if self.date_time.hour > 12: self.interval_en = "PM" self.hours = str(self.date_time.hour - 12) self.str_current_time_tick = str(sign_time) pos = self.str_current_time_tick.find(".") if pos != -1: self.str_current_time_tick = self.str_current_time_tick[:pos]
def __init__(self): self.__create_time = time.time() date_time = local_date_time(self.__create_time) self.__current_date = datetime.strftime(date_time, '%Y-%m-%d')