Beispiel #1
0
def test_get_timezone_location():
    tz = timezone('America/St_Johns')
    assert (dates.get_timezone_location(
        tz, locale='de_DE') == u"Kanada (St. John\u2019s) Zeit")
    tz = timezone('America/Mexico_City')
    assert (dates.get_timezone_location(
        tz, locale='de_DE') == u'Mexiko (Mexiko-Stadt) Zeit')

    tz = timezone('Europe/Berlin')
    assert (dates.get_timezone_name(
        tz, locale='de_DE') == u'Mitteleurop\xe4ische Zeit')
Beispiel #2
0
def test_get_timezone_location():
    tz = timezone('America/St_Johns')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u"Kanada (St. John's) Zeit")
    tz = timezone('America/Mexico_City')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u'Mexiko (Mexiko-Stadt) Zeit')

    tz = timezone('Europe/Berlin')
    assert (dates.get_timezone_name(tz, locale='de_DE') ==
            u'Mitteleurop\xe4ische Zeit')
Beispiel #3
0
def test_get_timezone_location():
    tz = timezone('America/St_Johns')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u"Kanada (St. John\u2019s) Zeit")
    tz = timezone('America/Mexico_City')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u'Mexiko (Mexiko-Stadt) Zeit')

    tz = timezone('Europe/Berlin')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u'Deutschland (Berlin) Zeit')
Beispiel #4
0
def test_get_timezone_location():
    tz = timezone('America/St_Johns')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u"Kanada (St. John\u2019s) Zeit")
    assert (dates.get_timezone_location(tz, locale='en') ==
            u'Canada (St. John’s) Time')
    assert (dates.get_timezone_location(tz, locale='en', return_city=True) ==
            u'St. John’s')

    tz = timezone('America/Mexico_City')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u'Mexiko (Mexiko-Stadt) Zeit')

    tz = timezone('Europe/Berlin')
    assert (dates.get_timezone_location(tz, locale='de_DE') ==
            u'Deutschland (Berlin) Zeit')
Beispiel #5
0
def get_timezones():
    user = get_user()
    lang = user.get("language",
                    flask.current_app.config.get("DEFAULT_LANGUAGE",
                                                 "en")).replace("-", "_")
    return [{
        "id": tz,
        "name": dates.get_timezone_name(tz, locale=lang),
        "location": dates.get_timezone_location(tz, locale=lang),
    } for tz in pytz.common_timezones]
Beispiel #6
0
def get_timezones():
    user = get_user()
    lang = user.get('language',
                    flask.current_app.config.get('DEFAULT_LANGUAGE',
                                                 'en')).replace('-', '_')
    return [{
        'id': tz,
        'name': dates.get_timezone_name(tz, locale=lang),
        'location': dates.get_timezone_location(tz, locale=lang),
    } for tz in pytz.common_timezones]
Beispiel #7
0
def _localize_timezone(zone: str, aliases: List[str], locale: babel.Locale,
                       collator: Collator) -> LocalizedTimezone:
    tzinfo = pytz.timezone(zone)
    name = get_timezone_location(tzinfo, locale=locale)
    name_sort_key = collator.getSortKey(name)
    return LocalizedTimezone(
        id=zone,
        name=name,
        aliases=aliases,
        name_sort_key=name_sort_key,
        tzinfo=tzinfo,
        locale=locale,
    )
Beispiel #8
0
    def get_timezone_location(self, dt_or_timezone=None, return_city=False):
        """Return a representation of the given timezone using "location format"

        The result depends on both the local display name of the country and the
        city associated with the time zone

        In:
          - ``dt_or_tzinfo`` -- ``datetime`` or ``tzinfo`` object that determines
            the timezone; if `None`, the current date and time in UTC is assumed
          - ``return_city`` -- Is the city (location) for the time zone to be included?

        Return:
          - the timezone representation
        """
        return dates.get_timezone_location(dt_or_timezone, self, return_city)
Beispiel #9
0
def list_timezones(locale=None):
    from ilog.application import get_request
    if not locale:
        request = get_request()
        if not request:
            locale = 'en'
        else:
            locale = request.locale

    if str(locale) not in TIMEZONES:
        result = [(x, get_timezone_location(timezone(x), locale))
                  for x in common_timezones]
        result.sort(key=lambda x: x[1].lower())
        TIMEZONES[str(locale)] = result
    return TIMEZONES[str(locale)]
Beispiel #10
0
    def get_timezone_location(self, dt_or_timezone=None):
        """Return a representation of the given timezone using "location format"

        The result depends on both the local display name of the country and the
        city associated with the time zone:

        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')
        >>> Locale('de', 'DE').get_timezone_location(tz)
        u"Kanada (St. John's)"
        >>> tz = timezone('America/Mexico_City')
        >>> Locale('de', 'DE').get_timezone_location(tz)
        u'Mexiko (Mexiko-Stadt)'

        In:
          - ``dt_or_tzinfo`` -- ``datetime`` or ``tzinfo`` object that determines
            the timezone; if `None`, the current date and time in UTC is assumed

        Return:
          - the timezone representation
        """
        return dates.get_timezone_location(dt_or_timezone, self)
Beispiel #11
0
def get_timezone_local_name(tz):
    code = getattr(settings, 'LANGUAGE_CODE', get_language())
    locale = Locale.parse(code, sep='-')
    return get_timezone_location(tz, locale=locale)
Beispiel #12
0
from collections import OrderedDict

from babel.dates import get_timezone_location
from pytz import common_timezones_set

from .tools import format_gmt_offset, get_gmt_offset

timezones = common_timezones_set - {'UTC'}

__TIMEZONES_DICT = OrderedDict()
__tz_offset_tz_name_map = {}

for tz_name in timezones:
    gmt_offset = get_gmt_offset(tz_name)
    tz_locale_name = get_timezone_location(tz_name,
                                           locale='ru',
                                           return_city=True)
    first_tz_name = __tz_offset_tz_name_map.setdefault(gmt_offset, tz_name)
    if __TIMEZONES_DICT.setdefault(first_tz_name,
                                   [tz_locale_name]) != [tz_locale_name]:
        if tz_locale_name not in __TIMEZONES_DICT[first_tz_name]:
            __TIMEZONES_DICT[first_tz_name].append(tz_locale_name)

TIMEZONES = []
for tz_name, tz_locale_names in __TIMEZONES_DICT.items():
    tz_locale_names = sorted(tz_locale_names)
    for tz_locale_name in tz_locale_names:
        TIMEZONES.append([
            tz_name,
            "(GMT%s) %s" %
            (format_gmt_offset(get_gmt_offset(tz_name)), tz_locale_name)