mirror of https://github.com/mpv-player/mpv
mac/touchbar: use DateComponentsFormatter for time formatting
This commit is contained in:
parent
be49f4fe20
commit
ef82ef0bb5
|
@ -251,15 +251,11 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func format(time: Int) -> String {
|
func format(time: Int) -> String {
|
||||||
let seconds = time % 60
|
let formatter = DateComponentsFormatter()
|
||||||
let minutes = (time / 60) % 60
|
formatter.unitsStyle = .positional
|
||||||
let hours = time / (60 * 60)
|
formatter.zeroFormattingBehavior = time >= (60 * 60) ? [.dropLeading] : []
|
||||||
|
formatter.allowedUnits = time >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second]
|
||||||
var stime = hours > 0 ? "\(hours):" : ""
|
return formatter.string(from: TimeInterval(time)) ?? "0:00"
|
||||||
stime = (stime.count > 0 || minutes > 9) ? String(format: "%@%02d:", stime, minutes) : "\(minutes):"
|
|
||||||
stime = String(format: "%@%02d", stime, seconds)
|
|
||||||
|
|
||||||
return stime
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeConstraintFor(identifier: NSTouchBarItem.Identifier) {
|
func removeConstraintFor(identifier: NSTouchBarItem.Identifier) {
|
||||||
|
|
Loading…
Reference in New Issue