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
251 }251 }
252 252
253 func format(time: Int) -> String {253 func format(time: Int) -> String {
254 let seconds = time % 60254 let formatter = DateComponentsFormatter()
255 let minutes = (time / 60) % 60255 formatter.unitsStyle = .positional
256 let hours = time / (60 * 60)256 formatter.zeroFormattingBehavior = time >= (60 * 60) ? [.dropLeading] : []
257 257 formatter.allowedUnits = time >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second]
258 var stime = hours > 0 ? "\(hours):" : ""258 return formatter.string(from: TimeInterval(time)) ?? "0:00"
259 stime = (stime.count > 0 || minutes > 9) ? String(format: "%@%02d:", stime, minutes) : "\(minutes):"
260 stime = String(format: "%@%02d", stime, seconds)
261
262 return stime
263 }259 }
264 260
265 func removeConstraintFor(identifier: NSTouchBarItem.Identifier) {261 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