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
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
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
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
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
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
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
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
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
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
def test_tfrac_seconds_02(): t = 1.75 (base, frac) = tfrac(t, seconds=1) assert base == 1 assert frac == 0.75
def test_tfrac_milliseconds_01(): t = 123.5 (base, frac) = tfrac(t, milliseconds=1) assert base == 123.5 assert frac == 0.0
def test_tfrac_hours_01(): t = 3601 (base, frac) = tfrac(t, hours=1) assert base == 3600 assert frac == 1
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
def test_tfrac_hours_02(): t = 3601 (base, frac) = tfrac(t, hours=2) assert base == 0 assert frac == 3601
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_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
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
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
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
def test_tfrac_seconds_01(): t = 3601 (base, frac) = tfrac(t, seconds=1) assert base == 3601 assert frac == 0
def test_tfrac_years_02(): with set_timezone(UTC): t = 3601 (base, frac) = tfrac(t, years=10) assert base == 0 assert frac == 3601
def test_tfrac_days_01(): with set_timezone(UTC): t = 3601 (base, frac) = tfrac(t, days=1) assert base == 0 assert frac == 3601
def test_tfrac_hours_02(): with set_timezone(UTC): t = 3601 (base, frac) = tfrac(t, hours=2) assert base == 0 assert frac == 3601
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
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
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
def test_tfrac_minutes_01(): t = 3601 (base, frac) = tfrac(t, minutes=1) assert base == 3600 assert frac == 1
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
def test_tfrac_minutes_02(): t = 123.5 (base, frac) = tfrac(t, minutes=1) assert base == 120 assert frac == 3.5
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