本文整理汇总了Python中delorean.Delorean.next_monday方法的典型用法代码示例。如果您正苦于以下问题:Python Delorean.next_monday方法的具体用法?Python Delorean.next_monday怎么用?Python Delorean.next_monday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类delorean.Delorean
的用法示例。
在下文中一共展示了Delorean.next_monday方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_reply
# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import next_monday [as 别名]
def generate_reply(text, user_id):
if not is_valid(text):
reply_text = "Incorrect Format - Should be HH:MM (eg. 09:00 or 16:45)"
return create_json(reply_text, user_id)
hours = text[0:2]
minutes = text[3:5]
# Handle timezone
now = Delorean()
now.shift("Europe/London") # Currently only supports UK timezone
# If today is Monday and before our target time
if now.datetime.weekday() == 0 and (now.datetime.hour < int(hours) or (now.datetime.hour == int(hours) and now.datetime.minute < int(minutes))):
monday = now.datetime
else:
monday = now.next_monday().datetime
target = Delorean(datetime.datetime(monday.year, monday.month, monday.day, int(hours), int(minutes)), timezone='Europe/London')
# Calculate time
result = (target - now)
days_until = result.days
hours_until = result.seconds / 60 / 60
minutes_until = (result.seconds / 60) - (hours_until * 60)
# Format message
days_format = "day" if days_until == 1 else "days"
hours_format = "hour" if hours_until == 1 else "hours"
minutes_format = "minute" if minutes_until == 1 else "minutes"
reply_text = "{} {}, {} {} and {} {} until Monday at {}:{}.".format(days_until, days_format, hours_until, hours_format, minutes_until, minutes_format, hours, minutes)
return create_json(reply_text, user_id)