split up date formatting

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-01-30 19:01:31 -08:00
parent b73b1da46e
commit f05cd1b7e6
3 changed files with 9 additions and 5 deletions

View File

@@ -76,10 +76,14 @@ func format_relative_time(_ created_at: UInt32) -> String
return time_ago_since(Date(timeIntervalSince1970: Double(created_at)))
}
func format_date(_ created_at: UInt32) -> String {
func format_date(created_at: UInt32) -> String {
let date = Date(timeIntervalSince1970: TimeInterval(created_at))
return format_date(date: date)
}
func format_date(date: Date, time_style: DateFormatter.Style = .short) -> String {
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = .short
dateFormatter.timeStyle = time_style
dateFormatter.dateStyle = .short
return dateFormatter.string(from: date)
}

View File

@@ -57,7 +57,7 @@ struct SelectedEventView: View {
Mention
Text(verbatim: "\(format_date(event.created_at))")
Text(verbatim: "\(format_date(created_at: event.created_at))")
.padding([.top, .leading, .trailing])
.font(.footnote)
.foregroundColor(.gray)

View File

@@ -308,14 +308,14 @@ struct DamusPurpleView: View {
Text(NSLocalizedString("Purchased on", comment: "Indicating when the user purchased the subscription"))
.font(.title2)
.foregroundColor(.white)
Text(format_date(UInt32(purchased.tx.purchaseDate.timeIntervalSince1970)))
Text(format_date(date: purchased.tx.purchaseDate))
.foregroundColor(.white)
.opacity(0.65)
if let expiry = purchased.tx.expirationDate {
Text(NSLocalizedString("Renews on", comment: "Indicating when the subscription will renew"))
.font(.title2)
.foregroundColor(.white)
Text(format_date(UInt32(expiry.timeIntervalSince1970)))
Text(format_date(date: expiry))
.foregroundColor(.white)
.opacity(0.65)
}