Skip to content

Commit 169d4e3

Browse files
committed
Adjust StatsTimeRangeV4 availability
1 parent ed00130 commit 169d4e3

File tree

5 files changed

+69
-58
lines changed

5 files changed

+69
-58
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Yosemite
2+
3+
extension StatsTimeRangeV4 {
4+
/// The maximum number of stats intervals a time range could have.
5+
var maxNumberOfIntervals: Int {
6+
switch self {
7+
case .today:
8+
return 24
9+
case .thisWeek:
10+
return 7
11+
case .thisMonth:
12+
return 31
13+
case .thisYear:
14+
return 12
15+
}
16+
}
17+
18+
/// Returns the latest date to be shown for the time range, given the current date and site time zone
19+
///
20+
/// - Parameters:
21+
/// - currentDate: the date which the latest date is based on
22+
/// - siteTimezone: site time zone, which the stats data are based on
23+
func latestDate(currentDate: Date, siteTimezone: TimeZone) -> Date {
24+
switch self {
25+
case .today:
26+
return currentDate.endOfDay(timezone: siteTimezone)
27+
case .thisWeek:
28+
return currentDate.endOfWeek(timezone: siteTimezone)
29+
case .thisMonth:
30+
return currentDate.endOfMonth(timezone: siteTimezone)
31+
case .thisYear:
32+
return currentDate.endOfYear(timezone: siteTimezone)
33+
}
34+
}
35+
36+
/// Returns the earliest date to be shown for the time range, given the latest date and site time zone
37+
///
38+
/// - Parameters:
39+
/// - latestDate: the date which the earliest date is based on
40+
/// - siteTimezone: site time zone, which the stats data are based on
41+
func earliestDate(latestDate: Date, siteTimezone: TimeZone) -> Date {
42+
switch self {
43+
case .today:
44+
return latestDate.startOfDay(timezone: siteTimezone)
45+
case .thisWeek:
46+
return latestDate.startOfWeek(timezone: siteTimezone)
47+
case .thisMonth:
48+
return latestDate.startOfMonth(timezone: siteTimezone)
49+
case .thisYear:
50+
return latestDate.startOfYear(timezone: siteTimezone)
51+
}
52+
}
53+
}

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StatsTimeRangeV4+UI.swift

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import Yosemite
22

33
extension StatsTimeRangeV4 {
4-
/// The maximum number of stats intervals a time range could have.
5-
var maxNumberOfIntervals: Int {
6-
switch self {
7-
case .today:
8-
return 24
9-
case .thisWeek:
10-
return 7
11-
case .thisMonth:
12-
return 31
13-
case .thisYear:
14-
return 12
15-
}
16-
}
174

185
/// The title of a time range tab.
196
var tabTitle: String {
@@ -29,42 +16,6 @@ extension StatsTimeRangeV4 {
2916
}
3017
}
3118

32-
/// Returns the latest date to be shown for the time range, given the current date and site time zone
33-
///
34-
/// - Parameters:
35-
/// - currentDate: the date which the latest date is based on
36-
/// - siteTimezone: site time zone, which the stats data are based on
37-
func latestDate(currentDate: Date, siteTimezone: TimeZone) -> Date {
38-
switch self {
39-
case .today:
40-
return currentDate.endOfDay(timezone: siteTimezone)
41-
case .thisWeek:
42-
return currentDate.endOfWeek(timezone: siteTimezone)
43-
case .thisMonth:
44-
return currentDate.endOfMonth(timezone: siteTimezone)
45-
case .thisYear:
46-
return currentDate.endOfYear(timezone: siteTimezone)
47-
}
48-
}
49-
50-
/// Returns the earliest date to be shown for the time range, given the latest date and site time zone
51-
///
52-
/// - Parameters:
53-
/// - latestDate: the date which the earliest date is based on
54-
/// - siteTimezone: site time zone, which the stats data are based on
55-
func earliestDate(latestDate: Date, siteTimezone: TimeZone) -> Date {
56-
switch self {
57-
case .today:
58-
return latestDate.startOfDay(timezone: siteTimezone)
59-
case .thisWeek:
60-
return latestDate.startOfWeek(timezone: siteTimezone)
61-
case .thisMonth:
62-
return latestDate.startOfMonth(timezone: siteTimezone)
63-
case .thisYear:
64-
return latestDate.startOfYear(timezone: siteTimezone)
65-
}
66-
}
67-
6819
/// Returns a date formatter for the x-axis labels of a stats chart
6920
///
7021
/// - Parameter siteTimezone: site time zone, which the stats data are based on

WooCommerce/StoreWidgets/StoreInfoDataService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Networking
2+
import enum Yosemite.StatsTimeRangeV4
23

34
/// Orchestrator class that fetches today store stats data.
45
///

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
028AFFB32484ED2800693C09 /* Dictionary+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028AFFB22484ED2800693C09 /* Dictionary+Logging.swift */; };
279279
028AFFB62484EDA000693C09 /* Dictionary+LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028AFFB52484EDA000693C09 /* Dictionary+LoggingTests.swift */; };
280280
028BAC3D22F2DECE008BB4AF /* StoreStatsAndTopPerformersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028BAC3C22F2DECE008BB4AF /* StoreStatsAndTopPerformersViewController.swift */; };
281-
028BAC4722F3B550008BB4AF /* StatsTimeRangeV4+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+UI.swift */; };
281+
028BAC4722F3B550008BB4AF /* StatsTimeRangeV4+Parameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+Parameters.swift */; };
282282
028E19BA28053443001C36E0 /* MockOrderDetailsPaymentAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028E19B928053443001C36E0 /* MockOrderDetailsPaymentAlerts.swift */; };
283283
028E19BC2805BD22001C36E0 /* RefundSubmissionUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028E19BB2805BD22001C36E0 /* RefundSubmissionUseCaseTests.swift */; };
284284
028E1F702833DD0A001F8829 /* DashboardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028E1F6F2833DD0A001F8829 /* DashboardViewModel.swift */; };
@@ -1126,6 +1126,8 @@
11261126
ABC3521A374A2355001E3CD6 /* CardReaderSettingsSearchingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC353433EABC5F0EC796222 /* CardReaderSettingsSearchingViewController.swift */; };
11271127
ABC35528D2D6BE6F516E5CEF /* InPersonPaymentsOnboardingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC35A4B736A0B2D8348DD08 /* InPersonPaymentsOnboardingError.swift */; };
11281128
ABC35F18E744C5576B986CB3 /* InPersonPaymentsUnavailableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC35055F8AC8C8EB649F421 /* InPersonPaymentsUnavailableView.swift */; };
1129+
AE30F5D828FDDFAC00875181 /* StatsTimeRangeV4+Parameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+Parameters.swift */; };
1130+
AE30F5DA28FDE02F00875181 /* StatsTimeRangeV4+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE30F5D928FDE02F00875181 /* StatsTimeRangeV4+UI.swift */; };
11291131
AE457813275644590092F687 /* OrderStatusSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE457812275644590092F687 /* OrderStatusSection.swift */; };
11301132
AE56E73428E76CDB00A1292B /* StoreInfoInlineWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE56E73328E76CDB00A1292B /* StoreInfoInlineWidget.swift */; };
11311133
AE56E73628E7787700A1292B /* StoreInfoCircularWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE56E73528E7787700A1292B /* StoreInfoCircularWidget.swift */; };
@@ -2194,7 +2196,7 @@
21942196
028AFFB22484ED2800693C09 /* Dictionary+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+Logging.swift"; sourceTree = "<group>"; };
21952197
028AFFB52484EDA000693C09 /* Dictionary+LoggingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+LoggingTests.swift"; sourceTree = "<group>"; };
21962198
028BAC3C22F2DECE008BB4AF /* StoreStatsAndTopPerformersViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreStatsAndTopPerformersViewController.swift; sourceTree = "<group>"; };
2197-
028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatsTimeRangeV4+UI.swift"; sourceTree = "<group>"; };
2199+
028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+Parameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatsTimeRangeV4+Parameters.swift"; sourceTree = "<group>"; };
21982200
028E19B928053443001C36E0 /* MockOrderDetailsPaymentAlerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockOrderDetailsPaymentAlerts.swift; sourceTree = "<group>"; };
21992201
028E19BB2805BD22001C36E0 /* RefundSubmissionUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundSubmissionUseCaseTests.swift; sourceTree = "<group>"; };
22002202
028E1F6F2833DD0A001F8829 /* DashboardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardViewModel.swift; sourceTree = "<group>"; };
@@ -3024,6 +3026,7 @@
30243026
ABC35055F8AC8C8EB649F421 /* InPersonPaymentsUnavailableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsUnavailableView.swift; sourceTree = "<group>"; };
30253027
ABC353433EABC5F0EC796222 /* CardReaderSettingsSearchingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardReaderSettingsSearchingViewController.swift; sourceTree = "<group>"; };
30263028
ABC35A4B736A0B2D8348DD08 /* InPersonPaymentsOnboardingError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsOnboardingError.swift; sourceTree = "<group>"; };
3029+
AE30F5D928FDE02F00875181 /* StatsTimeRangeV4+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatsTimeRangeV4+UI.swift"; sourceTree = "<group>"; };
30273030
AE457812275644590092F687 /* OrderStatusSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderStatusSection.swift; sourceTree = "<group>"; };
30283031
AE56E73328E76CDB00A1292B /* StoreInfoInlineWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreInfoInlineWidget.swift; sourceTree = "<group>"; };
30293032
AE56E73528E7787700A1292B /* StoreInfoCircularWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreInfoCircularWidget.swift; sourceTree = "<group>"; };
@@ -4543,7 +4546,8 @@
45434546
021739992772F9DC0084CD89 /* StoreStatsV4PeriodViewController.xib */,
45444547
02312796277D4F640060E180 /* StoreStatsPeriodViewModel.swift */,
45454548
0217399F2773F5F50084CD89 /* StoreStatsChartCircleMarker.swift */,
4546-
028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+UI.swift */,
4549+
028BAC4622F3B550008BB4AF /* StatsTimeRangeV4+Parameters.swift */,
4550+
AE30F5D928FDE02F00875181 /* StatsTimeRangeV4+UI.swift */,
45474551
0285BF6F22FBD91C003A2525 /* TopPerformersSectionHeaderView.swift */,
45484552
02E4FD79230688BA0049610C /* OrderStatsV4Interval+Chart.swift */,
45494553
02E4FD7B2306A04C0049610C /* StatsTimeRangeBarView.swift */,
@@ -9394,6 +9398,7 @@
93949398
files = (
93959399
AED9012D28E5F517002B4572 /* AppLinkWidget.swift in Sources */,
93969400
2608C50728C941D600C9DFC0 /* UserDefaults+Woo.swift in Sources */,
9401+
AE30F5D828FDDFAC00875181 /* StatsTimeRangeV4+Parameters.swift in Sources */,
93979402
265C99E628B9CB8E005E6117 /* StoreInfoViewModifiers.swift in Sources */,
93989403
2608C50628C93AB700C9DFC0 /* WooConstants.swift in Sources */,
93999404
260DE20A28CA7CFE009ECD7C /* StoreInfoDataService.swift in Sources */,
@@ -9649,7 +9654,7 @@
96499654
7E7C5F832719A93C00315B61 /* ProductCategoryListViewModel.swift in Sources */,
96509655
CC666F2427F329DC0045AF1E /* View+DiscardChanges.swift in Sources */,
96519656
0282DD94233C9465006A5FDB /* SearchUICommand.swift in Sources */,
9652-
028BAC4722F3B550008BB4AF /* StatsTimeRangeV4+UI.swift in Sources */,
9657+
028BAC4722F3B550008BB4AF /* StatsTimeRangeV4+Parameters.swift in Sources */,
96539658
024DF32123744798006658FE /* AztecFormatBarCommandCoordinator.swift in Sources */,
96549659
B5AA7B3F20ED81C2004DA14F /* UserDefaults+Woo.swift in Sources */,
96559660
318477E527A33C650058C7E9 /* CardPresentModalConnectingFailedChargeReader.swift in Sources */,
@@ -9909,6 +9914,7 @@
99099914
45FDDD65267784AD00ADACE8 /* ShippingLabelSummaryTableViewCell.swift in Sources */,
99109915
45DB70662614CE3F0064A6CF /* Decimal+Helpers.swift in Sources */,
99119916
0379C51727BFCE9800A7E284 /* WCPayCardBrand+icons.swift in Sources */,
9917+
AE30F5DA28FDE02F00875181 /* StatsTimeRangeV4+UI.swift in Sources */,
99129918
B958A7C728B3D44A00823EEF /* UniversalLinkRouter.swift in Sources */,
99139919
02E8B17C23E2C78A00A43403 /* ProductImageStatus.swift in Sources */,
99149920
0259D5FF2581F3FA003B1CD6 /* ShippingLabelPaperSizeOptionsViewController.swift in Sources */,

Yosemite/Yosemite/Model/Enums/StatsTimeRangeV4.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public enum StatsTimeRangeV4: String {
1212
case thisYear
1313
}
1414

15-
extension StatsTimeRangeV4 {
15+
public extension StatsTimeRangeV4 {
1616
/// Represents the period unit of the store stats using Stats v4 API given a time range.
17-
public var intervalGranularity: StatsGranularityV4 {
17+
var intervalGranularity: StatsGranularityV4 {
1818
switch self {
1919
case .today:
2020
return .hourly
@@ -28,7 +28,7 @@ extension StatsTimeRangeV4 {
2828
}
2929

3030
/// Represents the period unit of the site visit stats given a time range.
31-
public var siteVisitStatsGranularity: StatGranularity {
31+
var siteVisitStatsGranularity: StatGranularity {
3232
switch self {
3333
case .today, .thisWeek, .thisMonth:
3434
return .day
@@ -38,7 +38,7 @@ extension StatsTimeRangeV4 {
3838
}
3939

4040
/// Represents the period unit of the top earners stats given a time range.
41-
public var topEarnerStatsGranularity: StatGranularity {
41+
var topEarnerStatsGranularity: StatGranularity {
4242
switch self {
4343
case .today:
4444
return .day
@@ -52,7 +52,7 @@ extension StatsTimeRangeV4 {
5252
}
5353

5454
/// Represents the period unit of the leaderboards v4 API given a time range.
55-
public var leaderboardsGranularity: StatsGranularityV4 {
55+
var leaderboardsGranularity: StatsGranularityV4 {
5656
switch self {
5757
case .today:
5858
return .daily

0 commit comments

Comments
 (0)