示例#1
0
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)
示例#2
0
def test_v2_encode_date_fn():
    day1_t = packet.dt_to_time_t(packet.JAN_1_2015_UTC)
    eq_(packet.v2_encode_date_fn(day1_t, False, False, pytz.UTC), 0)
    tz = pytz.timezone('Etc/GMT+1')
    eq_(packet.v2_encode_date_fn(day1_t, False, False, tz), 1 << 13)
    eq_(packet.v2_encode_date_fn(day1_t, True, False, pytz.UTC), 1 << 14)
    eq_(packet.v2_encode_date_fn(day1_t, False, True, pytz.UTC), 1 << 15)

    a_year_t = packet.dt_to_time_t(dt.datetime(2016, 1, 1, tzinfo=pytz.UTC))
    eq_(packet.v2_encode_date_fn(a_year_t, False, False, pytz.UTC), 365)
示例#3
0
def test_ndays_to_posixts():
    # 15 days after Jan 1 is Jan 16.
    jan_15_2015_t = packet.dt_to_time_t(
        dt.datetime(2015, 1, 16, tzinfo=pytz.UTC))
    eq_(packet.ndays_to_posixts(15), jan_15_2015_t)

    jan_1_2015_t = packet.dt_to_time_t(dt.datetime(2015, 1, 1,
                                                   tzinfo=pytz.UTC))
    eq_(packet.ndays_to_posixts(0), jan_1_2015_t)

    jan_1_2016_t = packet.dt_to_time_t(dt.datetime(2016, 1, 1,
                                                   tzinfo=pytz.UTC))
    eq_(packet.ndays_to_posixts(365), jan_1_2016_t)
示例#4
0
def test_v2_decode_date_bits():
    # Use round-trip tests, as there's no obvious way to create encoded
    # values.
    a_day_t = packet.dt_to_time_t(dt.datetime(2015, 6, 15, tzinfo=pytz.UTC))

    encoded1 = packet.v2_encode_date_fn(a_day_t, True, False, pytz.UTC)
    eq_(packet.v2_decode_date_bits(encoded1), (a_day_t, True, False))

    encoded2 = packet.v2_encode_date_fn(a_day_t, False, True, pytz.UTC)
    eq_(packet.v2_decode_date_bits(encoded2), (a_day_t, False, True))
示例#5
0
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)
示例#6
0
def test_dt_to_time_t():
    beginning_of_posix_time_dt = dt.datetime(1970, 1, 1, tzinfo=pytz.UTC)
    eq_(0, packet.dt_to_time_t(beginning_of_posix_time_dt))

    a_bit_later = dt.datetime(1970, 1, 1, 0, 0, 5, tzinfo=pytz.UTC)
    eq_(5, packet.dt_to_time_t(a_bit_later))