當前位置: 首頁>>代碼示例>>Python>>正文


Python dates.format_timedelta方法代碼示例

本文整理匯總了Python中babel.dates.format_timedelta方法的典型用法代碼示例。如果您正苦於以下問題:Python dates.format_timedelta方法的具體用法?Python dates.format_timedelta怎麽用?Python dates.format_timedelta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在babel.dates的用法示例。


在下文中一共展示了dates.format_timedelta方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: format_datetime

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def format_datetime(d):
    from dateutil.tz import tzutc
    from babel import dates
    d = d.replace(microsecond=0)
    if not USING_PYTHON2:
        # Switch from UTC to local TZ
        d = d.astimezone(tz=None)
    return dates.format_timedelta(d - datetime.now(tzutc()), add_direction=True) 
開發者ID:kislyuk,項目名稱:aegea,代碼行數:10,代碼來源:printing.py

示例2: format_cell

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def format_cell(cell):
    if isinstance(cell, datetime):
        cell = format_datetime(cell)
    if isinstance(cell, timedelta):
        from babel import dates
        cell = dates.format_timedelta(-cell, add_direction=True)
    if isinstance(cell, (list, dict)):
        cell = json.dumps(cell, default=lambda x: str(x))
    return cell 
開發者ID:kislyuk,項目名稱:aegea,代碼行數:11,代碼來源:printing.py

示例3: deltatimeformat

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def deltatimeformat(t):
    return dates.format_timedelta(t - datetime.now(), add_direction=True) 
開發者ID:techx,項目名稱:cog,代碼行數:4,代碼來源:utils.py

示例4: format_timedelta

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def format_timedelta(self, datetime_or_timedelta, granularity='second',
                         threshold=.85):
        """Formats the elapsed time from the given date to now or the given
        timedelta. This currently requires an unreleased development version
        of Babel.

        :param datetime_or_timedelta:
            A ``timedelta`` object representing the time difference to format,
            or a ``datetime`` object in UTC.
        :param granularity:
            Determines the smallest unit that should be displayed, the value
            can be one of "year", "month", "week", "day", "hour", "minute" or
            "second".
        :param threshold:
            Factor that determines at which point the presentation switches to
            the next higher unit.
        :returns:
            A string with the elapsed time.
        """
        if isinstance(datetime_or_timedelta, datetime.datetime):
            datetime_or_timedelta = datetime.datetime.utcnow() - \
                datetime_or_timedelta

        return dates.format_timedelta(datetime_or_timedelta, granularity,
                                      threshold=threshold,
                                      locale=self.locale) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:28,代碼來源:i18n.py

示例5: uptime

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def uptime(caller):

	delta = datetime.datetime.utcnow() - globals.server.started

	caller.connection.notify(caller.connection._("This server has been running for %s.")%(format_timedelta(delta, locale=caller.connection.player.get_locale())))

	if globals.rebooting:
		caller.connection.notify(caller.connection._("This server is going to reboot soon.")) 
開發者ID:tspivey,項目名稱:yugioh-game,代碼行數:10,代碼來源:lobby_parser.py

示例6: cmd_ro

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def cmd_ro(message: types.Message, chat: Chat):
    duration = await parse_timedelta_from_message(message)
    if not duration:
        return

    try:  # Apply restriction
        await message.chat.restrict(
            message.reply_to_message.from_user.id, can_send_messages=False, until_date=duration
        )
        logger.info(
            "User {user} restricted by {admin} for {duration}",
            user=message.reply_to_message.from_user.id,
            admin=message.from_user.id,
            duration=duration,
        )
    except exceptions.BadRequest as e:
        logger.error("Failed to restrict chat member: {error!r}", error=e)
        return False

    await message.reply_to_message.answer(
        _("<b>Read-only</b> activated for user {user}. Duration: {duration}").format(
            user=message.reply_to_message.from_user.get_mention(),
            duration=format_timedelta(
                duration, locale=chat.language, granularity="seconds", format="short"
            ),
        )
    )
    return True 
開發者ID:aiogram,項目名稱:bot,代碼行數:30,代碼來源:simple_admin.py

示例7: cmd_ban

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def cmd_ban(message: types.Message, chat: Chat):
    duration = await parse_timedelta_from_message(message)
    if not duration:
        return

    try:  # Apply restriction
        await message.chat.kick(message.reply_to_message.from_user.id, until_date=duration)
        logger.info(
            "User {user} kicked by {admin} for {duration}",
            user=message.reply_to_message.from_user.id,
            admin=message.from_user.id,
            duration=duration,
        )
    except exceptions.BadRequest as e:
        logger.error("Failed to kick chat member: {error!r}", error=e)
        return False

    await message.reply_to_message.answer(
        _("User {user} <b>banned</b> for {duration}").format(
            user=message.reply_to_message.from_user.get_mention(),
            duration=format_timedelta(
                duration, locale=chat.language, granularity="seconds", format="short"
            ),
        )
    )
    return True 
開發者ID:aiogram,項目名稱:bot,代碼行數:28,代碼來源:simple_admin.py

示例8: uptime

# 需要導入模塊: from babel import dates [as 別名]
# 或者: from babel.dates import format_timedelta [as 別名]
def uptime(message):
    """
    Processes uptime commands in the messages
    :param message: message to process
    :return:
    """

    logger = logging.getLogger(__name__)

    msgdetail = stampy.stampy.getmsgdetail(message)

    chat_id = msgdetail["chat_id"]
    message_id = msgdetail["message_id"]

    datelast = stampy.stampy.utize(dateutil.parser.parse(stampy.plugin.config.config(key='uptime', gid=0)))
    datelastfor = datelast.strftime('%Y/%m/%d %H:%M:%S')
    datelastts = time.mktime(datelast.timetuple())
    date = stampy.stampy.utize(datetime.datetime.now())
    datefor = date.strftime('%Y/%m/%d %H:%M:%S')
    dateforts = time.mktime(date.timetuple())
    elapsed = dateforts - datelastts

    text = _("Bot was started at: %s\n") % datelastfor
    text += _("Now it is: %s\n") % datefor
    text += _("Elapsed time: %s (seconds)\n") % elapsed
    text += _("Elapsed time: %s \n") % format_timedelta(datetime.timedelta(seconds=elapsed), locale=stampy.stampy.language)

    logger.debug(msg=_L("Returning %s") % text)

    stampy.stampy.sendmessage(chat_id=chat_id, text=text,
                              reply_to_message_id=message_id,
                              disable_web_page_preview=True,
                              parse_mode='markdown')
    return 
開發者ID:iranzo,項目名稱:stampython,代碼行數:36,代碼來源:uptime.py


注:本文中的babel.dates.format_timedelta方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。