Example #1
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')
Example #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')
Example #3
0
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)
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)
Example #5
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, basestring) else timezone)
    return _format_date(d, format=format, locale=locale).encode('utf-8')
Example #6
0
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)
Example #7
0
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)
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')