Skip to content

Commit 093f28a

Browse files
committed
bugfixes: fix incorrect seconds value
1 parent 3a483bd commit 093f28a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

InfiniLink/Utils/FitnessCalculator.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,18 @@ class FitnessCalculator {
126126
}
127127

128128
func secondsForDistance(distance: Double, pace: Pace = .avgWalk) -> Int {
129-
let speed: Double = personalizationController.units == .imperial ? pace.milesPerHour : (pace.kmPerHour * 1.60934)
129+
// Convert kph to mph if needed
130+
let speed: Double = personalizationController.units == .imperial ? pace.milesPerHour : (pace.kmPerHour / 1.609)
130131

131132
return Int(ceil((distance / speed) * 60 * 60))
132133
}
133134

134135
func secondsFormatted(seconds: Int, full: Bool = false) -> String {
135-
let hours = seconds / 3600
136+
let hours = Double(seconds) / 3600.0
136137
let minutes = (seconds % 3600) / 60
137138

138-
if hours > 0 {
139-
return "\(String(format: "%.1f", hours)) \(full ? "hour" : "hr")\(hours == 1 ? "" : "s")"
139+
if hours >= 1 {
140+
return "\(String(format: "%.2f", hours)) \(full ? "hour" : "hr")\(hours == 1 ? "" : "s")"
140141
} else if minutes > 0 {
141142
return "\(minutes) \(full ? "minute" : "min")\(minutes == 1 ? "" : "s")"
142143
} else {

0 commit comments

Comments
 (0)