From 76eac481bb8d3c59558998df8d89447919e318e3 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 12 Sep 2022 16:10:56 +0300 Subject: [PATCH] Share store TZ to extension --- WooCommerce/Classes/Extensions/UserDefaults+Woo.swift | 1 + WooCommerce/Classes/Yosemite/DefaultStoresManager.swift | 1 + WooCommerce/StoreWidgets/StoreInfoProvider.swift | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift b/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift index 221afa08ffb..4c84694d6f3 100644 --- a/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift +++ b/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift @@ -11,6 +11,7 @@ extension UserDefaults { case defaultSiteAddress case defaultStoreID case defaultStoreName + case defaultStoreTimeZoneGMTOffset case defaultAnonymousID case defaultRoles case deviceID diff --git a/WooCommerce/Classes/Yosemite/DefaultStoresManager.swift b/WooCommerce/Classes/Yosemite/DefaultStoresManager.swift index 557ff00a6ff..e0626786a56 100644 --- a/WooCommerce/Classes/Yosemite/DefaultStoresManager.swift +++ b/WooCommerce/Classes/Yosemite/DefaultStoresManager.swift @@ -508,6 +508,7 @@ private extension DefaultStoresManager { // Non-critical store info UserDefaults.group?[.defaultStoreID] = siteID UserDefaults.group?[.defaultStoreName] = sessionManager.defaultSite?.name + UserDefaults.group?[.defaultStoreTimeZoneGMTOffset] = sessionManager.defaultSite?.siteTimezone.secondsFromGMT() ?? TimeZone.current.secondsFromGMT() // Reload widgets UI WidgetCenter.shared.reloadAllTimelines() diff --git a/WooCommerce/StoreWidgets/StoreInfoProvider.swift b/WooCommerce/StoreWidgets/StoreInfoProvider.swift index 2b95c33a57a..1fef0377e2c 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -104,6 +104,7 @@ private extension StoreInfoProvider { let authToken: String let storeID: Int64 let storeName: String + let storeTimeZone: TimeZone } /// Fetches the required dependencies from the keychain and the shared users default. @@ -112,10 +113,12 @@ private extension StoreInfoProvider { let keychain = Keychain(service: WooConstants.keychainServiceName) guard let authToken = keychain[WooConstants.authToken], let storeID = UserDefaults.group?[.defaultStoreID] as? Int64, - let storeName = UserDefaults.group?[.defaultStoreName] as? String else { + let storeName = UserDefaults.group?[.defaultStoreName] as? String, + let storeTimeZoneGMTOffset = UserDefaults.group?[.defaultStoreTimeZoneGMTOffset] as? Int, + let storeTimeZone = TimeZone(secondsFromGMT: storeTimeZoneGMTOffset) else { return nil } - return Dependencies(authToken: authToken, storeID: storeID, storeName: storeName) + return Dependencies(authToken: authToken, storeID: storeID, storeName: storeName, storeTimeZone: storeTimeZone) } }