def test_visible_hours(): """ 测试可见小时的判断逻辑。 """ plan = Plan() plan.visible_hours = {12, 22} trigger_time1 = datetime(2020, 3, 12, 22, 14) trigger_time2 = datetime(2021, 4, 13, 23, 15) assert plan.is_visible(trigger_time=trigger_time1) assert not plan.is_visible(trigger_time=trigger_time2)
def _row2entity(self, row: dict): plan = Plan() plan.duration = row['duration'] plan.id = row['id'] plan.location_id = row['location_id'] if isinstance(row['repeat_interval'], int): plan.repeat_interval = timedelta(seconds=row['repeat_interval']) plan.repeat_type = row['repeat_type'] plan.status = row['status'] and PlanStatus(row['status']) plan.task_id = row['task_id'] plan.trigger_time = row['trigger_time'] plan.visible_hours = json.loads(row.get('visible_hours') or '[]') plan.visible_wdays = json.loads(row.get('visible_wdays') or '[]') return plan