Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #11
0
def test_tfrac_seconds_02():
    t = 1.75
    (base, frac) = tfrac(t, seconds=1)
    assert base == 1
    assert frac == 0.75
Example #12
0
def test_tfrac_milliseconds_01():
    t = 123.5
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 123.5
    assert frac == 0.0
Example #13
0
def test_tfrac_hours_01():
    t = 3601
    (base, frac) = tfrac(t, hours=1)
    assert base == 3600
    assert frac == 1
Example #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
Example #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
Example #16
0
def test_tfrac_hours_02():
    t = 3601
    (base, frac) = tfrac(t, hours=2)
    assert base == 0
    assert frac == 3601
Example #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
Example #18
0
def test_tfrac_hours_01():
    t = 3601
    (base, frac) = tfrac(t, hours=1)
    assert base == 3600
    assert frac == 1
Example #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
Example #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
Example #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
Example #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
Example #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
Example #27
0
def test_tfrac_seconds_01():
    t = 3601
    (base, frac) = tfrac(t, seconds=1)
    assert base == 3601
    assert frac == 0
Example #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
Example #29
0
def test_tfrac_milliseconds_01():
    t = 123.5
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 123.5
    assert frac == 0.0
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #38
0
def test_tfrac_minutes_01():
    t = 3601
    (base, frac) = tfrac(t, minutes=1)
    assert base == 3600
    assert frac == 1
Example #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
Example #40
0
def test_tfrac_seconds_01():
    t = 3601
    (base, frac) = tfrac(t, seconds=1)
    assert base == 3601
    assert frac == 0
Example #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
Example #42
0
def test_tfrac_hours_02():
    t = 3601
    (base, frac) = tfrac(t, hours=2)
    assert base == 0
    assert frac == 3601
Example #43
0
def test_tfrac_minutes_02():
    t = 123.5
    (base, frac) = tfrac(t, minutes=1)
    assert base == 120
    assert frac == 3.5
Example #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
Example #45
0
def test_tfrac_seconds_02():
    t = 1.75
    (base, frac) = tfrac(t, seconds=1)
    assert base == 1
    assert frac == 0.75
Example #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
Example #47
0
def test_tfrac_milliseconds_02():
    t = 10.0625
    (base, frac) = tfrac(t, milliseconds=1)
    assert base == 10.062
    assert frac ==  0.0005
Example #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
Example #49
0
def test_tfrac_minutes_01():
    t = 3601
    (base, frac) = tfrac(t, minutes=1)
    assert base == 3600
    assert frac == 1
Example #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
Example #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
Example #52
0
def test_tfrac_minutes_02():
    t = 123.5
    (base, frac) = tfrac(t, minutes=1)
    assert base == 120
    assert frac == 3.5