1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Model/Cache/CacheModel.swift

42 lines
993 B
Swift
Raw Normal View History

2022-12-10 07:31:59 +05:30
import Cache
2022-11-10 22:41:28 +05:30
import Foundation
2022-12-10 07:31:59 +05:30
import SwiftyJSON
2022-11-10 22:41:28 +05:30
2022-12-12 14:51:46 +05:30
protocol CacheModel {
var storage: Storage<String, JSON>? { get }
2022-11-10 22:41:28 +05:30
2022-12-12 14:51:46 +05:30
func clear()
}
2022-12-10 07:31:59 +05:30
2022-12-12 14:51:46 +05:30
extension CacheModel {
2022-12-10 07:31:59 +05:30
func clear() {
2022-12-12 14:51:46 +05:30
try? storage?.removeAll()
2022-12-10 07:31:59 +05:30
}
2022-12-12 14:51:46 +05:30
func getFormattedDate(_ date: Date?) -> String {
guard let date else { return "unknown" }
2022-12-10 07:31:59 +05:30
2022-12-12 14:51:46 +05:30
let isSameDay = Calendar(identifier: .iso8601).isDate(date, inSameDayAs: Date())
let formatter = isSameDay ? dateFormatterForTimeOnly : dateFormatter
return formatter.string(from: date)
2022-12-10 07:31:59 +05:30
}
2022-12-11 22:34:39 +05:30
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
2022-12-10 07:31:59 +05:30
}
2022-12-11 22:34:39 +05:30
var iso8601DateFormatter: ISO8601DateFormatter { .init() }
2022-11-10 22:41:28 +05:30
}