diff --git a/.gitignore b/.gitignore index 1b8513839baa9b0df303978fb14c130adf9ef47d..35b4c8cf96ac821f833acff025bd4b9cbc4a5a31 100644 --- a/.gitignore +++ b/.gitignore @@ -420,5 +420,6 @@ $RECYCLE.BIN/ config.json patches.json +patches.json.old input.json output.ics \ No newline at end of file diff --git a/main.py b/main.py index 3d3f9bf03e83ca3fe9378f718f344931deda8d54..8166d5f4f8a80b210e3c9f15766c99503320eeb1 100644 --- a/main.py +++ b/main.py @@ -98,6 +98,23 @@ def apply_patch(input_lessons: list, patch: dict, week_lookup_table: list) -> li # Edit the lesson for key, value in patch["edit"].items(): lesson[key] = value + elif patch["type"] == "edit_times": + # Edit all lesson times that match the condition + for lesson in input_lessons: + if eval_lesson_condition(lesson, patch["condition"]): + # Get startDate and endDate + start_date = datetime.datetime.strptime(lesson["startDate"], "%Y-%m-%dT%H:%M:%S") + end_date = datetime.datetime.strptime(lesson["endDate"], "%Y-%m-%dT%H:%M:%S") + # Get start time and end time, replace in date + if "start" in patch["edit"]: + start_time = datetime.time.fromisoformat(patch["edit"]["start"]) + start_date = start_date.replace(hour=start_time.hour, minute=start_time.minute, second=start_time.second) + if "end" in patch["edit"]: + end_time = datetime.time.fromisoformat(patch["edit"]["end"]) + end_date = end_date.replace(hour=end_time.hour, minute=end_time.minute, second=end_time.second) + # Set new dates + lesson["startDate"] = start_date.strftime("%Y-%m-%dT%H:%M:%S") + lesson["endDate"] = end_date.strftime("%Y-%m-%dT%H:%M:%S") elif patch["type"] == "add": # Add a lesson # Build day map