//
//  Int+Ex.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/20.
//

extension Int {
    var localNumber: String? {
        return localNumber()
    }
    
    func localNumber(_ minimumIntegerDigits: Int? = nil, locale: Locale? = nil) -> String? {
        let formatter = NumberFormatter()
        if let locale = locale {
            formatter.locale = locale
        }
        else {
            formatter.locale = Locale.local
        }
        
        formatter.numberStyle = .decimal
        if let value = minimumIntegerDigits {
            formatter.minimumIntegerDigits = value
        }
        return formatter.string(for: self);
    }
}
extension Locale {
    static var local: Locale {
        return Locale(identifier: TSConfig.appLanguage)
    }
}

extension Int {
    /// 将秒数转换为 "HH:mm" 格式的字符串
    /// - Returns: 转换后的字符串
    func toTimeString() -> String {
        // 计算小时和分钟
        let hours = self / 3600
        let minutes = (self % 3600) / 60
        
        // 格式化为 "HH:mm"
        return String(format: "%02d:%02d", hours, minutes)
    }
    
    /// 将秒数转换为 "HH:mm:ss" 格式的字符串
    /// - Returns: 转换后的字符串
    func toHourMinuteSecondString() -> String {
        // 计算小时、分钟和秒
        let hours = self / 3600
        let minutes = (self % 3600) / 60
        let seconds = self % 60
        
        // 格式化为 "HH:mm:ss"
        return String(format: "%02d:%02d:%02d", hours, minutes, seconds)
    }
}
