def test_from_human(self): weekly_1 = WeeklyInterval('Mon', time(10, 00), 'Fri', time(18, 00)) weekly_2 = WeeklyInterval('Sat', time(12, 00), 'Sun', time(9, 00)) interval = IntervalUnion([weekly_1, weekly_2]) assert interval == IntervalUnion.from_human( 'Mon@10am - Fri@6pm,Sat@12pm-Sunday 9am') assert IntervalUnion( [weekly_1]) == IntervalUnion.from_human('Mon@10am - Fri@6pm')
def test_from_human_with_timezone(self): weekly_1 = WeeklyInterval('Mon', time(10, 00), 'Fri', time(18, 00)) weekly_2 = WeeklyInterval('Sat', time(12, 00), 'Sun', time(9, 00)) interval = IntervalUnion([weekly_1, weekly_2]) # During summer time now = pendulum.datetime(2019, 8, 30, tz='Europe/London') set_test_now(now) assert IntervalUnion.from_human( "Mon 11:00 Europe/London - Fri 19:00 Europe/London," "Sat 13:00 Europe/London - Sun 10:00 Europe/London") == interval # Outside summer time now = pendulum.datetime(2019, 12, 30, tz='Europe/London') set_test_now(now) assert IntervalUnion.from_human( "Mon 10:00 Europe/London - Fri 18:00 Europe/London," "Sat 12:00 Europe/London - Sun 09:00 Europe/London") == interval
def test_non_overlapping(self): weekly_1 = WeeklyInterval('Mon', time(10, 00), 'Fri', time(18, 00)) weekly_2 = WeeklyInterval('Sat', time(12, 00), 'Sun', time(9, 00)) interval = IntervalUnion([weekly_1, weekly_2]) assert interval.covers(date('Tuesday 3pm')) assert not interval.covers(date('Saturday 9am')) assert interval.covers(date('Saturday 6pm')) assert not interval.covers(date('Sunday 11am'))
def test_singleton(self): weekly = WeeklyInterval('Mon', time(10, 00), 'Fri', time(18, 00)) interval = IntervalUnion([weekly]) assert interval.covers(date('Tuesday 3pm')) assert not interval.covers(date('Sunday 5pm'))
def test_empty(self): empty_interval = IntervalUnion.empty() assert empty_interval == IntervalUnion([]) assert not empty_interval.covers(date('Monday 5pm'))