def resolve_date_against_constraint(timex: Timex, constraint: DateRange): if (timex.month and timex.day_of_month) is not None: result = [] year = constraint.start.year while year - 1 != constraint.end.year: t = copy.copy(timex) t.year = year result.extend( TimexRangeResolver.resolve_definite_against_constraint( t, constraint)) year = year + 1 return filter(lambda x: x != '', result) if timex.day_of_week is not None: day = timex.day_of_week - 1 dates = TimexDateHelpers.dates_matching_day( day, constraint.start, constraint.end) result = [] for date in dates: t = copy.copy(timex) t.day_of_week = None t.year = date.year t.month = date.month t.day_of_month = date.day result.append(t.timex_value()) return result return ['']
def test_datatypes_datehelpers_datesmatchingday(): day = Constants.DAYS['THURSDAY'] start = datetime(2017, 3, 1) end = datetime(2017, 4, 1) result = TimexDateHelpers.dates_matching_day(day, start, end) assert len(result) == 5 assert result[0] == datetime(2017, 3, 2) assert result[1] == datetime(2017, 3, 9) assert result[2] == datetime(2017, 3, 16) assert result[3] == datetime(2017, 3, 23) assert result[4] == datetime(2017, 3, 30)