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