如何停止同时输入和过去的预约?

问题描述 投票:0回答:1

当前时间在代码开始时使用...定义

from datetime import datetime
now = datetime.now()
auformat = now.strftime("%d-%m-%Y %H:%M:%S")
# print(auformat)

我需要停止输入并发约会并停止插入过去的约会。这是我的代码,但我不知道该把它放在哪里,因为它需要位于下面的“addRecord”代码中的“日期、开始、结束”之后。

def isConcurrentAppointment(date, start, end):
    if isConcurrentAppointment(date, >=appt.start, >=appt.end): # greater than or equal to
        print("Cuncurrent appointment exists. Try again.")
        continue
    elif appt.start <=now: # OR <=current.time: - Not sure what to use
        print("Invalid entry. Appointment must be in the future. Try again!")
        continue

输入(addRecord)代码

def addRecord(schedule):
    date = input("Enter a date (DD/MM/YYYY): ")
    date = date.strip()
    start = input("Enter a start time (HH): ")
    start = start.strip()
    end = input("Enter an end time (HH): ")
    end = end.strip()
    '''
    I think the above code should slot in here somehow!
    '''
    description = input("Enter a description (Max. 25 characters with spaces): ")
    venue = input("Enter a venue  (Max. 25 characters with spaces): ")
    priority = input("Enter a priority (High, Medium or Low): ")
    priority = priority.strip() # if isConcurrentAppointment statement goes maybe below here.
    appointment = Appointment(date,start,end,description,venue,priority)
    schedule.append(appointment)
    print("Appointment added.")

如前所述,我创建了要插入的代码,但无法确定插入位置,因为它有一个“def”语句。也许我需要以某种方式失去“def”行?

def isConcurrentAppointment(date, start, end):
    if isConcurrentAppointment(date, >=appt.start, >=appt.end): # greater than or equal to
        print("Cuncurrent appointment exists. Try again.")
        continue
    elif appt.start <=now: # OR <=current.time: - Not sure what to use
        print("Invalid entry. Appointment must be in the future. Try again!")
        continue
python concurrency future appointment
1个回答
0
投票

一般来说,您可以通过以下方法确定所请求的预约是否与任何其他现有预约重叠。

  1. 循环每个现有约会。
  2. 如果请求的约会开始时间介于现有约会的开始和结束时间之间,或者请求的约会的结束时间介于现有约会的开始和结束时间之间,则两个约会重叠。
  3. 如果您没有发现任何此类重叠,则所请求的预约不会与任何其他现有预约重叠。
© www.soinside.com 2019 - 2024. All rights reserved.