// A media entry's length, as a conversation's media draws it. What a message // SAYS in a list is the core's (`cotton-core/src/messages/preview.rs`). // // A `static` function with no core and no clock, so a test drives it with // nothing at all. It does not draw. import Foundation public enum ChatMessagePreview { /// `m:ss`, or `h:mm:ss` past an hour. A bad number reads as zero, never as /// nothing at all. static func duration(ms: Int) -> String { let total = ms > 0 ? ms / 1000 : 0 let seconds = total % 60 let minutes = (total / 60) % 60 let hours = total / 3600 let ss = seconds < 10 ? "0\(seconds)" : "\(seconds)" if hours == 0 { return "\(minutes):\(ss)" } let mm = minutes < 10 ? "0\(minutes)" : "\(minutes)" return "\(hours):\(mm):\(ss)" } }