From 3f4d50045d8475de2f9ca6c52d5d2851f2b35d3d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 16 Jun 2026 19:10:01 +0000 Subject: [PATCH] Fix duration display showing 6:60 instead of 7:00 When summing many sleep segments, floating-point imprecision could leave the remainder at 3599 seconds. Rounding that to minutes produced 60 without rolling into the next hour. Calculate total minutes first, then split into hours and minutes so values like 420 minutes always display as 7:00. Co-authored-by: Greg --- Bedtime/Bedtime/Utils/TimeFormatter.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Bedtime/Bedtime/Utils/TimeFormatter.swift b/Bedtime/Bedtime/Utils/TimeFormatter.swift index fc3cf16..7a3a92d 100644 --- a/Bedtime/Bedtime/Utils/TimeFormatter.swift +++ b/Bedtime/Bedtime/Utils/TimeFormatter.swift @@ -9,8 +9,9 @@ import Foundation struct TimeFormatter { static func formatDuration(_ duration: TimeInterval) -> String { - let hours = Int(duration) / 3600 - let minutes = Int((duration.truncatingRemainder(dividingBy: 3600) / 60).rounded()) + let totalMinutes = Int((duration / 60).rounded()) + let hours = totalMinutes / 60 + let minutes = totalMinutes % 60 return "\(hours):\(String(format: "%02d", minutes))" } }