forked from mirrors/linphone-iphone
67 lines
1.8 KiB
Swift
67 lines
1.8 KiB
Swift
/*
|
|
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
|
*
|
|
* This file is part of Linphone
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
extension Int {
|
|
|
|
public func hmsFrom() -> (Int, Int, Int) {
|
|
return (self / 3600, (self % 3600) / 60, (self % 3600) % 60)
|
|
}
|
|
|
|
public func convertDurationToString() -> String {
|
|
var duration = ""
|
|
let (hour, minute, second) = self.hmsFrom()
|
|
if hour > 0 {
|
|
duration = self.getHour(hour: hour)
|
|
}
|
|
return "\(duration)\(self.getMinute(minute: minute))\(self.getSecond(second: second))"
|
|
}
|
|
|
|
private func getHour(hour: Int) -> String {
|
|
var duration = "\(hour):"
|
|
if hour < 10 {
|
|
duration = "0\(hour):"
|
|
}
|
|
return duration
|
|
}
|
|
|
|
private func getMinute(minute: Int) -> String {
|
|
if minute == 0 {
|
|
return "00:"
|
|
}
|
|
|
|
if minute < 10 {
|
|
return "0\(minute):"
|
|
}
|
|
|
|
return "\(minute):"
|
|
}
|
|
|
|
private func getSecond(second: Int) -> String {
|
|
if second == 0 {
|
|
return "00"
|
|
}
|
|
|
|
if second < 10 {
|
|
return "0\(second)"
|
|
}
|
|
return "\(second)"
|
|
}
|
|
}
|