diff options
author | der richter <der.richter@gmx.de> | 2024-03-17 23:47:30 +0100 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2024-03-18 20:29:27 +0100 |
commit | ef82ef0bb5823e2cc1eb74acb34b4d2315d40369 (patch) | |
tree | 8b8050970818840c45efd1115101ed86189c887a | |
parent | be49f4fe205bed7af4cc39a48f50af8a2691ce50 (diff) | |
download | mpv-ef82ef0bb5823e2cc1eb74acb34b4d2315d40369.tar.bz2 mpv-ef82ef0bb5823e2cc1eb74acb34b4d2315d40369.tar.xz |
mac/touchbar: use DateComponentsFormatter for time formatting
-rw-r--r-- | osdep/mac/touch_bar.swift | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/osdep/mac/touch_bar.swift b/osdep/mac/touch_bar.swift index 13bdbfa6f6..daffc4ccb0 100644 --- a/osdep/mac/touch_bar.swift +++ b/osdep/mac/touch_bar.swift @@ -251,15 +251,11 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate { } func format(time: Int) -> String { - let seconds = time % 60 - let minutes = (time / 60) % 60 - let hours = time / (60 * 60) - - var stime = hours > 0 ? "\(hours):" : "" - stime = (stime.count > 0 || minutes > 9) ? String(format: "%@%02d:", stime, minutes) : "\(minutes):" - stime = String(format: "%@%02d", stime, seconds) - - return stime + let formatter = DateComponentsFormatter() + formatter.unitsStyle = .positional + formatter.zeroFormattingBehavior = time >= (60 * 60) ? [.dropLeading] : [] + formatter.allowedUnits = time >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second] + return formatter.string(from: TimeInterval(time)) ?? "0:00" } func removeConstraintFor(identifier: NSTouchBarItem.Identifier) { |