From 76eac481bb8d3c59558998df8d89447919e318e3 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 12 Sep 2022 16:10:56 +0300 Subject: [PATCH 1/6] 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) } } From e5da3ab918c67a1bd3e7587a500b2e2d4e7ca09e Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 12 Sep 2022 16:27:53 +0300 Subject: [PATCH 2/6] Move Date extension to WooFoundation --- WooCommerce/WooCommerce.xcodeproj/project.pbxproj | 4 ---- WooFoundation/WooFoundation.xcodeproj/project.pbxproj | 4 ++++ .../WooFoundation}/Extensions/Date+StartAndEnd.swift | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename {WooCommerce/Classes => WooFoundation/WooFoundation}/Extensions/Date+StartAndEnd.swift (99%) diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index ba4af403566..396b4e83161 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -333,7 +333,6 @@ 02B2828E27C35061004A332A /* RefreshableInfiniteScrollList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828D27C35061004A332A /* RefreshableInfiniteScrollList.swift */; }; 02B2829027C352DA004A332A /* RefreshableScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828F27C352DA004A332A /* RefreshableScrollView.swift */; }; 02B2829227C4808D004A332A /* InfiniteScrollIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */; }; - 02B296A722FA6DB500FD7A4C /* Date+StartAndEnd.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B296A622FA6DB500FD7A4C /* Date+StartAndEnd.swift */; }; 02B296A922FA6E0000FD7A4C /* DateStartAndEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */; }; 02B2C831249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */; }; 02B653AC2429F7BF00A9C839 /* MockTaxClassStoresManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */; }; @@ -2232,7 +2231,6 @@ 02B2828D27C35061004A332A /* RefreshableInfiniteScrollList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableInfiniteScrollList.swift; sourceTree = ""; }; 02B2828F27C352DA004A332A /* RefreshableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableScrollView.swift; sourceTree = ""; }; 02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteScrollIndicator.swift; sourceTree = ""; }; - 02B296A622FA6DB500FD7A4C /* Date+StartAndEnd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+StartAndEnd.swift"; sourceTree = ""; }; 02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateStartAndEndTests.swift; sourceTree = ""; }; 02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTextAlignmentTests.swift; sourceTree = ""; }; 02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTaxClassStoresManager.swift; sourceTree = ""; }; @@ -7530,7 +7528,6 @@ D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */, 02820F3322C257B700DE0D37 /* UITableView+HeaderFooterHelpers.swift */, 456417F3247D5434001203F6 /* UITableView+Helpers.swift */, - 02B296A622FA6DB500FD7A4C /* Date+StartAndEnd.swift */, 02D45646231CB1FB008CF0A9 /* UIImage+Dot.swift */, 020DD48E232392C9005822B1 /* UIViewController+AppReview.swift */, 039D948C27610C6F0044EF38 /* UIView+SafeAreaConstraints.swift */, @@ -9964,7 +9961,6 @@ 3120491B26DD80E000A4EC4F /* ActivitySpinnerAndLabelTableViewCell.swift in Sources */, DEC51AFD276AEAE3009F3DF4 /* SystemStatusReportView.swift in Sources */, CECC759C23D61C1400486676 /* AggregateDataHelper.swift in Sources */, - 02B296A722FA6DB500FD7A4C /* Date+StartAndEnd.swift in Sources */, 02645D7D27BA027B0065DC68 /* Inbox.swift in Sources */, D81D9228222E7F0800FFA585 /* OrderStatusListViewController.swift in Sources */, CEE006082077D14C0079161F /* OrderDetailsViewController.swift in Sources */, diff --git a/WooFoundation/WooFoundation.xcodeproj/project.pbxproj b/WooFoundation/WooFoundation.xcodeproj/project.pbxproj index 35d33d228ae..33646c74ac5 100644 --- a/WooFoundation/WooFoundation.xcodeproj/project.pbxproj +++ b/WooFoundation/WooFoundation.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 689D11D32891B7D800F6A83F /* MockCrashLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 689D11D22891B7D800F6A83F /* MockCrashLogger.swift */; }; 68FBC5B328926B2C00A05461 /* Collection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68FBC5B228926B2C00A05461 /* Collection+Extensions.swift */; }; 9FA5113235035AC9A6079B0D /* Pods_WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1733C61561AE3A1AD3C16B7 /* Pods_WooFoundation.framework */; }; + AE948D0A28CF67CF009F3246 /* Date+StartAndEnd.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */; }; B987B06F284540D300C53CF6 /* CurrencyCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = B987B06E284540D300C53CF6 /* CurrencyCode.swift */; }; B9C9C63F283E703C001B879F /* WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9C9C635283E703C001B879F /* WooFoundation.framework */; }; B9C9C659283E7195001B879F /* NSDecimalNumber+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C9C658283E7195001B879F /* NSDecimalNumber+Helpers.swift */; }; @@ -62,6 +63,7 @@ 81B8569CD52D20EAE64EE737 /* Pods-WooFoundation.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooFoundation.release-alpha.xcconfig"; path = "Target Support Files/Pods-WooFoundation/Pods-WooFoundation.release-alpha.xcconfig"; sourceTree = ""; }; 99861FECBD0975C25DA03D80 /* Pods-WooFoundation.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooFoundation.debug.xcconfig"; path = "Target Support Files/Pods-WooFoundation/Pods-WooFoundation.debug.xcconfig"; sourceTree = ""; }; A21D73D352B4162AB096E276 /* Pods-WooFoundationTests.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooFoundationTests.release-alpha.xcconfig"; path = "Target Support Files/Pods-WooFoundationTests/Pods-WooFoundationTests.release-alpha.xcconfig"; sourceTree = ""; }; + AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+StartAndEnd.swift"; sourceTree = ""; }; B987B06E284540D300C53CF6 /* CurrencyCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyCode.swift; sourceTree = ""; }; B9AED558283E7553002A2668 /* Yosemite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Yosemite.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B9AED55B283E755A002A2668 /* Hardware.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Hardware.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -209,6 +211,7 @@ B9C9C657283E7174001B879F /* Extensions */ = { isa = PBXGroup; children = ( + AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */, B9C9C65F283E71F4001B879F /* Double+Woo.swift */, B9C9C658283E7195001B879F /* NSDecimalNumber+Helpers.swift */, 68FBC5B228926B2C00A05461 /* Collection+Extensions.swift */, @@ -442,6 +445,7 @@ B9C9C663283E7296001B879F /* Logging.swift in Sources */, 6874E81428998AD300074A97 /* LogErrorAndExit.swift in Sources */, B9C9C65D283E71C8001B879F /* CurrencyFormatter.swift in Sources */, + AE948D0A28CF67CF009F3246 /* Date+StartAndEnd.swift in Sources */, 26AF1F5628B8362800937BA9 /* UIColor+SystemColors.swift in Sources */, 689D11D32891B7D800F6A83F /* MockCrashLogger.swift in Sources */, B987B06F284540D300C53CF6 /* CurrencyCode.swift in Sources */, diff --git a/WooCommerce/Classes/Extensions/Date+StartAndEnd.swift b/WooFoundation/WooFoundation/Extensions/Date+StartAndEnd.swift similarity index 99% rename from WooCommerce/Classes/Extensions/Date+StartAndEnd.swift rename to WooFoundation/WooFoundation/Extensions/Date+StartAndEnd.swift index cd4c52cf489..569393c888e 100644 --- a/WooCommerce/Classes/Extensions/Date+StartAndEnd.swift +++ b/WooFoundation/WooFoundation/Extensions/Date+StartAndEnd.swift @@ -1,6 +1,6 @@ import Foundation -extension Date { +public extension Date { // MARK: Day /// Returns self's start of day in the given time zone. From fa15c6fa421e50bf1ff99b66d0cd1442a71e181d Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 12 Sep 2022 16:37:10 +0300 Subject: [PATCH 3/6] Move extension test --- WooCommerce/WooCommerce.xcodeproj/project.pbxproj | 4 ---- .../WooFoundation.xcodeproj/project.pbxproj | 12 ++++++++++++ .../Extensions/DateStartAndEndTests.swift | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) rename {WooCommerce/WooCommerceTests => WooFoundation/WooFoundationTests}/Extensions/DateStartAndEndTests.swift (99%) diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 396b4e83161..57b871cbdee 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -333,7 +333,6 @@ 02B2828E27C35061004A332A /* RefreshableInfiniteScrollList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828D27C35061004A332A /* RefreshableInfiniteScrollList.swift */; }; 02B2829027C352DA004A332A /* RefreshableScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828F27C352DA004A332A /* RefreshableScrollView.swift */; }; 02B2829227C4808D004A332A /* InfiniteScrollIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */; }; - 02B296A922FA6E0000FD7A4C /* DateStartAndEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */; }; 02B2C831249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */; }; 02B653AC2429F7BF00A9C839 /* MockTaxClassStoresManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */; }; 02B8650F24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B8650E24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift */; }; @@ -2231,7 +2230,6 @@ 02B2828D27C35061004A332A /* RefreshableInfiniteScrollList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableInfiniteScrollList.swift; sourceTree = ""; }; 02B2828F27C352DA004A332A /* RefreshableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableScrollView.swift; sourceTree = ""; }; 02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteScrollIndicator.swift; sourceTree = ""; }; - 02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateStartAndEndTests.swift; sourceTree = ""; }; 02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTextAlignmentTests.swift; sourceTree = ""; }; 02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTaxClassStoresManager.swift; sourceTree = ""; }; 02B8650E24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Product+SwiftUIPreviewHelpers.swift"; sourceTree = ""; }; @@ -6832,7 +6830,6 @@ B5980A6621AC91AA00EBF596 /* BundleWooTests.swift */, B57C5C9821B80E7100FF82B2 /* DataWooTests.swift */, 746FC23C2200A62B00C3096C /* DateWooTests.swift */, - 02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */, B57C5C9721B80E7100FF82B2 /* DictionaryWooTests.swift */, 748C7783211E2D8400814F2C /* DoubleWooTests.swift */, B5C6CE602190D28E00515926 /* NSAttributedStringHelperTests.swift */, @@ -10578,7 +10575,6 @@ 4572641B27F1FDF2004E1F95 /* AddEditCouponViewModelTests.swift in Sources */, AEE1D4FF25D1580E006A490B /* AttributeOptionListSelectorCommandTests.swift in Sources */, CC5BA5F5287EDC900072F307 /* OrderCustomFieldsViewModelTests.swift in Sources */, - 02B296A922FA6E0000FD7A4C /* DateStartAndEndTests.swift in Sources */, 02B653AC2429F7BF00A9C839 /* MockTaxClassStoresManager.swift in Sources */, 0277AEA5256CAA4200F45C4A /* MockShippingLabel.swift in Sources */, 02BAB02324D0250300F8B06E /* ProductVariation+ProductFormTests.swift in Sources */, diff --git a/WooFoundation/WooFoundation.xcodeproj/project.pbxproj b/WooFoundation/WooFoundation.xcodeproj/project.pbxproj index 33646c74ac5..245bf89a6fa 100644 --- a/WooFoundation/WooFoundation.xcodeproj/project.pbxproj +++ b/WooFoundation/WooFoundation.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 68FBC5B328926B2C00A05461 /* Collection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68FBC5B228926B2C00A05461 /* Collection+Extensions.swift */; }; 9FA5113235035AC9A6079B0D /* Pods_WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1733C61561AE3A1AD3C16B7 /* Pods_WooFoundation.framework */; }; AE948D0A28CF67CF009F3246 /* Date+StartAndEnd.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */; }; + AE948D0D28CF6D50009F3246 /* DateStartAndEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE948D0C28CF6D50009F3246 /* DateStartAndEndTests.swift */; }; B987B06F284540D300C53CF6 /* CurrencyCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = B987B06E284540D300C53CF6 /* CurrencyCode.swift */; }; B9C9C63F283E703C001B879F /* WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9C9C635283E703C001B879F /* WooFoundation.framework */; }; B9C9C659283E7195001B879F /* NSDecimalNumber+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C9C658283E7195001B879F /* NSDecimalNumber+Helpers.swift */; }; @@ -64,6 +65,7 @@ 99861FECBD0975C25DA03D80 /* Pods-WooFoundation.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooFoundation.debug.xcconfig"; path = "Target Support Files/Pods-WooFoundation/Pods-WooFoundation.debug.xcconfig"; sourceTree = ""; }; A21D73D352B4162AB096E276 /* Pods-WooFoundationTests.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooFoundationTests.release-alpha.xcconfig"; path = "Target Support Files/Pods-WooFoundationTests/Pods-WooFoundationTests.release-alpha.xcconfig"; sourceTree = ""; }; AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+StartAndEnd.swift"; sourceTree = ""; }; + AE948D0C28CF6D50009F3246 /* DateStartAndEndTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateStartAndEndTests.swift; sourceTree = ""; }; B987B06E284540D300C53CF6 /* CurrencyCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyCode.swift; sourceTree = ""; }; B9AED558283E7553002A2668 /* Yosemite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Yosemite.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B9AED55B283E755A002A2668 /* Hardware.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Hardware.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -165,6 +167,14 @@ path = Mocks; sourceTree = ""; }; + AE948D0B28CF6D34009F3246 /* Extensions */ = { + isa = PBXGroup; + children = ( + AE948D0C28CF6D50009F3246 /* DateStartAndEndTests.swift */, + ); + path = Extensions; + sourceTree = ""; + }; B9C9C5ED283E6FAA001B879F = { isa = PBXGroup; children = ( @@ -203,6 +213,7 @@ B9C9C642283E703C001B879F /* WooFoundationTests */ = { isa = PBXGroup; children = ( + AE948D0B28CF6D34009F3246 /* Extensions */, 686BE913288EE2BC00967C86 /* Utilities */, ); path = WooFoundationTests; @@ -466,6 +477,7 @@ files = ( 686BE915288EE2CA00967C86 /* TypedPredicateTests.swift in Sources */, 265C99DF28B94271005E6117 /* MurielColorTests.swift in Sources */, + AE948D0D28CF6D50009F3246 /* DateStartAndEndTests.swift in Sources */, 265C99DD28B941D5005E6117 /* UIColor+Muriel-Tests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/WooCommerce/WooCommerceTests/Extensions/DateStartAndEndTests.swift b/WooFoundation/WooFoundationTests/Extensions/DateStartAndEndTests.swift similarity index 99% rename from WooCommerce/WooCommerceTests/Extensions/DateStartAndEndTests.swift rename to WooFoundation/WooFoundationTests/Extensions/DateStartAndEndTests.swift index 8526ee38e2d..d649d050574 100644 --- a/WooCommerce/WooCommerceTests/Extensions/DateStartAndEndTests.swift +++ b/WooFoundation/WooFoundationTests/Extensions/DateStartAndEndTests.swift @@ -1,5 +1,5 @@ import XCTest -@testable import WooCommerce +@testable import WooFoundation final class DateStartAndEndTests: XCTestCase { private let gmtPlus8TimeZone: TimeZone = TimeZone(secondsFromGMT: 8 * 3600)! From 14219ce79f35b392e239b8d6b6d5dc2921ca1b45 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 12 Sep 2022 16:43:41 +0300 Subject: [PATCH 4/6] Use site TZ in StoreInfoDataService --- .../StoreWidgets/StoreInfoDataService.swift | 37 +++++-------------- .../StoreWidgets/StoreInfoProvider.swift | 2 +- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/WooCommerce/StoreWidgets/StoreInfoDataService.swift b/WooCommerce/StoreWidgets/StoreInfoDataService.swift index fe0a6e234df..8ccc3c855e8 100644 --- a/WooCommerce/StoreWidgets/StoreInfoDataService.swift +++ b/WooCommerce/StoreWidgets/StoreInfoDataService.swift @@ -25,10 +25,15 @@ final class StoreInfoDataService { /// private var network: AlamofireNetwork - init(authToken: String) { + /// Timezone of the website + /// + private let siteTimeZone: TimeZone + + init(authToken: String, siteTimeZone: TimeZone) { network = AlamofireNetwork(credentials: Credentials(authToken: authToken)) orderStatsRemoteV4 = OrderStatsRemoteV4(network: network) siteVisitStatsRemote = SiteVisitStatsRemote(network: network) + self.siteTimeZone = siteTimeZone } /// Async function that fetches todays stats data. @@ -55,7 +60,6 @@ final class StoreInfoDataService { private extension StoreInfoDataService { /// Async wrapper that fetches todays revenues & orders. - /// TODO: Update dates with the correct timezone. /// func fetchTodaysRevenueAndOrders(for storeID: Int64) async throws -> OrderStatsV4 { try await withCheckedThrowingContinuation { continuation in @@ -63,8 +67,8 @@ private extension StoreInfoDataService { Task { @MainActor in orderStatsRemoteV4.loadOrderStats(for: storeID, unit: .hourly, - earliestDateToInclude: Date.startOfToday, - latestDateToInclude: Date.endOfToday, + earliestDateToInclude: Date().startOfDay(timezone: siteTimeZone), + latestDateToInclude: Date().endOfDay(timezone: siteTimeZone), quantity: 24, forceRefresh: true) { result in continuation.resume(with: result) @@ -74,7 +78,6 @@ private extension StoreInfoDataService { } /// Async wrapper that fetches todays visitors. - /// TODO: Update dates with the correct timezone. /// func fetchTodaysVisitors(for storeID: Int64) async throws -> SiteVisitStats { try await withCheckedThrowingContinuation { continuation in @@ -82,7 +85,7 @@ private extension StoreInfoDataService { Task { @MainActor in siteVisitStatsRemote.loadSiteVisitorStats(for: storeID, unit: .day, - latestDateToInclude: Date.startOfToday, + latestDateToInclude: Date().endOfDay(timezone: siteTimeZone), quantity: 1) { result in continuation.resume(with: result) } @@ -90,25 +93,3 @@ private extension StoreInfoDataService { } } } - -// TEMP: Update dates with the correct timezones mimic the app behaviour -private extension Date { - - /// Temporary function to get the start of day in the device timezone. - /// - static var startOfToday: Date { - var calendar = Calendar(identifier: .gregorian) - calendar.timeZone = .current - return calendar.startOfDay(for: Date()) - } - - /// Temporary function to get the end of day in the device timezone. - /// - static var endOfToday: Date { - var calendar = Calendar(identifier: .gregorian) - calendar.timeZone = .current - let startDate = calendar.startOfDay(for: Date()) - let components = DateComponents(day: 1, second: -1) - return calendar.date(byAdding: components, to: startDate) ?? Date() - } -} diff --git a/WooCommerce/StoreWidgets/StoreInfoProvider.swift b/WooCommerce/StoreWidgets/StoreInfoProvider.swift index 1fef0377e2c..f6b9d6691df 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -68,7 +68,7 @@ final class StoreInfoProvider: TimelineProvider { return // TODO: Dispatch non auth error entry } - let strongService = StoreInfoDataService(authToken: dependencies.authToken) + let strongService = StoreInfoDataService(authToken: dependencies.authToken, siteTimeZone: dependencies.storeTimeZone) networkService = strongService Task { do { From 49687deddf8406edb415c9a4d4528a3e53730049 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Tue, 13 Sep 2022 14:26:26 +0300 Subject: [PATCH 5/6] 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 6/6] 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 {