コード例 #1
0
ファイル: test_dates.py プロジェクト: Givemore/fjord
def test_get_timezone_gmt():
    dt = datetime(2007, 4, 1, 15, 30)
    assert dates.get_timezone_gmt(dt, locale='en') == u'GMT+00:00'

    tz = timezone('America/Los_Angeles')
    dt = tz.localize(datetime(2007, 4, 1, 15, 30))
    assert dates.get_timezone_gmt(dt, locale='en') == u'GMT-07:00'
    assert dates.get_timezone_gmt(dt, 'short', locale='en') == u'-0700'

    assert dates.get_timezone_gmt(dt, 'long', locale='fr_FR') == u'UTC-07:00'
コード例 #2
0
def test_get_timezone_gmt():
    dt = datetime(2007, 4, 1, 15, 30)
    assert dates.get_timezone_gmt(dt, locale='en') == u'GMT+00:00'

    tz = timezone('America/Los_Angeles')
    dt = tz.localize(datetime(2007, 4, 1, 15, 30))
    assert dates.get_timezone_gmt(dt, locale='en') == u'GMT-07:00'
    assert dates.get_timezone_gmt(dt, 'short', locale='en') == u'-0700'

    assert dates.get_timezone_gmt(dt, 'long', locale='fr_FR') == u'UTC-07:00'
コード例 #3
0
ファイル: test_dates.py プロジェクト: fsys/babel
def test_get_timezone_gmt():
    dt = datetime(2007, 4, 1, 15, 30)
    assert dates.get_timezone_gmt(dt, locale='en') == 'GMT+00:00'

    tz = timezone('America/Los_Angeles')
    dt = datetime(2007, 4, 1, 15, 30, tzinfo=tz)
    assert dates.get_timezone_gmt(dt, locale='en') == 'GMT-08:00'
    assert dates.get_timezone_gmt(dt, 'short', locale='en') == '-0800'

    assert dates.get_timezone_gmt(dt, 'long', locale='fr_FR') == 'UTC-08:00'
コード例 #4
0
    def get_timezone_gmt(self, datetime=None, width='long', return_z=False):
        """Format the timezone associated with the given datetime

        In:
          - ``datetime`` -- the `datetime`
          - ``width`` -- 'long', 'short', 'iso8601' or 'iso8601_short'
          - ``return_z`` -- Have indicator 'Z' when local time offset is 0 to be included?

        Returns:
          - the formatted timezone
        """
        return dates.get_timezone_gmt(datetime, width, self, return_z)
コード例 #5
0
def _timestamp_localized_timezone(
        tz: LocalizedTimezone,
        dt: datetime.datetime) -> TimestampedLocalizedTimezone:
    localized_dt = tz.tzinfo.localize(dt)
    offset = get_timezone_gmt(localized_dt, locale=tz.locale)
    return TimestampedLocalizedTimezone(
        id=tz.id,
        name=tz.name,
        offset=offset,
        aliases=tz.aliases,
        sort_key=(localized_dt.utcoffset(), tz.name_sort_key),
    )
コード例 #6
0
ファイル: i18n.py プロジェクト: isaideureka/abilian-core
def timezones_choices():
    """Timezones values and their labels for current locale.

    :return: an iterable of `(code, label)`, code being a timezone code and label
    the timezone name in current locale.
    """
    utcnow = pytz.utc.localize(datetime.utcnow())
    locale = _get_locale()
    for tz in sorted(pytz.common_timezones):
        tz = get_timezone(tz)
        now = tz.normalize(utcnow.astimezone(tz))
        label = '({}) {}'.format(get_timezone_gmt(now, locale=locale), tz.zone)
        yield (tz, label)  # get_timezone_name(tz, locale=locale))
コード例 #7
0
ファイル: i18n.py プロジェクト: abilian/abilian-core
def timezones_choices():
    """Timezones values and their labels for current locale.

    :return: an iterable of `(code, label)`, code being a timezone code and label
    the timezone name in current locale.
    """
    utcnow = pytz.utc.localize(datetime.utcnow())
    locale = _get_locale()
    for tz in sorted(pytz.common_timezones):
        tz = get_timezone(tz)
        now = tz.normalize(utcnow.astimezone(tz))
        label = "({}) {}".format(get_timezone_gmt(now, locale=locale), tz.zone)
        yield (tz, label)  # get_timezone_name(tz, locale=locale))
コード例 #8
0
ファイル: i18n.py プロジェクト: nagareproject/core
    def get_timezone_gmt(self, dt=None, width='long'):
        """Return the timezone associated with the given ``dt`` datetime object, formatted as string indicating the offset from GMT

        >>> dt = datetime.datetime(2007, 4, 1, 15, 30)
        >>> Locale('en').get_timezone_gmt(dt)
        u'GMT+00:00'

        In:
          - ``datetime`` -- a ``datetime`` object; if ``None``, the current
            date and time in UTC is used
          - ``width`` -- either 'long' or 'short'

        Return:
          - The timezone
        """
        return dates.get_timezone_gmt(dt, width, self)
コード例 #9
0
ファイル: tzone.py プロジェクト: vb64/django.common
def name(tz, dt=None):
    if not dt:
        dt = datetime.now()
    return "{} {}".format(
        get_timezone_gmt(get_timezone(tz).localize(dt), width='iso8601_short'),
        tz)