예제 #1
0
def test_get_timezone_converter():
    ' args: from_timezone '
    ' convert is always TO utc '
    from metrique.utils import utcnow, get_timezone_converter

    # note: caching timezones always takes a few seconds
    est = 'US/Eastern'
    EST = pytz.timezone(est)

    now_utc_tz = utcnow(tz_aware=True, as_datetime=True)
    now_utc = now_utc_tz.replace(tzinfo=None)

    now_est = copy(now_utc_tz)
    now_est_tz = now_est.astimezone(EST)
    now_est = now_est_tz.replace(tzinfo=None)

    assert get_timezone_converter(None) is None

    c = get_timezone_converter(est)
    assert c(None) is None
    assert c(now_est) == now_utc
    assert c(now_est_tz) == now_utc
    assert c(now_est_tz) == c(now_est)

    c = get_timezone_converter(est, tz_aware=True)
    assert c(now_est) == now_utc_tz
    assert c(now_est_tz) == c(now_est)
    assert c(now_est_tz) == now_utc_tz
예제 #2
0
def test_get_timezone_converter():
    ' args: from_timezone '
    ' convert is always TO utc '
    from metrique.utils import utcnow, get_timezone_converter

    # note: caching timezones always takes a few seconds
    est = 'US/Eastern'
    EST = pytz.timezone(est)

    now_utc_tz = utcnow(tz_aware=True, as_datetime=True)
    now_utc = now_utc_tz.replace(tzinfo=None)

    now_est = copy(now_utc_tz)
    now_est_tz = now_est.astimezone(EST)
    now_est = now_est_tz.replace(tzinfo=None)

    assert get_timezone_converter(None) is None

    c = get_timezone_converter(est)
    assert c(None) is None
    assert c(now_est) == now_utc
    assert c(now_est_tz) == now_utc
    assert c(now_est_tz) == c(now_est)

    c = get_timezone_converter(est, tz_aware=True)
    assert c(now_est) == now_utc_tz
    assert c(now_est_tz) == c(now_est)
    assert c(now_est_tz) == now_utc_tz
예제 #3
0
def get_timezone_converter():
    ' args: from_timezone '
    ' convert is always TO utc '
    from metrique.utils import get_timezone_converter

    # note: caching timezones always takes a few seconds
    good = 'US/Eastern'
    good_tz = pytz.timezone(good)

    now_utc = datetime.now(pytz.utc)

    now_est = copy(now_utc)
    now_est = now_est.astimezone(good_tz)
    now_est = now_est.replace(tzinfo=None)

    c = get_timezone_converter(good)
    assert c(None, now_est) == now_utc