Exemplo n.º 1
0
def format_timedelta(td, format='short', threshold=0.85, locale=None):
    """
    Basically a wrapper around Babel's own format_timedelta
    """
    if not locale:
        locale = get_current_locale()

    return _format_timedelta(td, format=format, locale=locale, threshold=threshold).encode('utf-8')
Exemplo n.º 2
0
def format_timedelta(td, format='short', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_timedelta
    """
    if not locale:
        locale = currentLocale()

    return _format_timedelta(td, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
Exemplo n.º 3
0
def format_timedelta(td, format='short', locale=None):
    """
    Basically a wrapper around Babel's own format_timedelta
    """
    if not locale:
        locale = get_current_locale()

    return _format_timedelta(td, format=format, locale=locale).encode('utf-8')
Exemplo n.º 4
0
def format_timedelta(td, format='short', threshold=0.85, locale=None):
    """Basically a wrapper around Babel's own format_timedelta."""
    if not locale:
        locale = get_current_locale()

    return _format_timedelta(td,
                             format=format,
                             locale=locale,
                             threshold=threshold)
def format_timedelta(td, format='short', threshold=0.85, locale=None):
    """
    Basically a wrapper around Babel's own format_timedelta
    """
    if not locale:
        locale = get_current_locale()

    rv = _format_timedelta(td, format=format, locale=locale, threshold=threshold)
    return inject_unicode_debug(rv, 2).encode('utf-8')
Exemplo n.º 6
0
def format_timedelta(
    delta,
    format="long",
    granularity="second",
    threshold=0.85,
    add_direction=False,
    locale=LC_TIME,
):
    """
    Return timedelta as a formatted string.

    Args:
        format (str, optional): Can be one of "long", "short", or "narrow". Defaults to
            `'long`'.
        granularity (str, optional): The smallest unit that should be displayed. The
            value can be one of "year", "month", "week", "day", "hour", "minute" or
            "second". Defaults to `'second'`.
        threshold (float, optional): Factor that determines at which point the
            presentation switches to the next higher unit. Defaults to `0.85`.
        add_direction (bool, optional): If ``True`` the return value will include
            directional information (e.g. `'1 hour ago'`, `'in 1 hour'`). Defaults to
            ``False``.
        locale (str|Locale, optional): A ``Locale`` object or locale identifier.
            Defaults to system default.

    Returns:
        str
    """
    if granularity not in TIMEDELTA_GRANULARITIES:
        units = ", ".join('"{0}"'.format(unit)
                          for unit in TIMEDELTA_GRANULARITIES)
        raise ValueError(
            'Time delta granularity must be one of {0}, not "{1}"'.format(
                units, granularity))

    if format not in TIMEDELTA_FORMATS:
        formats = ", ".join('"{0}"'.format(format)
                            for format in TIMEDELTA_FORMATS)
        raise ValueError(
            'Time delta format must be one of {0}, not "{1}"'.format(
                formats, format))

    return _format_timedelta(
        delta,
        granularity=granularity,
        threshold=threshold,
        add_direction=add_direction,
        format=format,
        locale=locale,
    )
Exemplo n.º 7
0
def format_timedelta(delta,
                     format='long',
                     granularity='second',
                     threshold=0.85,
                     add_direction=False,
                     locale=LC_TIME):
    """Return timedelta as a formatted string.

    Args:
        format (str, optional): Can be one of "long", "short", or "narrow".
            Defaults to `'long`'.
        granularity (str, optional): The smallest unit that should be
            displayed. The value can be one of "year", "month", "week",
            "day", "hour", "minute" or "second". Defaults to `'second'`.
        threshold (float, optional): Factor that determines at which point
            the presentation switches to the next higher unit. Defaults to
            `0.85`.
        add_direction (bool, optional): If ``True`` the return value will
            include directional information (e.g. `'1 hour ago'`,
            `'in 1 hour'`). Defaults to ``False``.
        locale (str|Locale, optional): A ``Locale`` object or locale
            identifer. Defaults to system default.

    Returns:
        str
    """
    if granularity not in TIMEDELTA_GRANULARITIES:
        units = ', '.join('"{0}"'.format(unit)
                          for unit in TIMEDELTA_GRANULARITIES)
        raise ValueError('Time delta granularity must be one of {0}, not "{1}"'
                         .format(units, granularity))

    if format not in TIMEDELTA_FORMATS:
        formats = ', '.join('"{0}"'.format(format)
                            for format in TIMEDELTA_FORMATS)
        raise ValueError('Time delta format must be one of {0}, not "{1}"'
                         .format(formats, format))

    return _format_timedelta(delta,
                             granularity=granularity,
                             threshold=threshold,
                             add_direction=add_direction,
                             format=format,
                             locale=locale)
Exemplo n.º 8
0
def format_timedelta(*args, **kwargs):
    return _format_timedelta(*args, locale=translation.getLocale(), **kwargs)
Exemplo n.º 9
0
def format_timedelta(*args, **kwargs):
    return _format_timedelta(*args, locale=translation.getLocale(), **kwargs).encode(getCurrentCharset())