22 lines
717 B
Swift
22 lines
717 B
Swift
import Foundation
|
|
|
|
nonisolated public enum ChatMessageTimestampFormatter {
|
|
public static func string(
|
|
for date: Date,
|
|
now: Date = .now,
|
|
calendar: Calendar = .autoupdatingCurrent,
|
|
locale: Locale = .autoupdatingCurrent,
|
|
timeZone: TimeZone = .autoupdatingCurrent
|
|
) -> String {
|
|
let formatter = DateFormatter()
|
|
var calendar = calendar
|
|
calendar.timeZone = timeZone
|
|
formatter.calendar = calendar
|
|
formatter.locale = locale
|
|
formatter.timeZone = timeZone
|
|
formatter.dateStyle = calendar.isDate(date, inSameDayAs: now) ? .none : .short
|
|
formatter.timeStyle = .short
|
|
return formatter.string(from: date)
|
|
}
|
|
}
|