From 54d7fe216f1cac4babaaf963cd63830700cf5e06 Mon Sep 17 00:00:00 2001 From: bastiaanv Date: Mon, 30 Sep 2024 06:58:31 +0200 Subject: [PATCH] fix: Fix time formatting --- .../DanaKitUI/ViewModels/DanaKitSettingsViewModel.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Dependencies/DanaKit/DanaKitUI/ViewModels/DanaKitSettingsViewModel.swift b/Dependencies/DanaKit/DanaKitUI/ViewModels/DanaKitSettingsViewModel.swift index df2201be57..a0d2bc791b 100644 --- a/Dependencies/DanaKit/DanaKitUI/ViewModels/DanaKitSettingsViewModel.swift +++ b/Dependencies/DanaKit/DanaKitUI/ViewModels/DanaKitSettingsViewModel.swift @@ -374,10 +374,12 @@ class DanaKitSettingsViewModel : ObservableObject { } private func formatDateToDayHour(_ date: Date) -> String { - let day = String(format: "%.0f", floor(-date.timeIntervalSinceNow / .days(1))) - let hour = String(format: "%.0f", (-date.timeIntervalSinceNow.truncatingRemainder(dividingBy: .days(1))) / .hours(1)) + let components = Calendar.current.dateComponents([.day, .hour, .minute, .second], from: date, to: Date.now) + if let days = components.day, let hours = components.hour { + return "\(days)d \(hours)h" + } - return "\(day)d \(hour)h" + return "?d ?h" } }