mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
42 lines
993 B
Swift
42 lines
993 B
Swift
import Cache
|
|
import Foundation
|
|
import SwiftyJSON
|
|
|
|
protocol CacheModel {
|
|
var storage: Storage<String, JSON>? { get }
|
|
|
|
func clear()
|
|
}
|
|
|
|
extension CacheModel {
|
|
func clear() {
|
|
try? storage?.removeAll()
|
|
}
|
|
|
|
func getFormattedDate(_ date: Date?) -> String {
|
|
guard let date else { return "unknown" }
|
|
|
|
let isSameDay = Calendar(identifier: .iso8601).isDate(date, inSameDayAs: Date())
|
|
let formatter = isSameDay ? dateFormatterForTimeOnly : dateFormatter
|
|
return formatter.string(from: date)
|
|
}
|
|
|
|
var dateFormatter: DateFormatter {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .short
|
|
formatter.timeStyle = .medium
|
|
|
|
return formatter
|
|
}
|
|
|
|
var dateFormatterForTimeOnly: DateFormatter {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .none
|
|
formatter.timeStyle = .medium
|
|
|
|
return formatter
|
|
}
|
|
|
|
var iso8601DateFormatter: ISO8601DateFormatter { .init() }
|
|
}
|