Skip to content

Commit

Permalink
Merge timezon branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ecarrion committed Sep 13, 2022
2 parents 72e118c + eedc08e commit 22e4fe2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion WooCommerce/Classes/Extensions/UserDefaults+Woo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extension UserDefaults {
case defaultSiteAddress
case defaultStoreID
case defaultStoreName
case defaultStoreTimeZoneGMTOffset
case defaultStoreCurrencySettings
case defaultAnonymousID
case defaultRoles
Expand Down
1 change: 0 additions & 1 deletion WooCommerce/Classes/Yosemite/DefaultStoresManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 5 additions & 10 deletions WooCommerce/StoreWidgets/StoreInfoDataService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
6 changes: 1 addition & 5 deletions WooCommerce/StoreWidgets/StoreInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class StoreInfoProvider: TimelineProvider {
return completion(Timeline<StoreInfoEntry>(entries: [StoreInfoEntry.notConnected], policy: .never))
}

let strongService = StoreInfoDataService(authToken: dependencies.authToken, siteTimeZone: dependencies.storeTimeZone)
let strongService = StoreInfoDataService(authToken: dependencies.authToken)
networkService = strongService
Task {
do {
Expand Down Expand Up @@ -121,7 +121,6 @@ private extension StoreInfoProvider {
let authToken: String
let storeID: Int64
let storeName: String
let storeTimeZone: TimeZone
let storeCurrencySettings: CurrencySettings
}

Expand All @@ -132,16 +131,13 @@ private extension StoreInfoProvider {
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),
let storeCurrencySettingsData = UserDefaults.group?[.defaultStoreCurrencySettings] as? Data,
let storeCurrencySettings = try? JSONDecoder().decode(CurrencySettings.self, from: storeCurrencySettingsData) else {
return nil
}
return Dependencies(authToken: authToken,
storeID: storeID,
storeName: storeName,
storeTimeZone: storeTimeZone,
storeCurrencySettings: storeCurrencySettings)
}
}
Expand Down

0 comments on commit 22e4fe2

Please sign in to comment.