Просмотр исходного кода

Fix fringe case bug in drawActiveOverrides()
- Before this fix: If editing a running override with a set duration and change it to indefinite, the old duration still renders in Trio main chart
- After this fix: drawActiveOverride() checks for indefinite = true before checking duration != 0 to render correct duration

dsnallfot 1 год назад
Родитель
Сommit
b1c488d0b8

+ 9 - 2
Trio/Sources/Modules/Home/View/Chart/ChartElements/OverrideView.swift

@@ -23,8 +23,15 @@ struct OverrideView: ChartContent {
                 attribute: "duration",
                 context: viewContext
             ) ?? 0
-            let end: Date = duration != 0 ? start.addingTimeInterval(duration) : start
-                .addingTimeInterval(60 * 60 * 24 * 30) // handle infinite overrides -> 60s x 60m x 24h x 30d = 30 days duration
+            let end: Date = {
+                if override.indefinite {
+                    return start.addingTimeInterval(60 * 60 * 24 * 30)
+                } else if duration != 0 {
+                    return start.addingTimeInterval(duration)
+                } else {
+                    return start.addingTimeInterval(60 * 60 * 24 * 30)
+                }
+            }()
 
             let target = getOverrideTarget(override: override)