History

mac/touchbar: use DateComponentsFormatter for time formatting

der richter committed 2 years ago

Commit ef82ef01 parent be49f4f1 file · +5 −9Browse files

Unified · Split

osdep/mac/touch_bar.swift+5−9
@@ -251,15 +251,11 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate { · 250 unmodified lines
251251 }
252252
253253 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"
263259 }
264260
265261 func removeConstraintFor(identifier: NSTouchBarItem.Identifier) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t