当前位置: 首页>>代码示例>>Python>>正文


Python Delorean.next_monday方法代码示例

本文整理汇总了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)
开发者ID:danstewart,项目名称:mondaybot,代码行数:34,代码来源:response.py


注:本文中的delorean.Delorean.next_monday方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。