mirror of
https://github.com/yattee/yattee.git
synced 2024-12-15 06:40:32 +05:30
18 lines
446 B
Swift
18 lines
446 B
Swift
|
import Foundation
|
||
|
|
||
|
extension Double {
|
||
|
func formattedAsPlaybackTime() -> String? {
|
||
|
guard !isZero else {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
let formatter = DateComponentsFormatter()
|
||
|
|
||
|
formatter.unitsStyle = .positional
|
||
|
formatter.allowedUnits = self >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second]
|
||
|
formatter.zeroFormattingBehavior = [.pad]
|
||
|
|
||
|
return formatter.string(from: self)
|
||
|
}
|
||
|
}
|