Notification.swift 878 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // Notification.swift
  3. // ntfy
  4. //
  5. // Created by Philipp Heckel on 5/16/22.
  6. //
  7. import Foundation
  8. extension Notification {
  9. func shortDateTime() -> String {
  10. let date = Date(timeIntervalSince1970: TimeInterval(self.time))
  11. let calendar = Calendar.current
  12. if calendar.isDateInYesterday(date) {
  13. return "Yesterday"
  14. }
  15. let dateFormatter = DateFormatter()
  16. if calendar.isDateInToday(date) {
  17. dateFormatter.dateFormat = "h:mm a"
  18. dateFormatter.amSymbol = "AM"
  19. dateFormatter.pmSymbol = "PM"
  20. } else {
  21. dateFormatter.dateStyle = .medium
  22. dateFormatter.timeStyle = .short
  23. }
  24. return dateFormatter.string(from: date)
  25. }
  26. }
  27. struct Message: Decodable {
  28. var id: String
  29. var time: Int64
  30. var message: String?
  31. var title: String?
  32. }