Browse Source

fix review hints, reduce code duplication

cyberta 5 years ago
parent
commit
45f3f3f6e3

+ 8 - 4
DcCore/DcCore.xcodeproj/project.pbxproj

@@ -15,12 +15,13 @@
 		30421952243DE15D00516852 /* wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 3042194E243DE15D00516852 /* wrapper.c */; };
 		30421959243DE6AD00516852 /* libdeltachat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 30421958243DE61400516852 /* libdeltachat.a */; platformFilter = ios; };
 		3042195B243DF1C500516852 /* deltachat.h in Headers */ = {isa = PBXBuildFile; fileRef = 3042195A243DF1C500516852 /* deltachat.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		3042195D243E23F100516852 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3042195C243E23F100516852 /* Utils.swift */; };
+		3042195D243E23F100516852 /* DcUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3042195C243E23F100516852 /* DcUtils.swift */; };
 		30421960243E257100516852 /* UIColor+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3042195F243E257100516852 /* UIColor+Extensions.swift */; };
 		30421962243E26C800516852 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30421961243E26C800516852 /* Logger.swift */; };
 		30421964243F0B8400516852 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30421963243F0B8400516852 /* String+Extensions.swift */; };
 		30421986243F209E00516852 /* events.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30421985243F209E00516852 /* events.swift */; };
 		30421988243F23E500516852 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30421987243F23E500516852 /* Constants.swift */; };
+		306C324824460CDE001D89F3 /* DateUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 306C324724460CDE001D89F3 /* DateUtils.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -45,12 +46,13 @@
 		3042194E243DE15D00516852 /* wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wrapper.c; path = ../../DcCore/DcCore/DC/wrapper.c; sourceTree = "<group>"; };
 		30421958243DE61400516852 /* libdeltachat.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdeltachat.a; path = "../deltachat-ios/libraries/deltachat-core-rust/target/universal/release/libdeltachat.a"; sourceTree = "<group>"; };
 		3042195A243DF1C500516852 /* deltachat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = deltachat.h; path = "../deltachat-ios/libraries/deltachat-core-rust/deltachat-ffi/deltachat.h"; sourceTree = "<group>"; };
-		3042195C243E23F100516852 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
+		3042195C243E23F100516852 /* DcUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DcUtils.swift; sourceTree = "<group>"; };
 		3042195F243E257100516852 /* UIColor+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extensions.swift"; sourceTree = "<group>"; };
 		30421961243E26C800516852 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Logger.swift; path = ../../DcCore/DcCore/DC/Logger.swift; sourceTree = "<group>"; };
 		30421963243F0B8400516852 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
 		30421985243F209E00516852 /* events.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = events.swift; path = ../../DcCore/DcCore/DC/events.swift; sourceTree = "<group>"; };
 		30421987243F23E500516852 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
+		306C324724460CDE001D89F3 /* DateUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateUtils.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -148,7 +150,8 @@
 			isa = PBXGroup;
 			children = (
 				30421987243F23E500516852 /* Constants.swift */,
-				3042195C243E23F100516852 /* Utils.swift */,
+				3042195C243E23F100516852 /* DcUtils.swift */,
+				306C324724460CDE001D89F3 /* DateUtils.swift */,
 			);
 			path = Helper;
 			sourceTree = "<group>";
@@ -289,8 +292,9 @@
 				30421962243E26C800516852 /* Logger.swift in Sources */,
 				30421986243F209E00516852 /* events.swift in Sources */,
 				30421951243DE15D00516852 /* Wrapper.swift in Sources */,
+				306C324824460CDE001D89F3 /* DateUtils.swift in Sources */,
 				30421952243DE15D00516852 /* wrapper.c in Sources */,
-				3042195D243E23F100516852 /* Utils.swift in Sources */,
+				3042195D243E23F100516852 /* DcUtils.swift in Sources */,
 				30421964243F0B8400516852 /* String+Extensions.swift in Sources */,
 				30421960243E257100516852 /* UIColor+Extensions.swift in Sources */,
 			);

+ 5 - 5
DcCore/DcCore/DC/Wrapper.swift

@@ -39,12 +39,12 @@ public class DcContext {
 
     public func getContacts(flags: Int32, queryString: String? = nil) -> [Int] {
         let cContacts = dc_get_contacts(contextPointer, UInt32(flags), queryString)
-        return Utils.copyAndFreeArray(inputArray: cContacts)
+        return DcUtils.copyAndFreeArray(inputArray: cContacts)
     }
 
     public func getBlockedContacts() -> [Int] {
         let cBlockedContacts = dc_get_blocked_contacts(contextPointer)
-        return Utils.copyAndFreeArray(inputArray: cBlockedContacts)
+        return DcUtils.copyAndFreeArray(inputArray: cBlockedContacts)
     }
 
     public func addContacts(contactString: String) {
@@ -80,7 +80,7 @@ public class DcContext {
             return []
         }
 
-        let messageIds: [Int] =  Utils.copyAndFreeArray(inputArray: messagesPointer)
+        let messageIds: [Int] =  DcUtils.copyAndFreeArray(inputArray: messagesPointer)
         return messageIds
     }
 
@@ -399,7 +399,7 @@ public class DcContext {
         guard let arrayPointer = dc_search_msgs(contextPointer, UInt32(chatId), searchText) else {
             return []
         }
-        let messageIds = Utils.copyAndFreeArray(inputArray: arrayPointer)
+        let messageIds = DcUtils.copyAndFreeArray(inputArray: arrayPointer)
         return messageIds
     }
 
@@ -668,7 +668,7 @@ public class DcChat {
     }
 
     public var contactIds: [Int] {
-        return Utils.copyAndFreeArray(inputArray: dc_get_chat_contacts(DcContext.shared.contextPointer, UInt32(id)))
+        return DcUtils.copyAndFreeArray(inputArray: dc_get_chat_contacts(DcContext.shared.contextPointer, UInt32(id)))
     }
 
     public lazy var profileImage: UIImage? = { [unowned self] in

+ 3 - 3
DcCore/DcCore/Extensions/String+Extensions.swift

@@ -1,7 +1,7 @@
 import Foundation
-internal extension String {
+public extension String {
     
-    static func localized(_ stringID: String) -> String {
+    public static func localized(_ stringID: String) -> String {
         let value = NSLocalizedString(stringID, comment: "")
         if value != stringID || NSLocale.preferredLanguages.first == "en" {
             return value
@@ -14,7 +14,7 @@ internal extension String {
         return NSLocalizedString(stringID, bundle: bundle, comment: "")
     }
 
-    static func localized(stringID: String, count: Int) -> String {
+    public static func localized(stringID: String, count: Int) -> String {
         let formatString: String = localized(stringID)
         let resultString: String = String.localizedStringWithFormat(formatString, count)
         return resultString

+ 3 - 3
DcCore/DcCore/Extensions/UIColor+Extensions.swift

@@ -1,6 +1,6 @@
 import UIKit
 
-internal extension UIColor {
+public extension UIColor {
 
     convenience init(alpha: Int, red: Int, green: Int, blue: Int) {
         assert(red >= 0 && red <= 255, "Invalid red component")
@@ -38,7 +38,7 @@ internal extension UIColor {
         self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
     }
 
-    static func themeColor(light: UIColor, dark: UIColor? = nil) -> UIColor {
+    public static func themeColor(light: UIColor, dark: UIColor? = nil) -> UIColor {
         if let dark = dark {
             if #available(iOS 13, *) {
                 return UIColor.init { (trait) -> UIColor in
@@ -49,7 +49,7 @@ internal extension UIColor {
         return light
     }
 
-    static func themeColor(lightHex: String, darkHex: String? = nil) -> UIColor {
+    public static func themeColor(lightHex: String, darkHex: String? = nil) -> UIColor {
         if let darkHex = darkHex {
             if #available(iOS 13, *) {
                 return UIColor.init { (trait) -> UIColor in

+ 28 - 57
DcCore/DcCore/Helper/Utils.swift → DcCore/DcCore/Helper/DateUtils.swift

@@ -1,67 +1,13 @@
 import Foundation
-import UIKit
-import AVFoundation
 
-struct Utils {
-
-    static func copyAndFreeArray(inputArray: OpaquePointer?) -> [Int] {
-        var acc: [Int] = []
-        let len = dc_array_get_cnt(inputArray)
-        for i in 0 ..< len {
-            let e = dc_array_get_id(inputArray, i)
-            acc.append(Int(e))
-        }
-        dc_array_unref(inputArray)
-
-        return acc
-    }
-
-    static func copyAndFreeArrayWithLen(inputArray: OpaquePointer?, len: Int = 0) -> [Int] {
-        var acc: [Int] = []
-        let arrayLen = dc_array_get_cnt(inputArray)
-        let start = max(0, arrayLen - len)
-        for i in start ..< arrayLen {
-            let e = dc_array_get_id(inputArray, i)
-            acc.append(Int(e))
-        }
-        dc_array_unref(inputArray)
-
-        return acc
-    }
-
-    static func copyAndFreeArrayWithOffset(inputArray: OpaquePointer?, len: Int = 0, from: Int = 0, skipEnd: Int = 0) -> [Int] {
-        let lenArray = dc_array_get_cnt(inputArray)
-        if lenArray <= skipEnd || lenArray == 0 {
-            dc_array_unref(inputArray)
-            return []
-        }
-
-        let start = lenArray - 1 - skipEnd
-        let end = max(0, start - len)
-        let finalLen = start - end + (len > 0 ? 0 : 1)
-        var acc: [Int] = [Int](repeating: 0, count: finalLen)
-
-        for i in stride(from: start, to: end, by: -1) {
-            let index = finalLen - (start - i) - 1
-            acc[index] = Int(dc_array_get_id(inputArray, i))
-        }
-
-        dc_array_unref(inputArray)
-        DcContext.shared.logger?.info("got: \(from) \(len) \(lenArray) - \(acc)")
-
-        return acc
-    }
-
-}
-
-class DateUtils {
+public class DateUtils {
     typealias DtU = DateUtils
     static let minute: Double = 60
     static let hour: Double = 3600
     static let day: Double = 86400
     static let year: Double = 365 * day
 
-    static func getRelativeTimeInSeconds(timeStamp: Double) -> Double {
+    public static func getRelativeTimeInSeconds(timeStamp: Double) -> Double {
         let unixTime = Double(Date().timeIntervalSince1970)
         return unixTime - timeStamp
     }
@@ -78,7 +24,7 @@ class DateUtils {
         return formatter
     }
 
-    static func getExtendedRelativeTimeSpanString(timeStamp: Double) -> String {
+    public static func getExtendedRelativeTimeSpanString(timeStamp: Double) -> String {
         let seconds = getRelativeTimeInSeconds(timeStamp: timeStamp)
         let date = Date(timeIntervalSince1970: timeStamp)
         let formatter = getLocalDateFormatter()
@@ -104,4 +50,29 @@ class DateUtils {
         }
     }
 
+    public static func getBriefRelativeTimeSpanString(timeStamp: Double) -> String {
+        let seconds = getRelativeTimeInSeconds(timeStamp: timeStamp)
+        let date = Date(timeIntervalSince1970: timeStamp)
+        let formatter = getLocalDateFormatter()
+
+        if seconds < DtU.minute {
+            return String.localized("now")    // under one minute
+        } else if seconds < DtU.hour {
+            let mins = seconds / DtU.minute
+            return String.localized(stringID: "n_minutes", count: Int(mins))
+        } else if seconds < DtU.day {
+            let hours = seconds / DtU.hour
+            return String.localized(stringID: "n_hours", count: Int(hours))
+        } else if seconds < DtU.day * 6 {
+            formatter.dateFormat = "EEE"
+            return formatter.string(from: date)
+        } else if seconds < DtU.year {
+            formatter.dateFormat = "MMM d"
+            return formatter.string(from: date)
+        } else {
+            formatter.dateFormat = "MMM d, yyyy"
+            let localDate = formatter.string(from: date)
+            return localDate
+        }
+    }
 }

+ 66 - 0
DcCore/DcCore/Helper/DcUtils.swift

@@ -0,0 +1,66 @@
+import Foundation
+import UIKit
+
+public struct DcUtils {
+
+    public static func getMessageIds(chatId: Int, count: Int, from: Int?) -> [Int] {
+        let cMessageIds = DcContext.shared.getChatMessages(chatId: chatId)
+
+        let ids: [Int]
+        if let from = from {
+            ids = DcUtils.copyAndFreeArrayWithOffset(inputArray: cMessageIds, len: count, skipEnd: from)
+        } else {
+            ids = DcUtils.copyAndFreeArrayWithLen(inputArray: cMessageIds, len: count)
+        }
+        return ids
+    }
+
+    static func copyAndFreeArray(inputArray: OpaquePointer?) -> [Int] {
+        var acc: [Int] = []
+        let len = dc_array_get_cnt(inputArray)
+        for i in 0 ..< len {
+            let e = dc_array_get_id(inputArray, i)
+            acc.append(Int(e))
+        }
+        dc_array_unref(inputArray)
+
+        return acc
+    }
+
+    static func copyAndFreeArrayWithLen(inputArray: OpaquePointer?, len: Int = 0) -> [Int] {
+        var acc: [Int] = []
+        let arrayLen = dc_array_get_cnt(inputArray)
+        let start = max(0, arrayLen - len)
+        for i in start ..< arrayLen {
+            let e = dc_array_get_id(inputArray, i)
+            acc.append(Int(e))
+        }
+        dc_array_unref(inputArray)
+
+        return acc
+    }
+
+    static func copyAndFreeArrayWithOffset(inputArray: OpaquePointer?, len: Int = 0, from: Int = 0, skipEnd: Int = 0) -> [Int] {
+        let lenArray = dc_array_get_cnt(inputArray)
+        if lenArray <= skipEnd || lenArray == 0 {
+            dc_array_unref(inputArray)
+            return []
+        }
+
+        let start = lenArray - 1 - skipEnd
+        let end = max(0, start - len)
+        let finalLen = start - end + (len > 0 ? 0 : 1)
+        var acc: [Int] = [Int](repeating: 0, count: finalLen)
+
+        for i in stride(from: start, to: end, by: -1) {
+            let index = finalLen - (start - i) - 1
+            acc[index] = Int(dc_array_get_id(inputArray, i))
+        }
+
+        dc_array_unref(inputArray)
+        DcContext.shared.logger?.info("got: \(from) \(len) \(lenArray) - \(acc)")
+
+        return acc
+    }
+
+}

+ 1 - 9
deltachat-ios/Controller/ChatViewController.swift

@@ -355,15 +355,7 @@ class ChatViewController: MessagesViewController {
     }
 
     private func getMessageIds(_ count: Int, from: Int? = nil) -> [DcMsg] {
-        let cMessageIds = dcContext.getChatMessages(chatId: chatId)
-
-        let ids: [Int]
-        if let from = from {
-            ids = Utils.copyAndFreeArrayWithOffset(inputArray: cMessageIds, len: count, skipEnd: from)
-        } else {
-            ids = Utils.copyAndFreeArrayWithLen(inputArray: cMessageIds, len: count)
-        }
-
+        let ids = DcUtils.getMessageIds(chatId: chatId, count: count, from: from)
         let markIds: [UInt32] = ids.map { UInt32($0) }
         dcContext.markSeenMessages(messageIds: markIds, count: ids.count)
 

+ 0 - 19
deltachat-ios/Extensions/String+Extension.swift

@@ -74,25 +74,6 @@ extension String {
         return attributedText
     }
 
-    static func localized(_ stringID: String) -> String {
-        let value = NSLocalizedString(stringID, comment: "")
-        if value != stringID || NSLocale.preferredLanguages.first == "en" {
-            return value
-        }
-
-        guard
-            let path = Bundle.main.path(forResource: "en", ofType: "lproj"),
-            let bundle = Bundle(path: path)
-        else { return value }
-        return NSLocalizedString(stringID, bundle: bundle, comment: "")
-    }
-
-    static func localized(stringID: String, count: Int) -> String {
-        let formatString: String = localized(stringID)
-        let resultString: String = String.localizedStringWithFormat(formatString, count)
-        return resultString
-    }
-
     static func timeStringForInterval(_ interval: TimeInterval) -> String {
         let time = NSInteger(interval)
         let seconds = time % 60

+ 1 - 59
deltachat-ios/Extensions/UIColor+Extensions.swift

@@ -35,63 +35,5 @@ internal extension UIColor {
     static let inputBarGray = UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1.0)
     static let playButtonLightGray = UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1.0)
     static let sendButtonBlue = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
-
-    convenience init(alpha: Int, red: Int, green: Int, blue: Int) {
-        assert(red >= 0 && red <= 255, "Invalid red component")
-        assert(green >= 0 && green <= 255, "Invalid green component")
-        assert(blue >= 0 && blue <= 255, "Invalid blue component")
-
-        self.init(red: CGFloat(red) / 255, green: CGFloat(green) / 255, blue: CGFloat(blue) / 255, alpha: CGFloat(alpha) / 255)
-    }
-
-    convenience init(netHex: Int) {
-        var alpha = (netHex >> 24) & 0xFF
-        if alpha == 0 {
-            alpha = 255
-        }
-
-        self.init(alpha: alpha, red: (netHex >> 16) & 0xFF, green: (netHex >> 8) & 0xFF, blue: netHex & 0xFF)
-    }
-
-    // see: https://stackoverflow.com/a/33397427
-    convenience init(hexString: String) {
-        let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
-        var int = UInt32()
-        Scanner(string: hex).scanHexInt32(&int)
-        let a, r, g, b: UInt32
-        switch hex.count {
-        case 3: // RGB (12-bit)
-            (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
-        case 6: // RGB (24-bit)
-            (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
-        case 8: // ARGB (32-bit)
-            (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
-        default:
-            (a, r, g, b) = (255, 0, 0, 0)
-        }
-        self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
-    }
-
-
-    static func themeColor(light: UIColor, dark: UIColor? = nil) -> UIColor {
-        if let dark = dark {
-            if #available(iOS 13, *) {
-                return UIColor.init { (trait) -> UIColor in
-                    return trait.userInterfaceStyle == .dark ? dark : light
-                }
-            }
-        }
-        return light
-    }
-
-    static func themeColor(lightHex: String, darkHex: String? = nil) -> UIColor {
-        if let darkHex = darkHex {
-            if #available(iOS 13, *) {
-                return UIColor.init { (trait) -> UIColor in
-                    return trait.userInterfaceStyle == .dark ? UIColor(hexString: darkHex) :  UIColor(hexString: lightHex)
-                }
-            }
-        }
-        return UIColor(hexString: lightHex)
-    }
+    
 }

+ 0 - 125
deltachat-ios/Helper/Utils.swift

@@ -13,54 +13,6 @@ struct Utils {
         }
     }
 
-    static func copyAndFreeArray(inputArray: OpaquePointer?) -> [Int] {
-        var acc: [Int] = []
-        let len = dc_array_get_cnt(inputArray)
-        for i in 0 ..< len {
-            let e = dc_array_get_id(inputArray, i)
-            acc.append(Int(e))
-        }
-        dc_array_unref(inputArray)
-
-        return acc
-    }
-
-    static func copyAndFreeArrayWithLen(inputArray: OpaquePointer?, len: Int = 0) -> [Int] {
-        var acc: [Int] = []
-        let arrayLen = dc_array_get_cnt(inputArray)
-        let start = max(0, arrayLen - len)
-        for i in start ..< arrayLen {
-            let e = dc_array_get_id(inputArray, i)
-            acc.append(Int(e))
-        }
-        dc_array_unref(inputArray)
-
-        return acc
-    }
-
-    static func copyAndFreeArrayWithOffset(inputArray: OpaquePointer?, len: Int = 0, from: Int = 0, skipEnd: Int = 0) -> [Int] {
-        let lenArray = dc_array_get_cnt(inputArray)
-        if lenArray <= skipEnd || lenArray == 0 {
-            dc_array_unref(inputArray)
-            return []
-        }
-
-        let start = lenArray - 1 - skipEnd
-        let end = max(0, start - len)
-        let finalLen = start - end + (len > 0 ? 0 : 1)
-        var acc: [Int] = [Int](repeating: 0, count: finalLen)
-
-        for i in stride(from: start, to: end, by: -1) {
-            let index = finalLen - (start - i) - 1
-            acc[index] = Int(dc_array_get_id(inputArray, i))
-        }
-
-        dc_array_unref(inputArray)
-        logger.info("got: \(from) \(len) \(lenArray) - \(acc)")
-
-        return acc
-    }
-
     static func isValid(email: String) -> Bool {
         let emailRegEx = "(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
             + "~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
@@ -160,80 +112,3 @@ struct Utils {
         return String(lang)
     }
 }
-
-class DateUtils {
-    typealias DtU = DateUtils
-    static let minute: Double = 60
-    static let hour: Double = 3600
-    static let day: Double = 86400
-    static let year: Double = 365 * day
-
-    static func getRelativeTimeInSeconds(timeStamp: Double) -> Double {
-        let unixTime = Double(Date().timeIntervalSince1970)
-        return unixTime - timeStamp
-    }
-
-    private static func is24hDefault() -> Bool {
-        let dateString: String = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current) ?? ""
-        return !dateString.contains("a")
-    }
-
-    private static func getLocalDateFormatter() -> DateFormatter {
-        let formatter = DateFormatter()
-        formatter.timeZone = .current
-        formatter.locale = .current
-        return formatter
-    }
-
-    static func getExtendedRelativeTimeSpanString(timeStamp: Double) -> String {
-        let seconds = getRelativeTimeInSeconds(timeStamp: timeStamp)
-        let date = Date(timeIntervalSince1970: timeStamp)
-        let formatter = getLocalDateFormatter()
-        let is24h = is24hDefault()
-
-        if seconds < DtU.minute {
-            return String.localized("now")
-        } else if seconds < DtU.hour {
-            let mins = seconds / DtU.minute
-            return String.localized(stringID: "n_minutes", count: Int(mins))
-        } else if seconds < DtU.day {
-            formatter.dateFormat = is24h ?  "HH:mm" : "hh:mm a"
-            return formatter.string(from: date)
-        } else if seconds < 6 * DtU.day {
-            formatter.dateFormat = is24h ?  "EEE, HH:mm" : "EEE, hh:mm a"
-            return formatter.string(from: date)
-        } else if seconds < DtU.year {
-            formatter.dateFormat = is24h ? "MMM d, HH:mm" : "MMM d, hh:mm a"
-            return formatter.string(from: date)
-        } else {
-            formatter.dateFormat = is24h ? "MMM d, yyyy, HH:mm" : "MMM d, yyyy, hh:mm a"
-            return formatter.string(from: date)
-        }
-    }
-
-    static func getBriefRelativeTimeSpanString(timeStamp: Double) -> String {
-        let seconds = getRelativeTimeInSeconds(timeStamp: timeStamp)
-        let date = Date(timeIntervalSince1970: timeStamp)
-        let formatter = getLocalDateFormatter()
-
-        if seconds < DtU.minute {
-            return String.localized("now")	// under one minute
-        } else if seconds < DtU.hour {
-            let mins = seconds / DtU.minute
-            return String.localized(stringID: "n_minutes", count: Int(mins))
-        } else if seconds < DtU.day {
-            let hours = seconds / DtU.hour
-            return String.localized(stringID: "n_hours", count: Int(hours))
-        } else if seconds < DtU.day * 6 {
-            formatter.dateFormat = "EEE"
-            return formatter.string(from: date)
-        } else if seconds < DtU.year {
-            formatter.dateFormat = "MMM d"
-            return formatter.string(from: date)
-        } else {
-            formatter.dateFormat = "MMM d, yyyy"
-            let localDate = formatter.string(from: date)
-            return localDate
-        }
-    }
-}