Exemplo n.º 1
0
def test_tz_daylight():
    """
    Return 1 if the timezone has a DST definition, else 0
    """
    pytest.debug_func()
    lz = nldt.timezone('US/Central')
    assert lz.daylight() == 1
    hz = nldt.timezone('US/Hawaii')
    assert hz.daylight() == 0
Exemplo n.º 2
0
def test_tz_tzname():
    """
    Method tzname() returns a tuple containing the abbreviated timezone names.
    Method zone() returns the name used to initialize the object.
    """
    pytest.debug_func()
    inp = 'US/Mountain'
    lz = nldt.timezone(inp)
    assert lz.tzname() == ('MST', 'MDT')
    assert lz.zone() == inp
Exemplo n.º 3
0
def test_tz_altzone():
    """
    The altzone() method returns the value of time.altzone:

        UTC + self.altzone() => local DST

    The dst_offset() method returns the inverse offset:

        local DST + self.dst_offset() => UTC
    """
    pytest.debug_func()
    lz = nldt.timezone('US/Pacific')
    assert lz.altzone() == 25200
    assert lz.dst_offset() == -25200
    assert lz.altzone() == -1 * lz.dst_offset()
Exemplo n.º 4
0
def test_tz_timezone():
    """
    The timezone() method returns the value of time.timezone:

        UTC + self.timezone() => local time

    The std_offset() method returns the inverse offset:

        local time + self.std_offset() => UTC
    """
    pytest.debug_func()
    lz = nldt.timezone('US/Eastern')
    exp = 18000
    assert lz.timezone() == exp
    assert lz.std_offset() == -1 * exp
    assert lz.altzone() == exp - 3600
    assert lz.dst_offset() == -1 * (exp - 3600)
    assert lz.timezone() == -1 * lz.std_offset()
Exemplo n.º 5
0
def test_tz_constructor(inp, exp):
    """
    The class local should have a constructor that accepts the name of a
    timezone, calls tzset(), and records the resulting values from
    time.{timezone,altzone,daylight,tzname} and then is able to return them on
    request.

    We should be able to have multiple local objects active at the same time.

    The local object should be able to report which timezone designator
    ('US/Eastern', 'Asia/Jakarta') it was initialized with.
    """
    pytest.debug_func()
    lz = nldt.timezone(inp)
    assert hasattr(lz, '_zone')         # contains the tzinfo struct from pytz
    assert hasattr(lz, 'timezone')      # reports std utc offset in seconds
    assert hasattr(lz, 'std_offset')    # alias for timezone
    assert hasattr(lz, 'altzone')       # reports dst utc offset in seconds
    assert hasattr(lz, 'dst_offset')    # alias for altzone
    assert hasattr(lz, 'daylight')      # reports whether dst supported for tz
    assert hasattr(lz, 'tzname')        # short timezone name
    assert hasattr(lz, 'zone')          # input (long) timezone name
    assert lz._zone == exp