コード例 #1
0
ファイル: date_time.py プロジェクト: Ictp/indico
def format_date(d, format='medium', locale=None):
    """
    Basically a wrapper around Babel's own format_date
    """
    if not locale:
        locale = currentLocale()

    return _format_date(d, format=format, locale=locale).encode('utf-8')
コード例 #2
0
def format_date(d, format='medium', locale=None):
    """
    Basically a wrapper around Babel's own format_date
    """
    if not locale:
        locale = currentLocale()

    return _format_date(d, format=format, locale=locale).encode('utf-8')
コード例 #3
0
ファイル: dates.py プロジェクト: jeronimoalbi/duende
def format_date(date, format=MEDIUM):
    """Format date using current locale"""

    if not date:
        return date

    locale = get_current_locale_code()

    return _format_date(date, format=format, locale=locale)
コード例 #4
0
def format_date(d, format='medium', locale=None, timezone=None):
    """Basically a wrapper around Babel's own format_date."""
    if format == 'code':
        format = 'dd/MM/yyyy'
    if not locale:
        locale = get_current_locale()
    if timezone and isinstance(d, datetime) and d.tzinfo:
        d = d.astimezone(pytz.timezone(timezone) if isinstance(timezone, str) else timezone)

    return _format_date(d, format=format, locale=locale)
コード例 #5
0
ファイル: date_time.py プロジェクト: fph/indico
def format_date(d, format='medium', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_date
    """
    if format == 'code':
        format = 'dd/MM/yyyy'
    if not locale:
        locale = get_current_locale()
    if timezone and isinstance(d, datetime) and d.tzinfo:
        d = d.astimezone(pytz.timezone(timezone) if isinstance(timezone, basestring) else timezone)
    return _format_date(d, format=format, locale=locale).encode('utf-8')
コード例 #6
0
ファイル: i18n.py プロジェクト: SmallsLIVE/mediadrop
def format_date(date=None, format='medium'):
    """Return a date formatted according to the given pattern.

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

    :param date: the ``date`` or ``datetime`` object; if `None`, the current
                 date is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :rtype: `unicode`
    """
    return _format_date(date, format, translator.locale)
コード例 #7
0
ファイル: i18n.py プロジェクト: sudheesh001/mediadrop
def format_date(date=None, format='medium'):
    """Return a date formatted according to the given pattern.

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

    :param date: the ``date`` or ``datetime`` object; if `None`, the current
                 date is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :rtype: `unicode`
    """
    return _format_date(date, format, pylons.translator.locale)
コード例 #8
0
def format_date(d, format='medium', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_date
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if timezone and isinstance(d, datetime) and d.tzinfo:
        d = d.astimezone(pytz.timezone(timezone) if isinstance(timezone, basestring) else timezone)

    rv = _format_date(d, format=format, locale=locale)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')