News.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // News.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 06/04/19.
  6. // Copyright © 2019 Anhar Solehudin. All rights reserved.
  7. //
  8. import Foundation
  9. struct News {
  10. private(set) public var id: Int
  11. private(set) public var title_news: String
  12. private(set) public var pra_news: String
  13. private(set) public var create_date: String
  14. init (id: Int, title_news: String, pra_news: String, create_date: String) {
  15. self.id = id
  16. self.title_news = title_news
  17. self.pra_news = pra_news
  18. self.create_date = create_date
  19. }
  20. func date() -> String {
  21. var date = ""
  22. if (create_date == "null" || create_date.isEmpty) {
  23. date = ""
  24. } else {
  25. let createdDate = create_date.prefix(10)
  26. let inputFormatter = DateFormatter()
  27. inputFormatter.dateFormat = "yyyy-MM-dd"
  28. let dateString = String(createdDate)
  29. if let output = inputFormatter.date(from: dateString) {
  30. let outputFormatter = DateFormatter()
  31. outputFormatter.dateFormat = "dd-MM-yyyy"
  32. date = outputFormatter.string(from: output)
  33. }
  34. }
  35. return date
  36. }
  37. }