Skip to content
Snippets Groups Projects
Verified Commit baab7890 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Add time editing functionality

parent 750eaef2
Branches
No related tags found
No related merge requests found
......@@ -420,5 +420,6 @@ $RECYCLE.BIN/
config.json
patches.json
patches.json.old
input.json
output.ics
\ No newline at end of file
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment