//
//  Times.swift
//  TwoRooks
//
//  Created by Samuel McBroom on 2/24/21.
//

import Foundation

struct Times: Codable {
	var light: TimeInterval
	var dark: TimeInterval
	var lastUpdate: Date
	
	func stringFor(lightTime: Bool, withStyle style: DateComponentsFormatter.UnitsStyle) -> String {
		let formatter = DateComponentsFormatter()
		formatter.allowedUnits = [.hour, .minute, .second]
		formatter.unitsStyle = style
		formatter.zeroFormattingBehavior = .pad
		guard let formattedString = formatter.string(from: lightTime ? light : dark) else {
			return ""
		}
		return formattedString
	}
}
