Esempio n. 1
0
def test_policies() -> None:
    getzone = lambda dt: getattr(dt.tzinfo, 'zone')

    naive = D('20170730 10:00:00')
    # actual timezone at the time
    assert getzone(TZ.localize(naive)) == 'Europe/Rome'

    z = pytz.timezone('America/New_York')
    aware = z.localize(naive)

    assert getzone(TZ.localize(aware)) == 'America/New_York'

    assert getzone(TZ.localize(aware, policy='convert')) == 'Europe/Rome'

    with pytest.raises(RuntimeError):
        assert TZ.localize(aware, policy='throw')
Esempio n. 2
0
def test_past() -> None:
    # should fallback to the home location provider
    dt = D('20000101 12:34:45')
    dt = TZ.localize(dt)
    tz = dt.tzinfo
    assert tz is not None
    assert getattr(tz, 'zone') == 'America/New_York'
Esempio n. 3
0
def test_future() -> None:
    fut = datetime.now() + timedelta(days=100)
    # shouldn't crash at least
    assert TZ.localize(fut) is not None