def test_days_until(self): dates = test_data.test_dates diffs = np.arange(0, len(dates)) _, _, _, o, datetimes = unpack_test_dates(dates) date_tensor = dateslib.from_datetimes(datetimes) target_ordinals = o + diffs target_datetimes = [datetime.date.fromordinal(o) for o in target_ordinals] target_date_tensor = dateslib.from_datetimes(target_datetimes) self.assertAllEqual(diffs, date_tensor.days_until(target_date_tensor))
def perform_addition_test(self, data, period_type): dates_from, quantities, expected_dates = [], [], [] for date_from, quantity, expected_date in data: dates_from.append(date_from) quantities.append(quantity) expected_dates.append(expected_date) datetimes = unpack_test_dates(dates_from)[-1] date_tensor = dateslib.from_datetimes(datetimes) period_tensor = dateslib.periods.PeriodTensor(quantities, period_type) result_date_tensor = date_tensor + period_tensor y, m, d, o, _ = unpack_test_dates(expected_dates) self.assert_date_tensor_equals(result_date_tensor, y, m, d, o)
def test_create_from_date_time_list(self): dates = test_data.test_dates y, m, d, o, datetimes = unpack_test_dates(dates) date_tensor = dateslib.from_datetimes(datetimes) self.assert_date_tensor_equals(date_tensor, y, m, d, o)
def test_day_of_week(self): dates = test_data.test_dates datetimes = unpack_test_dates(dates)[-1] date_tensor = dateslib.from_datetimes(datetimes) expected_day_of_week = np.array([dt.weekday() for dt in datetimes]) self.assertAllEqual(expected_day_of_week, date_tensor.day_of_week())