Unified · Split
| @@ -251,15 +251,11 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate { · 250 unmodified lines | ||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | func format(time: Int) -> String { |
| 254 | − let seconds = time % 60 | |
| 255 | − let minutes = (time / 60) % 60 | |
| 256 | − let hours = time / (60 * 60) | |
| 257 | − | |
| 258 | − var stime = hours > 0 ? "\(hours):" : "" | |
| 259 | − stime = (stime.count > 0 || minutes > 9) ? String(format: "%@%02d:", stime, minutes) : "\(minutes):" | |
| 260 | − stime = String(format: "%@%02d", stime, seconds) | |
| 261 | − | |
| 262 | − return stime | |
| 254 | + let formatter = DateComponentsFormatter() | |
| 255 | + formatter.unitsStyle = .positional | |
| 256 | + formatter.zeroFormattingBehavior = time >= (60 * 60) ? [.dropLeading] : [] | |
| 257 | + formatter.allowedUnits = time >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second] | |
| 258 | + return formatter.string(from: TimeInterval(time)) ?? "0:00" | |
| 263 | 259 | } |
| 264 | 260 | |
| 265 | 261 | func removeConstraintFor(identifier: NSTouchBarItem.Identifier) { |