refactor: Move date formatter to utils
This commit is contained in:
+1
-7
@@ -57,12 +57,6 @@ class SeismicNetworkTableViewCell: UITableViewCell {
|
||||
private static let DefaultBodyFont = UIFont.preferredFont(forTextStyle: .body)
|
||||
private static let DefaultBodyFontLight = UIFont.preferredFont(for: .body, weight: .light)
|
||||
|
||||
private static var dateFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "HH:mm:ss d-MMM"
|
||||
return formatter
|
||||
}()
|
||||
|
||||
/// Seismic to show
|
||||
private var seismic: EQNSisma?
|
||||
private(set) var displayType = DisplayType.normal
|
||||
@@ -442,7 +436,7 @@ class SeismicNetworkTableViewCell: UITableViewCell {
|
||||
|
||||
// we need to check agains null values, because sometimes WS returns invalid dates
|
||||
if let date = seismic.date {
|
||||
let formattedDate = Self.dateFormatter.string(from: date)
|
||||
let formattedDate = EQNUtility.formattedDate(from: date)
|
||||
let time = EQNUtility.formattedString(forTimeDifference: Int(seismic.timeDifference))
|
||||
timeLabel.text = "🕗 \(formattedDate) - \(time)"
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,14 @@ import Foundation
|
||||
|
||||
extension EQNUtility {
|
||||
|
||||
private static var dateFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "HH:mm:ss d-MMM"
|
||||
return formatter
|
||||
}()
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
/// Convert coordinates in degrees
|
||||
/// - Parameter coordinate: The latitude and longitude associated with a location
|
||||
/// - Returns: Formatted coordinates, like
|
||||
@@ -49,4 +57,8 @@ extension EQNUtility {
|
||||
}
|
||||
return "\(minutes)m"
|
||||
}
|
||||
|
||||
class func formattedDate(from date: Date) -> String {
|
||||
Self.dateFormatter.string(from: date)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user