//
//  TimeInterval+Extensions.swift
//  LeCountdown
//
//  Created by Laurent Morvillier on 20/01/2023.
//

import Foundation

extension TimeInterval {
    
    var hourMinuteSecondHS: String {
        let h = self.hour
        if h > 1 {
            return String(format:"%d:%02d:%02d.%02d", hour, minute, second, hundredth)
        } else {
            return String(format:"%02d:%02d.%02d", minute, second, hundredth)
        }
    }
    var hourMinuteSecondMS: String {
        String(format:"%d:%02d:%02d.%03d", hour, minute, second, millisecond)
    }
    var minuteSecond: String {
        String(format:"%d:%02d", minute, second)
    }
    var hour: Int {
        Int((self/3600).truncatingRemainder(dividingBy: 3600))
    }
    var minute: Int {
        Int((self/60).truncatingRemainder(dividingBy: 60))
    }
    var second: Int {
        Int(truncatingRemainder(dividingBy: 60))
    }
    var millisecond: Int {
        Int((self*1000).truncatingRemainder(dividingBy: 1000))
    }
    var hundredth: Int {
        Int((self*100).truncatingRemainder(dividingBy: 100))
    }
    
}
