Esempio n. 1
0
def format_time(t,
                format='short',
                locale=None,
                timezone=None,
                server_tz=False,
                as_unicode=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE
    if isinstance(timezone, basestring):
        timezone = get_timezone(timezone)
    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    if as_unicode:
        return rv
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
Esempio n. 2
0
def format_time(t, format='short', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_time
    """
    if not locale:
        locale = currentLocale()

    return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
Esempio n. 3
0
def format_time(t, format='short', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_time
    """
    if not locale:
        locale = currentLocale()

    return _format_time(t, format=format, locale=locale,
                        tzinfo=timezone).encode('utf-8')
Esempio n. 4
0
def format_time(time, format=MEDIUM):
    """Format time using current locale"""

    if not time:
        return time

    locale = get_current_locale_code()

    return _format_time(time, format=format, locale=locale)
Esempio n. 5
0
def format_time(time=None, format='medium', tzinfo=None):
    """Return a time formatted according to the given pattern.

    This uses the locale of the current request's ``pylons.translator``.

    :param time: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the time-zone to apply to the time for display
    :rtype: `unicode`
    """
    return _format_time(time, format, tzinfo, translator.locale)
def format_time(t, format='short', locale=None, timezone=None, server_tz=False):
    """Basically a wrapper around Babel's own format_time."""
    if format == 'code':
        format = 'HH:mm'
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE
    if isinstance(timezone, str):
        timezone = get_timezone(timezone)
    return _format_time(t, format=format, locale=locale, tzinfo=timezone)
Esempio n. 7
0
def format_time(time=None, format='medium', tzinfo=None):
    """Return a time formatted according to the given pattern.

    This uses the locale of the current request's ``pylons.translator``.

    :param time: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the time-zone to apply to the time for display
    :rtype: `unicode`
    """
    return _format_time(time, format, tzinfo, translator.locale)
Esempio n. 8
0
def format_time(t, format='short', locale=None, timezone=None, server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    if not locale:
        locale = currentLocale()
    if not timezone and t.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone()
    if timezone:
        timezone = get_timezone(timezone)

    return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
Esempio n. 9
0
def format_time(t, format='short', locale=None, timezone=None, server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    if format == 'code':
        format = 'HH:mm'
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = Config.getInstance().getDefaultTimezone()
    if timezone:
        timezone = get_timezone(timezone)

    return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
Esempio n. 10
0
def format_time(t, format='short', locale=None, timezone=None, server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE
    if isinstance(timezone, basestring):
        timezone = get_timezone(timezone)
    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
Esempio n. 11
0
def format_time(t,
                format='short',
                locale=None,
                timezone=None,
                server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone()
    if timezone:
        timezone = get_timezone(timezone)

    return _format_time(t, format=format, locale=locale,
                        tzinfo=timezone).encode('utf-8')
Esempio n. 12
0
def format_time(t,
                format='short',
                locale=None,
                timezone=None,
                server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = Config.getInstance().getDefaultTimezone()
    if timezone:
        timezone = get_timezone(timezone)

    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')