|
|
|
@ -71,13 +71,22 @@ class DataStore: NSObject {
|
|
|
|
|
let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data] |
|
|
|
|
let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: CLUbiquitousStoreLastUpdateKey) as? Date) ?? Date() |
|
|
|
|
let defaultsLastUpdateDate = (ubiquitousStore?.object(forKey: CLUserDefaultsLastUpdateKey) as? Date) ?? Date() |
|
|
|
|
|
|
|
|
|
if cloudTimezones == currentTimezones { |
|
|
|
|
Logger.info("Ubiquitous Store timezones aren't equal to current timezones") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if defaultsLastUpdateDate.isLaterThanOrEqual(to: cloudLastUpdateDate) { |
|
|
|
|
Logger.info("Ubiquitous Store is stale as compared to User Defaults") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if cloudTimezones != currentTimezones, cloudLastUpdateDate.isLaterThanOrEqual(to: defaultsLastUpdateDate) { |
|
|
|
|
Logger.info("Syncing local timezones with data from the ☁️") |
|
|
|
|
Logger.info("Syncing local timezones with data from the ☁️. ☁️ last update timestamp is recent") |
|
|
|
|
userDefaults.set(cloudTimezones, forKey: CLDefaultPreferenceKey) |
|
|
|
|
userDefaults.set(Date(), forKey: CLUserDefaultsLastUpdateKey) |
|
|
|
|
NotificationCenter.default.post(name: DataStore.didSyncFromExternalSourceNotification, |
|
|
|
|
object: self) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|