Вам необходимо округлить свои секунды, прежде чем вычислять компоненты времени.
extension CMTime {
var roundedSeconds: TimeInterval {
return seconds.rounded()
}
var hours: Int { return Int(roundedSeconds / 3600) }
var minute: Int { return Int(roundedSeconds.truncatingRemainder(dividingBy: 3600) / 60) }
var second: Int { return Int(roundedSeconds.truncatingRemainder(dividingBy: 60)) }
var positionalTime: String {
return hours > 0 ?
String(format: "%d:%02d:%02d",
hours, minute, second) :
String(format: "%02d:%02d",
minute, second)
}
}
Проверка всех возможных случаев округления ребер:
CMTime(value: 0, timescale: 600).positionalTime // "00:00"
CMTime(value: 300, timescale: 600).positionalTime // "00:01"
CMTime(value: 600, timescale: 600).positionalTime // "00:01"
CMTime(value: 18000 - 600, timescale: 600).positionalTime // "00:29"
CMTime(value: 17945, timescale: 600).positionalTime // "00:30"
CMTime(value: 18000, timescale: 600).positionalTime // "00:30"
CMTime(value: 18055, timescale: 600).positionalTime // "00:30"
CMTime(value: 18000 + 600, timescale: 600).positionalTime // "00:31"
CMTime(value: 2160000 - 600, timescale: 600).positionalTime // "59:59"
CMTime(value: 2160000 - 300, timescale: 600).positionalTime // "1:00:00"
CMTime(value: 2160000, timescale: 600).positionalTime // "1:00:00"