add a new format for video duration
This commit is contained in:
parent
1a672cdd0a
commit
16d4d0128e
|
@ -184,7 +184,7 @@ extension MediaInfoVC {
|
|||
}()
|
||||
durationLabel.text = {
|
||||
guard let duration = attachment.duration else { return "N/A" }
|
||||
return floor(duration).formatted(format: .hoursMinutesSeconds)
|
||||
return floor(duration).formatted(format: .videoDuration)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,15 @@ public extension String {
|
|||
let secondsPerWeek: TimeInterval = (secondsPerDay * 7)
|
||||
|
||||
switch format {
|
||||
case .videoDuration:
|
||||
let seconds: Int = Int(duration.truncatingRemainder(dividingBy: 60))
|
||||
let minutes: Int = Int((duration / 60).truncatingRemainder(dividingBy: 60))
|
||||
let hours: Int = Int(duration / 3600)
|
||||
|
||||
guard hours > 0 else { return String(format: "%02ld:%02ld", minutes, seconds) }
|
||||
|
||||
return String(format: "%ld:%02ld:%02ld", hours, minutes, seconds)
|
||||
|
||||
case .hoursMinutesSeconds:
|
||||
let seconds: Int = Int(duration.truncatingRemainder(dividingBy: 60))
|
||||
let minutes: Int = Int((duration / 60).truncatingRemainder(dividingBy: 60))
|
||||
|
|
|
@ -7,6 +7,7 @@ public extension TimeInterval {
|
|||
case short
|
||||
case long
|
||||
case hoursMinutesSeconds
|
||||
case videoDuration
|
||||
}
|
||||
|
||||
func formatted(format: DurationFormat) -> String {
|
||||
|
|
Loading…
Reference in New Issue