def test_datetime_roundtrip_local_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt
def test_datetime_roundtrip_est_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz('EST')) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2.replace(tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) == pdt pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz('EST')) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2.replace(tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) == pdt
def test_datetime_roundtrip_local_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt.replace(tzinfo=None) pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt.replace(tzinfo=None)
def test_datetime_roundtrip_local_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz()) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz()) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt
def test_datetime_roundtrip_local_no_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000) pdt2 = ms_to_datetime(datetime_to_ms(pdt)).replace(tzinfo=None) assert pdt2 == pdt pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000) pdt2 = ms_to_datetime(datetime_to_ms(pdt)).replace(tzinfo=None) assert pdt2 == pdt
def test_datetime_roundtrip_lon_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz('Europe/London')) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt.replace(tzinfo=None) pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz('Europe/London')) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt.replace(tzinfo=None)
def test_datetime_roundtrip_lon_no_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2 == pdt
def test_datetime_roundtrip_est_tz(): pdt = datetime.datetime(2012, 6, 12, 12, 12, 12, 123000, tzinfo=mktz('EST')) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2.replace(tzinfo=mktz()) == pdt pdt = datetime.datetime(2012, 1, 12, 12, 12, 12, 123000, tzinfo=mktz('EST')) pdt2 = ms_to_datetime(datetime_to_ms(pdt)) assert pdt2.replace(tzinfo=mktz()) == pdt
def assert_roundtrip(tz): ts = datetime.datetime(1982, 7, 1, 16, 5) ts1 = ts.replace(tzinfo=tz) ts2 = ms_to_datetime(datetime_to_ms(ts1.astimezone(mktz("UTC"))), tz) assert(ts2.hour == ts1.hour) assert ts2 == ts1
def assert_roundtrip(tz): ts = datetime.datetime(1982, 7, 1, 16, 5) ts1 = ts.replace(tzinfo=tz) ts2 = ms_to_datetime(datetime_to_ms(ts1.astimezone(mktz("UTC"))), tz) assert (ts2.hour == ts1.hour) assert ts2 == ts1
def assert_roundtrip(tz): ts = datetime.datetime(1982, 7, 1, 16, 5) ts1 = ts.replace(tzinfo=tz) ts2 = ms_to_datetime(datetime_to_ms(ts1.astimezone(mktz("UTC"))), tz) ts1 = ts1.replace(tzinfo=None) if tz == mktz() else ts1 #logger.info(ts2.tzinfo) assert(ts2.hour == ts1.hour) # assert(ts2.tzinfo == ts1.tzinfo) assert ts2 == ts1
def test_millisecond_conversion(microseconds, expected): pdt = datetime.datetime(2004, 1, 14, 8, 30, 4, microseconds, tzinfo=pytz.utc) pdt2 = datetime_to_ms(pdt) assert pdt2 == expected
def test_datetime_to_ms_and_back_microseconds(): pdt = dt(2012, 8, 1, 12, 34, 56, 999999, tzinfo=mktz(DEFAULT_TIME_ZONE_NAME)) i = datetime_to_ms(pdt) pdt2 = ms_to_datetime(i) assert pdt != pdt2 assert pdt.year == pdt2.year assert pdt.month == pdt2.month assert pdt.day == pdt2.day assert pdt.hour == pdt2.hour assert pdt.minute == pdt2.minute assert pdt.second == pdt2.second # Microsecond precision loss inevitable. assert pdt.microsecond // 1000 == pdt2.microsecond // 1000
def test_datetime_to_ms_and_back_microseconds(): pdt = dt(2012, 8, 1, 12, 34, 56, 999999, tzinfo=mktz()) i = datetime_to_ms(pdt) pdt2 = ms_to_datetime(i) assert pdt != pdt2 assert pdt.year == pdt2.year assert pdt.month == pdt2.month assert pdt.day == pdt2.day assert pdt.hour == pdt2.hour assert pdt.minute == pdt2.minute assert pdt.second == pdt2.second # Microsecond precision loss inevitable. assert pdt.microsecond // 1000 == pdt2.microsecond // 1000
def test_datetime_to_ms_and_back(pdt, local_tz): i = datetime_to_ms(pdt) pdt = pdt.astimezone(local_tz) pdt2 = ms_to_datetime(i, tzinfo=local_tz) assert datetime_to_ms(pdt) == datetime_to_ms(pdt2)
def test_datetime_to_ms_and_back(pdt): i = datetime_to_ms(pdt) pdt = pdt.astimezone(mktz()) pdt2 = ms_to_datetime(i) assert pdt == pdt2