在工作日(周一至周五),周六,周日中的时间间隔

时间:2020-08-12 07:54:24

标签: python-3.x datetime time calendar settimeinterval

  1. 工作日中从00到08、08到16、16到21、21到24的拆分时间
  2. 将星期六的时间分为两种,从8点到12点,其余时间为一个时间
  3. 全日制单一类型
from datetime import date,time
import calendar

now = date.today()
start_time = input("Enter the start time: ".format("%H:%M"))
end_time = input("Enter the end time: ".format("%H:%M"))

def timeline(start_time,end_time):
    current_time = now.strftime("%H:%M")
>*to display all time in sunday as full-over time*
    for calendar.SUNDAY in current_time:
        if start_time == time(0, 0) and end_time == time(23, 59): return "Full-over time in Sundays"
>*to split and display time interval in saturdays*     
    for calendar.SATURDAY in current_time:
        if start_time >= time(8, 00) and end_time <= time(11, 59): return "Half-Over time in saturdays"
        else: return "Full-over time in Saturdays"
>*to split and display time interval in weekdays for example in Monday*
    for calendar.MONDAY in current_time:
        if start_time >= time(8,00) and end_time <= time(15,59): return "Normal weekday hour"
        elif start_time >= time(16,00) and end_time <= time(20,59): return "Half-Over weekday"
        else: return "Full-Over weekday"

    return current_time

print(timeline)

代码未执行,我将非常感谢您提供的有关解决此代码或进行任何更改的帮助

0 个答案:

没有答案