+def item_sort_by_priority_then_date(items):
+ sortedTasks = list(items)
+ sortedTasks.sort(
+ key = lambda taskDetails: (
+ taskDetails["priority"].get_nothrow(4),
+ taskDetails["dueDate"].get_nothrow(datetime.datetime.max),
+ ),
+ )
+ return sortedTasks
+
+
+def item_sort_by_date_then_priority(items):
+ sortedTasks = list(items)
+ sortedTasks.sort(
+ key = lambda taskDetails: (
+ taskDetails["dueDate"].get_nothrow(datetime.datetime.max),
+ taskDetails["priority"].get_nothrow(4),
+ ),
+ )
+ return sortedTasks
+
+
+def item_in_agenda(item):
+ taskDate = item["dueDate"].get_nothrow(datetime.datetime.max)
+ today = datetime.datetime.now()
+ delta = taskDate - today
+ dayDelta = abs(delta.days)
+
+ priority = item["priority"].get_nothrow(4)
+ weeksVisible = 5 - priority
+
+ isVisible = not bool(dayDelta / (weeksVisible * 7))
+ return isVisible
+
+
+def item_agenda_sort_by_date_then_priority(items):
+ sortedTasks = list(item for item in items if item_in_agenda(item))
+
+ def advanced_key(taskDetails):
+ dueDate = taskDetails["dueDate"].get_nothrow(datetime.datetime.max)
+ priority = taskDetails["priority"].get_nothrow(4)
+ isNotSameYear = not toolbox.is_same_year(dueDate)
+ isNotSameMonth = not toolbox.is_same_month(dueDate)
+ isNotSameDay = not toolbox.is_same_day(dueDate)
+ return isNotSameDay, isNotSameMonth, isNotSameYear, priority, dueDate
+
+ sortedTasks.sort(key=advanced_key)
+ return sortedTasks
+
+