Skip to content

Commit 67b8432

Browse files
authored
Merge pull request #7707 from woocommerce/issue/7564-store-tz-settings
Widgets: Reuse Date extension
2 parents ab6274c + eedc08e commit 67b8432

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

WooCommerce/StoreWidgets/StoreInfoDataService.swift

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,15 @@ final class StoreInfoDataService {
5555
private extension StoreInfoDataService {
5656

5757
/// Async wrapper that fetches todays revenues & orders.
58-
/// TODO: Update dates with the correct timezone.
5958
///
6059
func fetchTodaysRevenueAndOrders(for storeID: Int64) async throws -> OrderStatsV4 {
6160
try await withCheckedThrowingContinuation { continuation in
62-
// `WKWebView` is accessed internally, we are foreced to dispatch the call in the main thread.
61+
// `WKWebView` is accessed internally, we are forced to dispatch the call in the main thread.
6362
Task { @MainActor in
6463
orderStatsRemoteV4.loadOrderStats(for: storeID,
6564
unit: .hourly,
66-
earliestDateToInclude: Date.startOfToday,
67-
latestDateToInclude: Date.endOfToday,
65+
earliestDateToInclude: Date().startOfDay(timezone: .current),
66+
latestDateToInclude: Date().endOfDay(timezone: .current),
6867
quantity: 24,
6968
forceRefresh: true) { result in
7069
continuation.resume(with: result)
@@ -74,41 +73,18 @@ private extension StoreInfoDataService {
7473
}
7574

7675
/// Async wrapper that fetches todays visitors.
77-
/// TODO: Update dates with the correct timezone.
7876
///
7977
func fetchTodaysVisitors(for storeID: Int64) async throws -> SiteVisitStats {
8078
try await withCheckedThrowingContinuation { continuation in
8179
// `WKWebView` is accessed internally, we are foreced to dispatch the call in the main thread.
8280
Task { @MainActor in
8381
siteVisitStatsRemote.loadSiteVisitorStats(for: storeID,
8482
unit: .day,
85-
latestDateToInclude: Date.startOfToday,
83+
latestDateToInclude: Date().endOfDay(timezone: .current),
8684
quantity: 1) { result in
8785
continuation.resume(with: result)
8886
}
8987
}
9088
}
9189
}
9290
}
93-
94-
// TEMP: Update dates with the correct timezones mimic the app behaviour
95-
private extension Date {
96-
97-
/// Temporary function to get the start of day in the device timezone.
98-
///
99-
static var startOfToday: Date {
100-
var calendar = Calendar(identifier: .gregorian)
101-
calendar.timeZone = .current
102-
return calendar.startOfDay(for: Date())
103-
}
104-
105-
/// Temporary function to get the end of day in the device timezone.
106-
///
107-
static var endOfToday: Date {
108-
var calendar = Calendar(identifier: .gregorian)
109-
calendar.timeZone = .current
110-
let startDate = calendar.startOfDay(for: Date())
111-
let components = DateComponents(day: 1, second: -1)
112-
return calendar.date(byAdding: components, to: startDate) ?? Date()
113-
}
114-
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@
333333
02B2828E27C35061004A332A /* RefreshableInfiniteScrollList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828D27C35061004A332A /* RefreshableInfiniteScrollList.swift */; };
334334
02B2829027C352DA004A332A /* RefreshableScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2828F27C352DA004A332A /* RefreshableScrollView.swift */; };
335335
02B2829227C4808D004A332A /* InfiniteScrollIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */; };
336-
02B296A722FA6DB500FD7A4C /* Date+StartAndEnd.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B296A622FA6DB500FD7A4C /* Date+StartAndEnd.swift */; };
337-
02B296A922FA6E0000FD7A4C /* DateStartAndEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */; };
338336
02B2C831249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */; };
339337
02B653AC2429F7BF00A9C839 /* MockTaxClassStoresManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */; };
340338
02B8650F24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B8650E24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift */; };
@@ -2240,8 +2238,6 @@
22402238
02B2828D27C35061004A332A /* RefreshableInfiniteScrollList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableInfiniteScrollList.swift; sourceTree = "<group>"; };
22412239
02B2828F27C352DA004A332A /* RefreshableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshableScrollView.swift; sourceTree = "<group>"; };
22422240
02B2829127C4808D004A332A /* InfiniteScrollIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteScrollIndicator.swift; sourceTree = "<group>"; };
2243-
02B296A622FA6DB500FD7A4C /* Date+StartAndEnd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+StartAndEnd.swift"; sourceTree = "<group>"; };
2244-
02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateStartAndEndTests.swift; sourceTree = "<group>"; };
22452241
02B2C830249C4C8D0040C83C /* TextFieldTextAlignmentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTextAlignmentTests.swift; sourceTree = "<group>"; };
22462242
02B653AB2429F7BF00A9C839 /* MockTaxClassStoresManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTaxClassStoresManager.swift; sourceTree = "<group>"; };
22472243
02B8650E24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Product+SwiftUIPreviewHelpers.swift"; sourceTree = "<group>"; };
@@ -6852,7 +6848,6 @@
68526848
B5980A6621AC91AA00EBF596 /* BundleWooTests.swift */,
68536849
B57C5C9821B80E7100FF82B2 /* DataWooTests.swift */,
68546850
746FC23C2200A62B00C3096C /* DateWooTests.swift */,
6855-
02B296A822FA6E0000FD7A4C /* DateStartAndEndTests.swift */,
68566851
B57C5C9721B80E7100FF82B2 /* DictionaryWooTests.swift */,
68576852
748C7783211E2D8400814F2C /* DoubleWooTests.swift */,
68586853
B5C6CE602190D28E00515926 /* NSAttributedStringHelperTests.swift */,
@@ -7550,7 +7545,6 @@
75507545
D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */,
75517546
02820F3322C257B700DE0D37 /* UITableView+HeaderFooterHelpers.swift */,
75527547
456417F3247D5434001203F6 /* UITableView+Helpers.swift */,
7553-
02B296A622FA6DB500FD7A4C /* Date+StartAndEnd.swift */,
75547548
02D45646231CB1FB008CF0A9 /* UIImage+Dot.swift */,
75557549
020DD48E232392C9005822B1 /* UIViewController+AppReview.swift */,
75567550
039D948C27610C6F0044EF38 /* UIView+SafeAreaConstraints.swift */,
@@ -10011,7 +10005,6 @@
1001110005
3120491B26DD80E000A4EC4F /* ActivitySpinnerAndLabelTableViewCell.swift in Sources */,
1001210006
DEC51AFD276AEAE3009F3DF4 /* SystemStatusReportView.swift in Sources */,
1001310007
CECC759C23D61C1400486676 /* AggregateDataHelper.swift in Sources */,
10014-
02B296A722FA6DB500FD7A4C /* Date+StartAndEnd.swift in Sources */,
1001510008
02645D7D27BA027B0065DC68 /* Inbox.swift in Sources */,
1001610009
D81D9228222E7F0800FFA585 /* OrderStatusListViewController.swift in Sources */,
1001710010
CEE006082077D14C0079161F /* OrderDetailsViewController.swift in Sources */,
@@ -10631,7 +10624,6 @@
1063110624
4572641B27F1FDF2004E1F95 /* AddEditCouponViewModelTests.swift in Sources */,
1063210625
AEE1D4FF25D1580E006A490B /* AttributeOptionListSelectorCommandTests.swift in Sources */,
1063310626
CC5BA5F5287EDC900072F307 /* OrderCustomFieldsViewModelTests.swift in Sources */,
10634-
02B296A922FA6E0000FD7A4C /* DateStartAndEndTests.swift in Sources */,
1063510627
02B653AC2429F7BF00A9C839 /* MockTaxClassStoresManager.swift in Sources */,
1063610628
0277AEA5256CAA4200F45C4A /* MockShippingLabel.swift in Sources */,
1063710629
02BAB02324D0250300F8B06E /* ProductVariation+ProductFormTests.swift in Sources */,

WooFoundation/WooFoundation.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
689D11D32891B7D800F6A83F /* MockCrashLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 689D11D22891B7D800F6A83F /* MockCrashLogger.swift */; };
2424
68FBC5B328926B2C00A05461 /* Collection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68FBC5B228926B2C00A05461 /* Collection+Extensions.swift */; };
2525
9FA5113235035AC9A6079B0D /* Pods_WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1733C61561AE3A1AD3C16B7 /* Pods_WooFoundation.framework */; };
26+
AE948D0A28CF67CF009F3246 /* Date+StartAndEnd.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */; };
27+
AE948D0D28CF6D50009F3246 /* DateStartAndEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE948D0C28CF6D50009F3246 /* DateStartAndEndTests.swift */; };
2628
B987B06F284540D300C53CF6 /* CurrencyCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = B987B06E284540D300C53CF6 /* CurrencyCode.swift */; };
2729
B9C9C63F283E703C001B879F /* WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9C9C635283E703C001B879F /* WooFoundation.framework */; };
2830
B9C9C659283E7195001B879F /* NSDecimalNumber+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9C9C658283E7195001B879F /* NSDecimalNumber+Helpers.swift */; };
@@ -62,6 +64,8 @@
6264
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 = "<group>"; };
6365
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 = "<group>"; };
6466
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 = "<group>"; };
67+
AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+StartAndEnd.swift"; sourceTree = "<group>"; };
68+
AE948D0C28CF6D50009F3246 /* DateStartAndEndTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateStartAndEndTests.swift; sourceTree = "<group>"; };
6569
B987B06E284540D300C53CF6 /* CurrencyCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyCode.swift; sourceTree = "<group>"; };
6670
B9AED558283E7553002A2668 /* Yosemite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Yosemite.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6771
B9AED55B283E755A002A2668 /* Hardware.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Hardware.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -163,6 +167,14 @@
163167
path = Mocks;
164168
sourceTree = "<group>";
165169
};
170+
AE948D0B28CF6D34009F3246 /* Extensions */ = {
171+
isa = PBXGroup;
172+
children = (
173+
AE948D0C28CF6D50009F3246 /* DateStartAndEndTests.swift */,
174+
);
175+
path = Extensions;
176+
sourceTree = "<group>";
177+
};
166178
B9C9C5ED283E6FAA001B879F = {
167179
isa = PBXGroup;
168180
children = (
@@ -201,6 +213,7 @@
201213
B9C9C642283E703C001B879F /* WooFoundationTests */ = {
202214
isa = PBXGroup;
203215
children = (
216+
AE948D0B28CF6D34009F3246 /* Extensions */,
204217
686BE913288EE2BC00967C86 /* Utilities */,
205218
);
206219
path = WooFoundationTests;
@@ -209,6 +222,7 @@
209222
B9C9C657283E7174001B879F /* Extensions */ = {
210223
isa = PBXGroup;
211224
children = (
225+
AE948D0928CF67CE009F3246 /* Date+StartAndEnd.swift */,
212226
B9C9C65F283E71F4001B879F /* Double+Woo.swift */,
213227
B9C9C658283E7195001B879F /* NSDecimalNumber+Helpers.swift */,
214228
68FBC5B228926B2C00A05461 /* Collection+Extensions.swift */,
@@ -442,6 +456,7 @@
442456
B9C9C663283E7296001B879F /* Logging.swift in Sources */,
443457
6874E81428998AD300074A97 /* LogErrorAndExit.swift in Sources */,
444458
B9C9C65D283E71C8001B879F /* CurrencyFormatter.swift in Sources */,
459+
AE948D0A28CF67CF009F3246 /* Date+StartAndEnd.swift in Sources */,
445460
26AF1F5628B8362800937BA9 /* UIColor+SystemColors.swift in Sources */,
446461
689D11D32891B7D800F6A83F /* MockCrashLogger.swift in Sources */,
447462
B987B06F284540D300C53CF6 /* CurrencyCode.swift in Sources */,
@@ -462,6 +477,7 @@
462477
files = (
463478
686BE915288EE2CA00967C86 /* TypedPredicateTests.swift in Sources */,
464479
265C99DF28B94271005E6117 /* MurielColorTests.swift in Sources */,
480+
AE948D0D28CF6D50009F3246 /* DateStartAndEndTests.swift in Sources */,
465481
265C99DD28B941D5005E6117 /* UIColor+Muriel-Tests.swift in Sources */,
466482
);
467483
runOnlyForDeploymentPostprocessing = 0;

WooCommerce/Classes/Extensions/Date+StartAndEnd.swift renamed to WooFoundation/WooFoundation/Extensions/Date+StartAndEnd.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
extension Date {
3+
public extension Date {
44
// MARK: Day
55

66
/// Returns self's start of day in the given time zone.

WooCommerce/WooCommerceTests/Extensions/DateStartAndEndTests.swift renamed to WooFoundation/WooFoundationTests/Extensions/DateStartAndEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import XCTest
2-
@testable import WooCommerce
2+
@testable import WooFoundation
33

44
final class DateStartAndEndTests: XCTestCase {
55
private let gmtPlus8TimeZone: TimeZone = TimeZone(secondsFromGMT: 8 * 3600)!

0 commit comments

Comments
 (0)