Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(122)  |  Call(107)  |  Derive(0)  |  Import(15)
Return a time delta according to the rules of the given locale.

>>> format_timedelta(timedelta(weeks=12), locale='en_US')
u'3 months'
>>> format_timedelta(timedelta(seconds=1), locale='es')
u'1 segundo'

The granularity parameter can be provided to alter the lowest unit
presented, which defaults to a second.
(more...)

        def format_timedelta(delta, granularity='second', threshold=.85,
                     add_direction=False, format='medium',
                     locale=LC_TIME):
    """Return a time delta according to the rules of the given locale.

    >>> format_timedelta(timedelta(weeks=12), locale='en_US')
    u'3 months'
    >>> format_timedelta(timedelta(seconds=1), locale='es')
    u'1 segundo'

    The granularity parameter can be provided to alter the lowest unit
    presented, which defaults to a second.

    >>> format_timedelta(timedelta(hours=3), granularity='day',
    ...                  locale='en_US')
    u'1 day'

    The threshold parameter can be used to determine at which value the
    presentation switches to the next higher unit. A higher threshold factor
    means the presentation will switch later. For example:

    >>> format_timedelta(timedelta(hours=23), threshold=0.9, locale='en_US')
    u'1 day'
    >>> format_timedelta(timedelta(hours=23), threshold=1.1, locale='en_US')
    u'23 hours'

    In addition directional information can be provided that informs
    the user if the date is in the past or in the future:

    >>> format_timedelta(timedelta(hours=1), add_direction=True)
    u'In 1 hour'
    >>> format_timedelta(timedelta(hours=-1), add_direction=True)
    u'1 hour ago'

    :param delta: a ``timedelta`` object representing the time difference to
                  format, or the delta in seconds as an `int` value
    :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
    :param add_direction: if this flag is set to `True` the return value will
                          include directional information.  For instance a
                          positive timedelta will include the information about
                          it being in the future, a negative will be information
                          about the value being in the past.
    :param format: the format (currently only "medium" and "short" are supported)
    :param locale: a `Locale` object or a locale identifier
    """
    if format not in ('short', 'medium'):
        raise TypeError('Format can only be one of "short" or "medium"')
    if isinstance(delta, timedelta):
        seconds = int((delta.days * 86400) + delta.seconds)
    else:
        seconds = delta
    locale = Locale.parse(locale)

    def _iter_choices(unit):
        if add_direction:
            if seconds >= 0:
                yield unit + '-future'
            else:
                yield unit + '-past'
        yield unit + ':' + format
        yield unit

    for unit, secs_per_unit in TIMEDELTA_UNITS:
        value = abs(seconds) / secs_per_unit
        if value >= threshold or unit == granularity:
            if unit == granularity and value > 0:
                value = max(1, value)
            value = int(round(value))
            plural_form = locale.plural_form(value)
            pattern = None
            for choice in _iter_choices(unit):
                patterns = locale._data['unit_patterns'].get(choice)
                if patterns is not None:
                    pattern = patterns[plural_form]
                    break
            # This really should not happen
            if pattern is None:
                return u''
            return pattern.replace('{0}', str(value))

    return u''
        


src/w/e/webapp2_example-HEAD/lib/webapp2_extras/i18n.py   webapp2_example(Download)
                datetime_or_timedelta
 
        return dates.format_timedelta(datetime_or_timedelta, granularity,
                                      threshold=threshold,
                                      locale=self.locale)

src/f/j/fjord-HEAD/vendor/packages/Babel/babel/support.py   fjord(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
     format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
        u'3 months'
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold,
                                format=format, add_direction=add_direction,

src/z/e/ZenPacks.zenoss.OpenStack-HEAD/src/Babel-1.3/babel/support.py   ZenPacks.zenoss.OpenStack(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
     format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
        u'3 months'
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold,
                                format=format, add_direction=add_direction,

src/b/a/Babel-1.3/babel/support.py   Babel(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
     format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
        u'3 months'
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold,
                                format=format, add_direction=add_direction,

src/m/i/microblog-HEAD/flask/lib/python2.7/site-packages/babel/support.py   microblog(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
     format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
        u'3 months'
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold,
                                format=format, add_direction=add_direction,

src/p/r/proofofexistence-HEAD/babel/support.py   proofofexistence(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
     format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
        u'3 months'
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold,
                                format=format, add_direction=add_direction,

src/a/b/abilian-core-0.1.4/abilian/web/filters.py   abilian-core(Download)
from pytz import utc
from calendar import timegm
from babel.dates import DateTimePattern, format_timedelta, parse_pattern
import bleach
 
  # don't use (flask.ext.)babel.format_timedelta: as of Flask-Babel 0.9 it
  # doesn't support "threshold" arg.
  return format_timedelta((dt - now),
                          locale=babel.get_locale(),
                          granularity='minute',

src/v/e/veil-HEAD/src/veil/frontend/locale/l10n.py   veil(Download)
def timedelta_filter(delta, granularity='second', add_direction=False):
    if isinstance(delta, basestring):
        return delta
    return babel.dates.format_timedelta(delta, granularity=granularity, threshold=.95, add_direction=add_direction, locale=get_current_locale())
 

src/w/e/webapp-improved-HEAD/lib/babel/babel/support.py   webapp-improved(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
                        format_timedelta
from babel.numbers import format_number, format_decimal, format_currency, \
        :see: `babel.dates.format_timedelta`
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold, locale=self.locale)
 

src/p/l/plexnet-HEAD/third_party/python/babel/support.py   plexnet(Download)
 
from babel.core import Locale
from babel.dates import format_date, format_datetime, format_time, \
                        format_timedelta, LC_TIME
from babel.numbers import format_number, format_decimal, format_currency, \
        :see: `babel.dates.format_timedelta`
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold, locale=self.locale)
 

  1 | 2 | 3 | 4 | 5 | 6  Next