def resolve_by_date_range_constraints(candidates: [str], timex_constraints: [Timex]): date_range_constraints = list( map( lambda t: TimexHelpers.daterange_from_timex(t), filter(lambda t: Constants.TIMEX_TYPES_DATERANGE in t.types, timex_constraints))) collapsed_date_ranges = TimexConstraintsHelper.collapse( TimexConstraintsHelper(), date_range_constraints) if not any(collapsed_date_ranges): return candidates resolution = [] for timex in candidates: resolve_date = TimexRangeResolver.resolve_date( Timex(timex), collapsed_date_ranges) resolution.extend(resolve_date) return TimexRangeResolver.remove_duplicates(resolution)
def test_datatypes_helpers_daterangefromtimex(): timex = Timex(timex='(2017-09-27,2017-09-29,P2D)') range = TimexHelpers.daterange_from_timex(timex) assert range.start == datetime(2017, 9, 27).date() assert range.end == datetime(2017, 9, 29).date()