import Foundation

extension DateFormatter {
    static let bookStackDisplay: DateFormatter = {
        let f = DateFormatter()
        f.dateStyle = .medium
        f.timeStyle = .none
        return f
    }()

    static let bookStackDateTime: DateFormatter = {
        let f = DateFormatter()
        f.dateStyle = .medium
        f.timeStyle = .short
        return f
    }()

    static let bookStackRelative: RelativeDateTimeFormatter = {
        let f = RelativeDateTimeFormatter()
        f.unitsStyle = .abbreviated
        return f
    }()
}

extension Date {
    var bookStackFormatted: String {
        DateFormatter.bookStackDisplay.string(from: self)
    }

    var bookStackFormattedWithTime: String {
        DateFormatter.bookStackDateTime.string(from: self)
    }

    var bookStackRelative: String {
        DateFormatter.bookStackRelative.localizedString(for: self, relativeTo: Date())
    }
}
