Files
Termind/Frameworks/TermindPresentation/ChatMessageTimestampFormatter.swift
T
2026-09-12 22:39:45 +08:00

23 lines
743 B
Swift

import Foundation
import TermindApplication
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)
}
}