def test_posixts_to_ndays(): jan_1_2015_t = packet.dt_to_time_t(dt.datetime(2015, 1, 1, tzinfo=pytz.UTC)) eq_(packet.posixts_to_ndays(jan_1_2015_t), 0) jan_1_2016_t = packet.dt_to_time_t(dt.datetime(2016, 1, 1, tzinfo=pytz.UTC)) eq_(packet.posixts_to_ndays(jan_1_2016_t), 365)
def test_expiration_is_invertible(): # It can be surprising if the expiration date changes when you write # it to the cartridge and read it back. So, let's at least make sure # that the default expiration date can be read back without changing. expiration_date = packet.v2_defaults(1)['expiration_date'] eq_(expiration_date, packet.ndays_to_posixts(packet.posixts_to_ndays(expiration_date)))
def test_expiration_date_ndays(): '''Comprehensively test that dates are converted to ndays and back.''' # Test every date from the first date that can be represented using ndays # to an arbitrary date in the future. earliest = packet.JAN_1_2015_UTC until = FAR_FUTURE # Generate every date in the range. for a_dt in dur.rrule(du.rrule.DAILY, dtstart=earliest, until=until): ts_in = packet.date_to_posixts(a_dt) ndays = packet.posixts_to_ndays(ts_in) ts_out = packet.ndays_to_posixts(ndays) eq_(a_dt.date(), packet.posixts_to_date(ts_out))
def test_ndays_utc_round_trip(): # For a round-trip calculation to work, you must choose a number that # is evenly divisible by (24 * 60 * 60) utc_date = 3999974400 eq_(packet.ndays_to_posixts(packet.posixts_to_ndays(utc_date)), utc_date)
def test_posix_to_ndays_jan1(): jan_1_2014_t = packet.dt_to_time_t(dt.datetime(2014, 1, 1, tzinfo=pytz.UTC)) eq_(packet.posixts_to_ndays(jan_1_2014_t), 0)