You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
975 B

  1. //
  2. // Date+Ext.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 15/07/2019.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. extension Date {
  10. static func - (lhs: Date, rhs: Date) -> Int? {
  11. let calendar = Calendar.current
  12. let startDate = calendar.startOfDay(for: rhs)
  13. let endDate = calendar.startOfDay(for: lhs)
  14. guard let remindDay = calendar.dateComponents([.day], from: startDate, to: endDate).day else {
  15. return nil
  16. }
  17. return remindDay
  18. }
  19. }
  20. extension Date {
  21. func asString(style: DateFormatter.Style) -> String {
  22. let dateFormatter = DateFormatter()
  23. dateFormatter.dateStyle = style
  24. return dateFormatter.string(from: self)
  25. }
  26. func converToString(dateFormat format: String) -> String
  27. {
  28. let dateFormatter = DateFormatter()
  29. dateFormatter.dateFormat = format
  30. return dateFormatter.string(from: self)
  31. }
  32. }