-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widgets: Share store TZ settings #7707
Conversation
@@ -510,6 +510,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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This presentation is picked because we init it same way from API response:
woocommerce-ios/Networking/Networking/Model/Site.swift
Lines 168 to 173 in 29c95b9
/// Returns the TimeZone using the gmtOffset | |
/// | |
var siteTimezone: TimeZone { | |
let secondsFromGMT = Int(gmtOffset * 3600) | |
return TimeZone(secondsFromGMT: secondsFromGMT) ?? .current | |
} |
You can test the changes from this Pull Request by:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good!
Should we do the same?
I think we should match the way the app fetches & displays information. Because if not the merchant won't know what source of information to trust.
App | Widget |
---|---|
Since the stats charts are based on site time zone, we set the time zone for the stats UI to be the site time zone.
Wouldn't that means that we don't need the site timezone? As we don't show charts?
@@ -25,10 +25,15 @@ final class StoreInfoDataService { | |||
/// | |||
private var network: AlamofireNetwork | |||
|
|||
init(authToken: String) { | |||
/// Timezone of the website |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Timezone of the website | |
/// Timezone of the store |
That's what I think now. Should we close it and maybe get back if we found inconsistencies in testing? Update: Actually, I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// | ||
func fetchTodaysVisitors(for storeID: Int64) async throws -> SiteVisitStats { | ||
try await withCheckedThrowingContinuation { continuation in | ||
// `WKWebView` is accessed internally, we are foreced to dispatch the call in the main thread. | ||
Task { @MainActor in | ||
siteVisitStatsRemote.loadSiteVisitorStats(for: storeID, | ||
unit: .day, | ||
latestDateToInclude: Date.startOfToday, | ||
latestDateToInclude: Date().endOfDay(timezone: .current), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow I don't know why I used startOfToday
🤦
Closes: #7564
Description
To make sure we're using store TZ, share it as a parameter to widget extension and use in stats requests.
How
defaultStoreTimeZoneGMTOffset
userdefault propertyDate+StartAndEnd
extension to shared WooFoundation moduleNote: Testing this is complicated and sometimes I got different stats result in app dashboard and widget.
Stats dashboard uses store TZ for UI, but device TZ for requests:
woocommerce-ios/WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StoreStatsAndTopPerformersViewController.swift
Lines 206 to 210 in 29c95b9
Should we do the same?
Testing Steps
wp-admin
it's in Settings -> General -> Timezone.RELEASE-NOTES.txt
if necessary.