我在一个日历中使用以下代码,以告诉我离活动开始还有多长时间。有两部分,一部分显示离工作开始还有多长时间,另一部分显示我需要在什么时候起床上班。
work_alarm = timedelta(hours=2, minutes=30)
a_n = int((we_dt - tct).total_seconds() / 60) # to get minutes remaining from the current time to when work starts
alarm_time = we_dt - work_alarm
up_time = int((alarm_time - tct).total_seconds() / 60) # total minutes until I need to be up
print "Scheduled Work Time: " + str(we_dt.strftime('%H:%M'))
print "You have " + str(we[1]) + " in " + str(int((((we_dt - tct).total_seconds() / 60) / 60))) + " hours and " + str(divmod(a_n, 60)[1]) + " minutes."
print "You need to be up in " + str(int((((alarm_time - tct).total_seconds() / 60) / 60))) + " hours and " + str(divmod(up_time, 60)[1]) + " minutes."
一切都正常工作,直到“需要起床”的时间过去。当事件时间过去时,它将停止报告,因此这并不是真正的问题,但我想设置一种if语句来检查或告诉您是否需要起床的时间已经过去并停止显示它。因为目前情况是,一旦时间过去,它就开始倒数计时:例如,如果还有1分钟要起床,在零点后,它只会开始上涨:1、2、3分钟等等。该数字不会显示为负整数,因此我不知道如何对其进行比较,以便在时间过去后停止显示它。请注意,这个脚本每分钟使用一个apscheduler模块运行。任何帮助都将不胜感激。谢谢。
up_time
变量在接近唤醒时间时减少到0,然后在达到0后开始增加,那么你的代码中存在一个错误或逻辑错误。很难告诉你这个问题可能来自哪里,因为像tct
和we_dt
这样重要的变量在提供的代码中没有定义,也无法从它们的名称轻易猜出其内容。需要更多信息。 - Brian Peterson