|
|
|
@ -3,25 +3,25 @@
|
|
|
|
|
import Cocoa |
|
|
|
|
import CoreLoggerKit |
|
|
|
|
|
|
|
|
|
struct DateFormat { |
|
|
|
|
static let twelveHour = "h:mm a" |
|
|
|
|
static let twelveHourWithSeconds = "h:mm:ss a" |
|
|
|
|
static let twentyFourHour = "HH:mm" |
|
|
|
|
static let twentyFourHourWithSeconds = "HH:mm:ss" |
|
|
|
|
static let twelveHourWithZero = "hh:mm a" |
|
|
|
|
static let twelveHourWithZeroSeconds = "hh:mm:ss a" |
|
|
|
|
static let twelveHourWithoutSuffix = "hh:mm" |
|
|
|
|
static let twelveHourWithoutSuffixAndSeconds = "hh:mm:ss" |
|
|
|
|
public struct DateFormat { |
|
|
|
|
public static let twelveHour = "h:mm a" |
|
|
|
|
public static let twelveHourWithSeconds = "h:mm:ss a" |
|
|
|
|
public static let twentyFourHour = "HH:mm" |
|
|
|
|
public static let twentyFourHourWithSeconds = "HH:mm:ss" |
|
|
|
|
public static let twelveHourWithZero = "hh:mm a" |
|
|
|
|
public static let twelveHourWithZeroSeconds = "hh:mm:ss a" |
|
|
|
|
public static let twelveHourWithoutSuffix = "hh:mm" |
|
|
|
|
public static let twelveHourWithoutSuffixAndSeconds = "hh:mm:ss" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Non-class type cannot conform to NSCoding! |
|
|
|
|
class TimezoneData: NSObject, NSCoding { |
|
|
|
|
enum SelectionType: Int { |
|
|
|
|
public enum SelectionType: Int { |
|
|
|
|
case city |
|
|
|
|
case timezone |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum DateDisplayType: Int { |
|
|
|
|
public enum DateDisplayType: Int { |
|
|
|
|
case panel |
|
|
|
|
case menu |
|
|
|
|
} |
|
|
|
@ -71,7 +71,7 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
public var isSystemTimezone = false |
|
|
|
|
public var overrideFormat: TimezoneOverride = .globalFormat |
|
|
|
|
|
|
|
|
|
override init() { |
|
|
|
|
public override init() { |
|
|
|
|
selectionType = .timezone |
|
|
|
|
isFavourite = 0 |
|
|
|
|
note = CLEmptyString |
|
|
|
@ -80,7 +80,7 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
placeID = UUID().uuidString |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init(with dictionary: [String: Any]) { |
|
|
|
|
public init(with dictionary: [String: Any]) { |
|
|
|
|
if let label = dictionary[CLCustomLabel] as? String { |
|
|
|
|
customLabel = label |
|
|
|
|
} else { |
|
|
|
@ -164,7 +164,7 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
overrideFormat = TimezoneOverride(rawValue: override)! |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class func customObject(from encodedData: Data?) -> TimezoneData? { |
|
|
|
|
public class func customObject(from encodedData: Data?) -> TimezoneData? { |
|
|
|
|
guard let dataObject = encodedData else { |
|
|
|
|
return TimezoneData() |
|
|
|
|
} |
|
|
|
@ -176,33 +176,6 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class func converter(_ timezones: [Data]) -> [Data] { |
|
|
|
|
var newModels: [TimezoneData] = [] |
|
|
|
|
|
|
|
|
|
for timezone in timezones { |
|
|
|
|
// Get the old (aka CLTimezoneData) model object |
|
|
|
|
let old = NSKeyedUnarchiver.unarchiveObject(with: timezone) |
|
|
|
|
if let newModel = old as? Clocker.TimezoneData { |
|
|
|
|
if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil { |
|
|
|
|
print("Resetting Global Format") |
|
|
|
|
newModel.setShouldOverrideGlobalTimeFormat(0) |
|
|
|
|
} |
|
|
|
|
newModels.append(newModel) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil { |
|
|
|
|
UserDefaults.standard.set("YES", forKey: "migrateOverrideFormat") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Do the serialization |
|
|
|
|
let serializedModels = newModels.map { (place) -> Data in |
|
|
|
|
NSKeyedArchiver.archivedData(withRootObject: place) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return serializedModels |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func encode(with aCoder: NSCoder) { |
|
|
|
|
aCoder.encode(placeID, forKey: "place_id") |
|
|
|
|
|
|
|
|
@ -233,7 +206,7 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
aCoder.encode(overrideFormat.rawValue, forKey: "overrideFormat") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func formattedTimezoneLabel() -> String { |
|
|
|
|
public func formattedTimezoneLabel() -> String { |
|
|
|
|
// First check if there's an user preferred custom label set |
|
|
|
|
if let label = customLabel, !label.isEmpty { |
|
|
|
|
return label |
|
|
|
@ -261,11 +234,11 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
return "Error" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func setLabel(_ label: String) { |
|
|
|
|
public func setLabel(_ label: String) { |
|
|
|
|
customLabel = !label.isEmpty ? label : CLEmptyString |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) { |
|
|
|
|
public func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) { |
|
|
|
|
if shouldOverride == 0 { |
|
|
|
|
overrideFormat = .globalFormat |
|
|
|
|
} else if shouldOverride == 1 { |
|
|
|
@ -290,7 +263,7 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func timezone() -> String { |
|
|
|
|
public func timezone() -> String { |
|
|
|
|
if isSystemTimezone { |
|
|
|
|
timezoneID = TimeZone.autoupdatingCurrent.identifier |
|
|
|
|
formattedAddress = TimeZone.autoupdatingCurrent.identifier |
|
|
|
@ -314,8 +287,8 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
return TimeZone.autoupdatingCurrent.identifier |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func timezoneFormat() -> String { |
|
|
|
|
let chosenDefault = DataStore.shared().timezoneFormat() |
|
|
|
|
public func timezoneFormat(_ currentFormat: NSNumber) -> String { |
|
|
|
|
let chosenDefault = currentFormat |
|
|
|
|
let timeFormat = TimezoneData.values[chosenDefault] ?? DateFormat.twelveHour |
|
|
|
|
|
|
|
|
|
if overrideFormat == .globalFormat { |
|
|
|
@ -341,9 +314,8 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
return timeFormat |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func shouldShowSeconds() -> Bool { |
|
|
|
|
public func shouldShowSeconds(_ currentFormat: NSNumber) -> Bool { |
|
|
|
|
if overrideFormat == .globalFormat { |
|
|
|
|
let currentFormat = DataStore.shared().timezoneFormat() |
|
|
|
|
let formatInString = TimezoneData.values[currentFormat] ?? DateFormat.twelveHour |
|
|
|
|
return formatInString.contains("ss") |
|
|
|
|
} |
|
|
|
@ -352,7 +324,7 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
return formatInString.contains("ss") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override var hash: Int { |
|
|
|
|
public override var hash: Int { |
|
|
|
|
guard let placeIdentifier = placeID, let timezone = timezoneID else { |
|
|
|
|
return -1 |
|
|
|
|
} |
|
|
|
@ -364,14 +336,14 @@ class TimezoneData: NSObject, NSCoding {
|
|
|
|
|
return lhs.placeID == rhs.placeID |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override func isEqual(to object: Any?) -> Bool { |
|
|
|
|
public override func isEqual(to object: Any?) -> Bool { |
|
|
|
|
if let other = object as? TimezoneData { |
|
|
|
|
return placeID == other.placeID |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override func isEqual(_ object: Any?) -> Bool { |
|
|
|
|
public override func isEqual(_ object: Any?) -> Bool { |
|
|
|
|
guard let compared = object as? TimezoneData else { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|