From 49687deddf8406edb415c9a4d4528a3e53730049 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Tue, 13 Sep 2022 14:26:26 +0300 Subject: [PATCH 1/2] Revert "Share store TZ to extension" 76eac481bb8d3c59558998df8d89447919e318e3 --- WooCommerce/Classes/Extensions/UserDefaults+Woo.swift | 1 - WooCommerce/Classes/Yosemite/DefaultStoresManager.swift | 1 - WooCommerce/StoreWidgets/StoreInfoProvider.swift | 7 ++----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift b/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift index 4c84694d6f3..221afa08ffb 100644 --- a/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift +++ b/WooCommerce/Classes/Extensions/UserDefaults+Woo.swift @@ -11,7 +11,6 @@ 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 957bf554708..59b34e7f100 100644 --- a/WooCommerce/Classes/Yosemite/DefaultStoresManager.swift +++ b/WooCommerce/Classes/Yosemite/DefaultStoresManager.swift @@ -510,7 +510,6 @@ 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 0c889b7e642..f2fcbd9c1c6 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -118,7 +118,6 @@ 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. @@ -127,12 +126,10 @@ 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, - let storeTimeZoneGMTOffset = UserDefaults.group?[.defaultStoreTimeZoneGMTOffset] as? Int, - let storeTimeZone = TimeZone(secondsFromGMT: storeTimeZoneGMTOffset) else { + let storeName = UserDefaults.group?[.defaultStoreName] as? String else { return nil } - return Dependencies(authToken: authToken, storeID: storeID, storeName: storeName, storeTimeZone: storeTimeZone) + return Dependencies(authToken: authToken, storeID: storeID, storeName: storeName) } } From eedc08eba9f4ec8be36e203ad7de75235bc7bdbb Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Tue, 13 Sep 2022 14:29:09 +0300 Subject: [PATCH 2/2] Replace store TZ with device TZ in widgets API requests --- .../StoreWidgets/StoreInfoDataService.swift | 15 +++++---------- WooCommerce/StoreWidgets/StoreInfoProvider.swift | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/WooCommerce/StoreWidgets/StoreInfoDataService.swift b/WooCommerce/StoreWidgets/StoreInfoDataService.swift index 8ccc3c855e8..91e8ad42745 100644 --- a/WooCommerce/StoreWidgets/StoreInfoDataService.swift +++ b/WooCommerce/StoreWidgets/StoreInfoDataService.swift @@ -25,15 +25,10 @@ final class StoreInfoDataService { /// private var network: AlamofireNetwork - /// Timezone of the website - /// - private let siteTimeZone: TimeZone - - init(authToken: String, siteTimeZone: TimeZone) { + init(authToken: String) { network = AlamofireNetwork(credentials: Credentials(authToken: authToken)) orderStatsRemoteV4 = OrderStatsRemoteV4(network: network) siteVisitStatsRemote = SiteVisitStatsRemote(network: network) - self.siteTimeZone = siteTimeZone } /// Async function that fetches todays stats data. @@ -63,12 +58,12 @@ private extension StoreInfoDataService { /// func fetchTodaysRevenueAndOrders(for storeID: Int64) async throws -> OrderStatsV4 { try await withCheckedThrowingContinuation { continuation in - // `WKWebView` is accessed internally, we are foreced to dispatch the call in the main thread. + // `WKWebView` is accessed internally, we are forced to dispatch the call in the main thread. Task { @MainActor in orderStatsRemoteV4.loadOrderStats(for: storeID, unit: .hourly, - earliestDateToInclude: Date().startOfDay(timezone: siteTimeZone), - latestDateToInclude: Date().endOfDay(timezone: siteTimeZone), + earliestDateToInclude: Date().startOfDay(timezone: .current), + latestDateToInclude: Date().endOfDay(timezone: .current), quantity: 24, forceRefresh: true) { result in continuation.resume(with: result) @@ -85,7 +80,7 @@ private extension StoreInfoDataService { Task { @MainActor in siteVisitStatsRemote.loadSiteVisitorStats(for: storeID, unit: .day, - latestDateToInclude: Date().endOfDay(timezone: siteTimeZone), + latestDateToInclude: Date().endOfDay(timezone: .current), quantity: 1) { result in continuation.resume(with: result) } diff --git a/WooCommerce/StoreWidgets/StoreInfoProvider.swift b/WooCommerce/StoreWidgets/StoreInfoProvider.swift index f2fcbd9c1c6..81671065820 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -79,7 +79,7 @@ final class StoreInfoProvider: TimelineProvider { return completion(Timeline(entries: [StoreInfoEntry.notConnected], policy: .never)) } - let strongService = StoreInfoDataService(authToken: dependencies.authToken, siteTimeZone: dependencies.storeTimeZone) + let strongService = StoreInfoDataService(authToken: dependencies.authToken) networkService = strongService Task { do {