def resolve_date_timerange(timex: Timex): if timex.part_of_day is not None: date = TimexValue.date_value(timex) time_range = TimexResolver.part_of_day_timerange(timex) entry = Entry() entry.timex = timex.timex_value() entry.type = 'datetimerange' entry.start = f'{date} {time_range[0]}' entry.end = f'{date} {time_range[1]}' entry.value = None return [entry] else: time_range = TimexHelpers.expand_datetime_range(timex) entry = Entry() entry.timex = timex.timex_value() entry.type = 'datetimerange' entry.start = f'{TimexValue.date_value(time_range.start)} {TimexValue.time_value(time_range.start)}' entry.end = f'{TimexValue.date_value(time_range.end)} {TimexValue.time_value(time_range.end)}' entry.value = None return [entry]
def resolve_definite_daterange(timex: Timex): date_range = TimexHelpers.expand_datetime_range(timex) entry = Entry() entry.timex = timex.timex_value() entry.type = 'daterange' entry.start = TimexValue.date_value(date_range.start) entry.end = TimexValue.date_value(date_range.end) return [entry]
def test_datatypes_helpers_expanddatetimerange_short(): timex = Timex(timex='(2017-09-27,2017-09-29,P2D)') range = TimexHelpers.expand_datetime_range(timex) assert range.start.timex_value() == '2017-09-27' assert range.end.timex_value() == '2017-09-29'
def test_datatypes_helpers_expandtimerange(): timex = Timex(timex='(T14,T16,PT2H)') range = TimexHelpers.expand_datetime_range(timex) assert range.start.timex_value() == 'T14' assert range.end.timex_value() == 'T16'
def test_datatypes_helpers_expanddatetimerange_year(): timex = Timex(timex='1999') range = TimexHelpers.expand_datetime_range(timex) assert range.start.timex_value() == '1999-01-01' assert range.end.timex_value() == '2000-01-01'
def test_datatypes_helpers_expanddatetimerange_month(): timex = Timex(timex='2017-05') range = TimexHelpers.expand_datetime_range(timex) assert range.start.timex_value() == '2017-05-01' assert range.end.timex_value() == '2017-06-01'
def test_datatypes_gelpers_expanddatetimerange_include_time(): timex = Timex(timex='(2017-10-10T16:02:04,2017-10-10T16:07:04,PT5M)') range = TimexHelpers.expand_datetime_range(timex) assert range.start.timex_value() == '2017-10-10T16:02:04' assert range.end.timex_value() == '2017-10-10T16:07:04'
def test_datatypes_helpers_expanddatetimerange_long(): timex = Timex(timex='(2006-01-01,2008-06-01,P882D)') range = TimexHelpers.expand_datetime_range(timex) assert range.start.timex_value() == '2006-01-01' assert range.end.timex_value() == '2008-06-01'