Consistent sorting of output

This commit is contained in:
Christoph Hagen
2025-01-27 07:56:36 +01:00
parent 09b1f48aea
commit 82c40cc080
6 changed files with 23 additions and 6 deletions

View File

@@ -2,6 +2,8 @@ import Foundation
protocol DateItem {
var id: String { get }
var startDate: Date { get }
var hasEndDate: Bool { get }
@@ -9,6 +11,18 @@ protocol DateItem {
var potentialEndDate: Date { get }
}
extension Sequence where Element: DateItem {
func sortedByStartDateAndId() -> [Element] {
sorted { (lhs, rhs) -> Bool in
if lhs.startDate == rhs.startDate {
return lhs.id < rhs.id
}
return lhs.startDate > rhs.startDate
}
}
}
extension DateItem {
var endDate: Date? {