Skip to content

Commit

Permalink
fix: Fix time formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiaanv committed Sep 30, 2024
1 parent e858bfd commit 54d7fe2
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down

0 comments on commit 54d7fe2

Please sign in to comment.