Beispiel #1
0
def test_tfrac_years_01_Alice_Springs():
    # Australia/North (UTC+09:30, never DST)
    with set_timezone(ALICE_SPRINGS):
        t = 3601
        (base, frac) = tfrac(t, years=1)
        assert base == 3600 * -9.5  # Alice Springs year start UTC timestamp
        assert frac == 3600 * 10.5 + 1  # 10:30:01 in the morning Jan 1
Beispiel #2
0
def test_tfrac_milliseconds_05():
    t = 1.0078056
    # Note that the last digit is lost due to rounding to microsecond scale.
    (base, frac) = tfrac(t, milliseconds=1)
    print base, frac
    assert base == 1.007
    assert frac == 0.000806
Beispiel #3
0
def test_tfrac_hours_05_Alice_Springs():
    # Australia/North (UTC+09:30, never DST)
    with set_timezone(ALICE_SPRINGS):
        t = 3600 * 15.5
        (base, frac) = tfrac(t, hours=6)
        assert base == 3600 * 14.5
        assert frac == 3600 *  1.0
Beispiel #4
0
def test_tfrac_years_01_Honolulu():
    # Pacific/Honolulu (UTC-10:00, never DST)
    with set_timezone(HONOLULU):
        t = 3601
        (base, frac) = tfrac(t, years=1)
        assert base == 3600 * (-365*24 + 10)  # previous Honolulu year start UTC timestamp
        assert frac == 3600 * (364*24 + 15) + 1  # 15:00:01 in the afternoon, Dec 31
Beispiel #5
0
def test_tfrac_days_02_Honolulu():
    # Pacific/Honolulu (UTC-10:00, never DST)
    with set_timezone(HONOLULU):
        t = 3*24.0*3600 + 1000.0
        (base, frac) = tfrac(t, days=1)
        assert base == 3600 * (24 * 2 + 10)
        assert frac == 3600 * (24 - 10) + 1000
Beispiel #6
0
def test_tfrac_hours_02_Alice_Springs():
    # Australia/North (UTC+09:30, never DST)
    with set_timezone(ALICE_SPRINGS):
        t = 3601
        (base, frac) = tfrac(t, hours=2)
        assert base == 1800
        assert frac == 1801
Beispiel #7
0
def test_tfrac_days_01_Honolulu():
    # Pacific/Honolulu (UTC-10:00, never DST)
    with set_timezone(HONOLULU):
        t = 3601
        (base, frac) = tfrac(t, days=1)
        assert base == 3600 * (-24 + 10)  # previous Honolulu day start UTC timestamp
        assert frac == 3600 * 15 + 1  # 15:00:01 in the afternoon
Beispiel #8
0
def test_tfrac_days_02_Alice_Springs():
    # Australia/North (UTC+09:30, never DST)
    with set_timezone(ALICE_SPRINGS):
        t = 3*24.0*3600 + 1000.0
        (base, frac) = tfrac(t, days=1)
        assert base == 3600 * (24 * 3 - 9.5)
        assert frac == 3600 * 9.5 + 1000
Beispiel #9
0
def test_tfrac_years_02_Honolulu():
    # Pacific/Honolulu (UTC-10:00, never DST)
    with set_timezone(HONOLULU):
        t = 3601
        (base, frac) = tfrac(t, years=10)
        # previous Honolulu decade start UTC timestamp (including leap years)
        assert base == 3600 * (-(365*10 + 3)*24 + 10)
        # 15:00:01 in the afternoon, Dec 31, 9 years into decade
        assert frac == 3600 * ((365*9+3 + 364)*24 + 15) + 1
Beispiel #10
0
def test_tfrac_hours_05():
    t = 3600 * 15.5
    (base, frac) = tfrac(t, hours=6)
    assert base == 3600 * 12.0
    assert frac == 3600 *  3.5
Beispiel #11
0
def test_tfrac_seconds_02():
    t = 1.75
    (base, frac) = tfrac(t, seconds=1)
    assert base == 1
    assert frac == 0.75
Beispiel #12
0
def test_tfrac_milliseconds_01():
    t = 123.5
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 123.5
    assert frac == 0.0
Beispiel #13
0
def test_tfrac_hours_01():
    t = 3601
    (base, frac) = tfrac(t, hours=1)
    assert base == 3600
    assert frac == 1
Beispiel #14
0
def test_tfrac_hours_04():
    t = 3600 * 5.5
    (base, frac) = tfrac(t, hours=3)
    assert base == 3600 * 3.0
    assert frac == 3600 * 2.5
Beispiel #15
0
def test_tfrac_hours_05():
    t = 3600 * 15.5
    (base, frac) = tfrac(t, hours=6)
    assert base == 3600 * 12.0
    assert frac == 3600 * 3.5
Beispiel #16
0
def test_tfrac_hours_02():
    t = 3601
    (base, frac) = tfrac(t, hours=2)
    assert base == 0
    assert frac == 3601
Beispiel #17
0
def test_tfrac_hours_03():
    t = 3600 * 5.5
    (base, frac) = tfrac(t, hours=2)
    assert base == 3600 * 4
    assert frac == 3600 * 1.5
Beispiel #18
0
def test_tfrac_hours_01():
    t = 3601
    (base, frac) = tfrac(t, hours=1)
    assert base == 3600
    assert frac == 1
Beispiel #19
0
def test_tfrac_days_02():
    # Not sure this test is useful. --WW
    t = time.mktime(time.gmtime(0)) + 3 * 24.0 * 3600 + 1000.0
    (base, frac) = tfrac(t, days=1)
    assert base == t - 1000.0
    assert frac == 1000.0
Beispiel #20
0
def test_tfrac_days_01():
    # Not sure this test is useful. --WW
    t = time.mktime(time.gmtime(0))
    (base, frac) = tfrac(t, days=1)
    assert base == t
    assert frac == 0.0
Beispiel #21
0
def test_tfrac_hours_05():
    with set_timezone(UTC):
        t = 3600 * 15.5
        (base, frac) = tfrac(t, hours=6)
        assert base == 3600 * 12.0
        assert frac == 3600 *  3.5
def test_tfrac_milliseconds_02():
    t = 10.0625
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 10.062
    assert frac == 0.0005
Beispiel #23
0
def test_tfrac_hours_03():
    t = 3600 * 5.5
    (base, frac) = tfrac(t, hours=2)
    assert base == 3600 * 4
    assert frac == 3600 * 1.5
def test_tfrac_milliseconds_03():
    t = 10.0625
    (base, frac) = tfrac(t, milliseconds=10)
    assert base == 10.06
    assert frac == 0.0025
Beispiel #25
0
def test_tfrac_milliseconds_03():
    t = 10.0625
    (base, frac) = tfrac(t, milliseconds=10)
    assert base == 10.06
    assert frac ==  0.0025
def test_tfrac_milliseconds_05():
    t = 1.0078056
    # Note that the last digit is lost due to rounding to microsecond scale.
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 1.007
    assert frac == 0.000806
Beispiel #27
0
def test_tfrac_seconds_01():
    t = 3601
    (base, frac) = tfrac(t, seconds=1)
    assert base == 3601
    assert frac == 0
Beispiel #28
0
def test_tfrac_years_02():
    with set_timezone(UTC):
        t = 3601
        (base, frac) = tfrac(t, years=10)
        assert base == 0
        assert frac == 3601
Beispiel #29
0
def test_tfrac_milliseconds_01():
    t = 123.5
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 123.5
    assert frac == 0.0
Beispiel #30
0
def test_tfrac_days_01():
    with set_timezone(UTC):
        t = 3601
        (base, frac) = tfrac(t, days=1)
        assert base == 0
        assert frac == 3601
Beispiel #31
0
def test_tfrac_days_01():
    with set_timezone(UTC):
        t = 3601
        (base, frac) = tfrac(t, days=1)
        assert base == 0
        assert frac == 3601
Beispiel #32
0
def test_tfrac_hours_02():
    with set_timezone(UTC):
        t = 3601
        (base, frac) = tfrac(t, hours=2)
        assert base == 0
        assert frac == 3601
Beispiel #33
0
def test_tfrac_days_02():
    with set_timezone(UTC):
        t = 3*24.0*3600 + 1000.0
        (base, frac) = tfrac(t, days=1)
        assert base == 3600 * 24 * 3
        assert frac == 1000
Beispiel #34
0
def test_tfrac_hours_03():
    with set_timezone(UTC):
        t = 3600 * 5.5
        (base, frac) = tfrac(t, hours=2)
        assert base == 3600 * 4
        assert frac == 3600 * 1.5
Beispiel #35
0
def test_tfrac_days_02():
    with set_timezone(UTC):
        t = 3 * 24.0 * 3600 + 1000.0
        (base, frac) = tfrac(t, days=1)
        assert base == 3600 * 24 * 3
        assert frac == 1000
Beispiel #36
0
def test_tfrac_hours_04():
    t = 3600 * 5.5
    (base, frac) = tfrac(t, hours=3)
    assert base == 3600 * 3.0
    assert frac == 3600 * 2.5
Beispiel #37
0
def test_tfrac_hours_02():
    with set_timezone(UTC):
        t = 3601
        (base, frac) = tfrac(t, hours=2)
        assert base == 0
        assert frac == 3601
Beispiel #38
0
def test_tfrac_minutes_01():
    t = 3601
    (base, frac) = tfrac(t, minutes=1)
    assert base == 3600
    assert frac == 1
Beispiel #39
0
def test_tfrac_hours_04():
    with set_timezone(UTC):
        t = 3600 * 5.5
        (base, frac) = tfrac(t, hours=3)
        assert base == 3600 * 3.0
        assert frac == 3600 * 2.5
Beispiel #40
0
def test_tfrac_seconds_01():
    t = 3601
    (base, frac) = tfrac(t, seconds=1)
    assert base == 3601
    assert frac == 0
Beispiel #41
0
def test_tfrac_hours_03():
    with set_timezone(UTC):
        t = 3600 * 5.5
        (base, frac) = tfrac(t, hours=2)
        assert base == 3600 * 4
        assert frac == 3600 * 1.5
Beispiel #42
0
def test_tfrac_hours_02():
    t = 3601
    (base, frac) = tfrac(t, hours=2)
    assert base == 0
    assert frac == 3601
Beispiel #43
0
def test_tfrac_minutes_02():
    t = 123.5
    (base, frac) = tfrac(t, minutes=1)
    assert base == 120
    assert frac == 3.5
Beispiel #44
0
def test_tfrac_hours_04():
    with set_timezone(UTC):
        t = 3600 * 5.5
        (base, frac) = tfrac(t, hours=3)
        assert base == 3600 * 3.0
        assert frac == 3600 * 2.5
Beispiel #45
0
def test_tfrac_seconds_02():
    t = 1.75
    (base, frac) = tfrac(t, seconds=1)
    assert base == 1
    assert frac == 0.75
Beispiel #46
0
def test_tfrac_hours_05():
    with set_timezone(UTC):
        t = 3600 * 15.5
        (base, frac) = tfrac(t, hours=6)
        assert base == 3600 * 12.0
        assert frac == 3600 * 3.5
Beispiel #47
0
def test_tfrac_milliseconds_02():
    t = 10.0625
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 10.062
    assert frac ==  0.0005
Beispiel #48
0
def test_tfrac_days_01():
    # Not sure this test is useful. --WW
    t = time.mktime(time.gmtime(0))
    (base, frac) = tfrac(t, days=1)
    assert base == t
    assert frac == 0.0
Beispiel #49
0
def test_tfrac_minutes_01():
    t = 3601
    (base, frac) = tfrac(t, minutes=1)
    assert base == 3600
    assert frac == 1
Beispiel #50
0
def test_tfrac_days_02():
    # Not sure this test is useful. --WW
    t = time.mktime(time.gmtime(0)) + 3*24.0*3600 + 1000.0
    (base, frac) = tfrac(t, days=1)
    assert base == t - 1000.0
    assert frac == 1000.0
Beispiel #51
0
def test_tfrac_years_02():
    with set_timezone(UTC):
        t = 3601
        (base, frac) = tfrac(t, years=10)
        assert base == 0
        assert frac == 3601
Beispiel #52
0
def test_tfrac_minutes_02():
    t = 123.5
    (base, frac) = tfrac(t, minutes=1)
    assert base == 120
    assert frac == 3.5