def test_add_duration_1():
    # 2000-01-12T12:13:14Z	P1Y3M5DT7H10M3S	2001-04-17T19:23:17Z
    t = add_duration(str_to_time("2000-01-12T12:13:14Z"), "P1Y3M5DT7H10M3S")
    assert t.tm_year == 2001
    assert t.tm_mon == 4
    assert t.tm_mday == 17
    assert t.tm_hour == 19
    assert t.tm_min == 23
    assert t.tm_sec == 17
def test_add_duration_2():
    # 2000-01-12 PT33H   2000-01-13
    t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "PT33H")
    assert t.tm_year == 2000
    assert t.tm_mon == 1
    assert t.tm_mday == 14
    assert t.tm_hour == 9
    assert t.tm_min == 0
    assert t.tm_sec == 0
def test_add_duration_3():
    # 2000-01-12 PT33H   2000-01-13
    t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "P32D")
    assert t.tm_year == 2000
    assert t.tm_mon == 2
    assert t.tm_mday == 12
    assert t.tm_hour == 0
    assert t.tm_min == 0
    assert t.tm_sec == 0
    assert t.tm_wday == 5
    assert t.tm_wday == 5
    assert t.tm_yday == 43
    assert t.tm_isdst == 0
def test_str_to_time_1():
    t = str_to_time("")
    assert t == 0
def test_str_to_time_str_error():
    with pytest.raises(AttributeError):
        str_to_time("2000-01-12T00:00:00ZABC")
def test_a_while_ago():
    dt = time.mktime(time.gmtime())
    then = a_while_ago(seconds=10)
    t = time.mktime(str_to_time(then))
    delta = dt - t  # slightly less than 10
    assert 9 <= delta <= 10
def test_instant():
    inst = str_to_time(instant())
    now = time.gmtime()

    assert now >= inst
def test_str_to_time():
    t = calendar.timegm(str_to_time("2000-01-12T00:00:00Z"))
    assert t == 947635200
def test_add_duration_4():
    # 2000-01-12 PT33H   2000-01-13
    t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "-P32D")
    assert t is None