mirror of
https://github.com/yattee/yattee.git
synced 2024-11-14 01:58:24 +00:00
321c265a11
WIP on controls Chapters working Add previews variable Add lists ids WIP
27 lines
763 B
Swift
27 lines
763 B
Swift
import Foundation
|
|
|
|
extension Double {
|
|
func formattedAsPlaybackTime(allowZero: Bool = false) -> String? {
|
|
guard allowZero || !isZero, isFinite 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)
|
|
}
|
|
|
|
func formattedAsRelativeTime() -> String? {
|
|
let date = Date(timeIntervalSince1970: self)
|
|
|
|
let formatter = RelativeDateTimeFormatter()
|
|
formatter.unitsStyle = .full
|
|
|
|
return formatter.localizedString(for: date, relativeTo: Date())
|
|
}
|
|
}
|