Skip to content

Commit 1cc10b6

Browse files
authored
Merge pull request #8303 from woocommerce/issue/8146-introduce-yesterday-range-option
Introduce `yesterday` range option
2 parents 7af938d + 734c3a7 commit 1cc10b6

File tree

9 files changed

+130
-26
lines changed

9 files changed

+130
-26
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/Time Range/AnalyticsHubTimeRangeSelection.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,23 @@ public class AnalyticsHubTimeRangeSelection {
3838

3939
switch selectionType {
4040
case .today:
41-
selectionData = AnalyticsHubDayRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
41+
selectionData = AnalyticsHubTodayRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
42+
case .yesterday:
43+
selectionData = AnalyticsHubYesterdayRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
4244
case .weekToDate:
43-
selectionData = AnalyticsHubWeekRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
45+
selectionData = AnalyticsHubWeekToDateRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
4446
case .monthToDate:
45-
selectionData = AnalyticsHubMonthRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
47+
selectionData = AnalyticsHubMonthToDateRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
4648
case .yearToDate:
47-
selectionData = AnalyticsHubYearRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
49+
selectionData = AnalyticsHubYearToDateRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
4850
}
4951

5052
let currentTimeRange = selectionData.currentTimeRange
5153
let previousTimeRange = selectionData.previousTimeRange
5254
self.currentTimeRange = currentTimeRange
5355
self.previousTimeRange = previousTimeRange
5456

55-
let simplifiedDescription = selectionType == .today
57+
let simplifiedDescription = selectionType == .today || selectionType == .yesterday
5658
self.formattedCurrentRangeText = currentTimeRange?.formatToString(simplified: simplifiedDescription,
5759
timezone: timezone,
5860
calendar: calendar)
@@ -86,6 +88,7 @@ public class AnalyticsHubTimeRangeSelection {
8688
extension AnalyticsHubTimeRangeSelection {
8789
enum SelectionType: CaseIterable {
8890
case today
91+
case yesterday
8992
case weekToDate
9093
case monthToDate
9194
case yearToDate
@@ -94,6 +97,8 @@ extension AnalyticsHubTimeRangeSelection {
9497
switch self {
9598
case .today:
9699
return Localization.today
100+
case .yesterday:
101+
return Localization.yesterday
97102
case .weekToDate:
98103
return Localization.weekToDate
99104
case .monthToDate:
@@ -126,6 +131,7 @@ extension AnalyticsHubTimeRangeSelection {
126131

127132
enum Localization {
128133
static let today = NSLocalizedString("Today", comment: "Title of the Analytics Hub Today's selection range")
134+
static let yesterday = NSLocalizedString("Yesterday", comment: "Title of the Analytics Hub Yesterday selection range")
129135
static let weekToDate = NSLocalizedString("Week to Date", comment: "Title of the Analytics Hub Week to Date selection range")
130136
static let monthToDate = NSLocalizedString("Month to Date", comment: "Title of the Analytics Hub Month to Date selection range")
131137
static let yearToDate = NSLocalizedString("Year to Date", comment: "Title of the Analytics Hub Year to Date selection range")
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import Foundation
22

3-
struct AnalyticsHubMonthRangeData: AnalyticsHubTimeRangeData {
3+
/// Responsible for defining two ranges of data, one starting from the first day of the current month
4+
/// until the current date and the previous one, starting from the first day of the previous month
5+
/// until the same day of the previous month. E. g.
6+
///
7+
/// Today: 31 Jul 2022
8+
/// Current range: Jul 1 until Jul 31, 2022
9+
/// Previous range: Jun 1 until Jun 30, 2022
10+
///
11+
struct AnalyticsHubMonthToDateRangeData: AnalyticsHubTimeRangeData {
412
let currentDateStart: Date?
513
let currentDateEnd: Date?
614
let previousDateStart: Date?
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import Foundation
22

3-
struct AnalyticsHubDayRangeData: AnalyticsHubTimeRangeData {
3+
/// Responsible for defining two ranges of data, one starting from the the first second of the current day
4+
/// until the same day in the current time and the previous one, starting from the first second of
5+
/// yesterday until the same time of that day. E. g.
6+
///
7+
/// Today: 29 Jul 2022
8+
/// Current range: Jul 29 until Jul 29, 2022
9+
/// Previous range: Jul 28 until Jul 28, 2022
10+
///
11+
struct AnalyticsHubTodayRangeData: AnalyticsHubTimeRangeData {
412
let currentDateStart: Date?
513
let currentDateEnd: Date?
614
let previousDateStart: Date?
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import Foundation
22

3-
struct AnalyticsHubWeekRangeData: AnalyticsHubTimeRangeData {
3+
/// Responsible for defining two ranges of data, one starting from the first day of the current week
4+
/// until the current date and the previous one, starting from the first day of the previous week
5+
/// until the same day of that week. E. g.
6+
///
7+
/// Today: 29 Jul 2022
8+
/// Current range: Jul 25 until Jul 29, 2022
9+
/// Previous range: Jul 18 until Jul 22, 2022
10+
///
11+
struct AnalyticsHubWeekToDateRangeData: AnalyticsHubTimeRangeData {
412
let currentDateStart: Date?
513
let currentDateEnd: Date?
614
let previousDateStart: Date?
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import Foundation
22

3-
struct AnalyticsHubYearRangeData: AnalyticsHubTimeRangeData {
3+
/// Responsible for defining two ranges of data, one starting from January 1st of the current year
4+
/// until the current date and the previous one, starting from January 1st of the last year
5+
/// until the same day on the in that year. E. g.
6+
///
7+
/// Today: 1 Jul 2022
8+
/// Current range: Jan 1 until Jul 1, 2022
9+
/// Previous range: Jan 1 until Jul 1, 2022
10+
///
11+
struct AnalyticsHubYearToDateRangeData: AnalyticsHubTimeRangeData {
412
let currentDateStart: Date?
513
let currentDateEnd: Date?
614
let previousDateStart: Date?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
3+
/// Responsible for defining two ranges of data, one starting from the the first second of yesterday
4+
/// until the last minute of the same day and the previous one, starting from the first second of
5+
/// the day before yesterday until the end of that day. E. g.
6+
///
7+
/// Today: 29 Jul 2022
8+
/// Current range: Jul 28 until Jul 28, 2022
9+
/// Previous range: Jul 27 until Jul 27, 2022
10+
///
11+
struct AnalyticsHubYesterdayRangeData: AnalyticsHubTimeRangeData {
12+
let currentDateStart: Date?
13+
let currentDateEnd: Date?
14+
let previousDateStart: Date?
15+
let previousDateEnd: Date?
16+
17+
init(referenceDate: Date, timezone: TimeZone, calendar: Calendar) {
18+
let yesterday = calendar.date(byAdding: .day, value: -1, to: referenceDate)
19+
self.currentDateEnd = yesterday?.endOfDay(timezone: timezone)
20+
self.currentDateStart = yesterday?.startOfDay(timezone: timezone)
21+
let previousDateEnd = calendar.date(byAdding: .day, value: -2, to: referenceDate)
22+
self.previousDateEnd = previousDateEnd?.endOfDay(timezone: timezone)
23+
self.previousDateStart = previousDateEnd?.startOfDay(timezone: timezone)
24+
}
25+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,14 +1363,15 @@
13631363
B687940C27699D420092BCA0 /* RefundFeesCalculationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = B687940B27699D410092BCA0 /* RefundFeesCalculationUseCase.swift */; };
13641364
B6A10E9C292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6A10E9B292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift */; };
13651365
B6C838DE28793B3A003AB786 /* OrderCustomFieldsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C838DD28793B3A003AB786 /* OrderCustomFieldsViewModel.swift */; };
1366+
B6E7DB64293A7C390049B001 /* AnalyticsHubYesterdayRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E7DB63293A7C390049B001 /* AnalyticsHubYesterdayRangeData.swift */; };
13661367
B6E851F3276320C70041D1BA /* RefundFeesDetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E851F2276320C70041D1BA /* RefundFeesDetailsViewModel.swift */; };
13671368
B6E851F5276330200041D1BA /* RefundFeesDetailsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E851F4276330200041D1BA /* RefundFeesDetailsTableViewCell.swift */; };
13681369
B6E851F7276331110041D1BA /* RefundFeesDetailsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B6E851F6276331110041D1BA /* RefundFeesDetailsTableViewCell.xib */; };
13691370
B6F379682937836700718561 /* AnalyticsHubTimeRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F379672937836700718561 /* AnalyticsHubTimeRange.swift */; };
1370-
B6F3796A29378B3900718561 /* AnalyticsHubMonthRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796929378B3900718561 /* AnalyticsHubMonthRangeData.swift */; };
1371-
B6F3796C293794A000718561 /* AnalyticsHubYearRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796B293794A000718561 /* AnalyticsHubYearRangeData.swift */; };
1372-
B6F3796E293796BC00718561 /* AnalyticsHubWeekRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796D293796BC00718561 /* AnalyticsHubWeekRangeData.swift */; };
1373-
B6F37970293798ED00718561 /* AnalyticsHubDayRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796F293798ED00718561 /* AnalyticsHubDayRangeData.swift */; };
1371+
B6F3796A29378B3900718561 /* AnalyticsHubMonthToDateRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796929378B3900718561 /* AnalyticsHubMonthToDateRangeData.swift */; };
1372+
B6F3796C293794A000718561 /* AnalyticsHubYearToDateRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796B293794A000718561 /* AnalyticsHubYearToDateRangeData.swift */; };
1373+
B6F3796E293796BC00718561 /* AnalyticsHubWeekToDateRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796D293796BC00718561 /* AnalyticsHubWeekToDateRangeData.swift */; };
1374+
B6F37970293798ED00718561 /* AnalyticsHubTodayRangeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F3796F293798ED00718561 /* AnalyticsHubTodayRangeData.swift */; };
13741375
B873E8F8E103966D2182EE67 /* Pods_WooCommerceTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DC4526F9A7357761197EBF0 /* Pods_WooCommerceTests.framework */; };
13751376
B910686027F1F28F00AD0575 /* GhostableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B910685F27F1F28F00AD0575 /* GhostableViewController.swift */; };
13761377
B9151B3F2840EB330036180F /* WooFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9151B3E2840EB330036180F /* WooFoundation.framework */; };
@@ -3378,14 +3379,15 @@
33783379
B687940B27699D410092BCA0 /* RefundFeesCalculationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundFeesCalculationUseCase.swift; sourceTree = "<group>"; };
33793380
B6A10E9B292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsTimeRangeCardViewModel.swift; sourceTree = "<group>"; };
33803381
B6C838DD28793B3A003AB786 /* OrderCustomFieldsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCustomFieldsViewModel.swift; sourceTree = "<group>"; };
3382+
B6E7DB63293A7C390049B001 /* AnalyticsHubYesterdayRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubYesterdayRangeData.swift; sourceTree = "<group>"; };
33813383
B6E851F2276320C70041D1BA /* RefundFeesDetailsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundFeesDetailsViewModel.swift; sourceTree = "<group>"; };
33823384
B6E851F4276330200041D1BA /* RefundFeesDetailsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundFeesDetailsTableViewCell.swift; sourceTree = "<group>"; };
33833385
B6E851F6276331110041D1BA /* RefundFeesDetailsTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RefundFeesDetailsTableViewCell.xib; sourceTree = "<group>"; };
33843386
B6F379672937836700718561 /* AnalyticsHubTimeRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubTimeRange.swift; sourceTree = "<group>"; };
3385-
B6F3796929378B3900718561 /* AnalyticsHubMonthRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubMonthRangeData.swift; sourceTree = "<group>"; };
3386-
B6F3796B293794A000718561 /* AnalyticsHubYearRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubYearRangeData.swift; sourceTree = "<group>"; };
3387-
B6F3796D293796BC00718561 /* AnalyticsHubWeekRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubWeekRangeData.swift; sourceTree = "<group>"; };
3388-
B6F3796F293798ED00718561 /* AnalyticsHubDayRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubDayRangeData.swift; sourceTree = "<group>"; };
3387+
B6F3796929378B3900718561 /* AnalyticsHubMonthToDateRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubMonthToDateRangeData.swift; sourceTree = "<group>"; };
3388+
B6F3796B293794A000718561 /* AnalyticsHubYearToDateRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubYearToDateRangeData.swift; sourceTree = "<group>"; };
3389+
B6F3796D293796BC00718561 /* AnalyticsHubWeekToDateRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubWeekToDateRangeData.swift; sourceTree = "<group>"; };
3390+
B6F3796F293798ED00718561 /* AnalyticsHubTodayRangeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsHubTodayRangeData.swift; sourceTree = "<group>"; };
33893391
B910685F27F1F28F00AD0575 /* GhostableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GhostableViewController.swift; sourceTree = "<group>"; };
33903392
B9151B3E2840EB330036180F /* WooFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = WooFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
33913393
B92FF9AD27FC7217005C34E3 /* OrderListViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OrderListViewController.xib; sourceTree = "<group>"; };
@@ -7472,18 +7474,19 @@
74727474
B66D6CEF293A4D990075D4AF /* Range Data Generation */ = {
74737475
isa = PBXGroup;
74747476
children = (
7475-
B6F3796929378B3900718561 /* AnalyticsHubMonthRangeData.swift */,
7476-
B6F3796B293794A000718561 /* AnalyticsHubYearRangeData.swift */,
7477-
B6F3796D293796BC00718561 /* AnalyticsHubWeekRangeData.swift */,
7478-
B6F3796F293798ED00718561 /* AnalyticsHubDayRangeData.swift */,
7479-
B66D6CEB29396A3E0075D4AF /* AnalyticsHubTimeRangeData.swift */,
7477+
B6F3796929378B3900718561 /* AnalyticsHubMonthToDateRangeData.swift */,
7478+
B6F3796B293794A000718561 /* AnalyticsHubYearToDateRangeData.swift */,
7479+
B6F3796D293796BC00718561 /* AnalyticsHubWeekToDateRangeData.swift */,
7480+
B6F3796F293798ED00718561 /* AnalyticsHubTodayRangeData.swift */,
7481+
B6E7DB63293A7C390049B001 /* AnalyticsHubYesterdayRangeData.swift */,
74807482
);
74817483
path = "Range Data Generation";
74827484
sourceTree = "<group>";
74837485
};
74847486
B6F379662937831D00718561 /* Time Range */ = {
74857487
isa = PBXGroup;
74867488
children = (
7489+
B66D6CEB29396A3E0075D4AF /* AnalyticsHubTimeRangeData.swift */,
74877490
B66D6CEF293A4D990075D4AF /* Range Data Generation */,
74887491
B6440FB5292E72DA0012D506 /* AnalyticsHubTimeRangeSelection.swift */,
74897492
B6F379672937836700718561 /* AnalyticsHubTimeRange.swift */,
@@ -9910,14 +9913,14 @@
99109913
02645D8827BA2E820065DC68 /* NSAttributedString+Attributes.swift in Sources */,
99119914
024DF3092372CA00006658FE /* EditorViewProperties.swift in Sources */,
99129915
45F8C43B2680BC3500F1A6EC /* ShippingLabelDiscountInfoViewController.swift in Sources */,
9913-
B6F3796E293796BC00718561 /* AnalyticsHubWeekRangeData.swift in Sources */,
9916+
B6F3796E293796BC00718561 /* AnalyticsHubWeekToDateRangeData.swift in Sources */,
99149917
DE77889A26FD7EF0008DFF44 /* ShippingLabelPackageItem.swift in Sources */,
99159918
CE85535D209B5BB700938BDC /* OrderDetailsViewModel.swift in Sources */,
99169919
31B05523264B3C8900134D87 /* CardPresentModalConnectingToReader.swift in Sources */,
99179920
025FA38B2522CB4D0054CA57 /* AppCoordinator.swift in Sources */,
99189921
02CEBB8024C9869E002EDF35 /* ProductFormActionsFactoryProtocol.swift in Sources */,
99199922
CE21B3E020FFC59700A259D5 /* ProductDetailsTableViewCell.swift in Sources */,
9920-
B6F3796A29378B3900718561 /* AnalyticsHubMonthRangeData.swift in Sources */,
9923+
B6F3796A29378B3900718561 /* AnalyticsHubMonthToDateRangeData.swift in Sources */,
99219924
B509FED121C041DF000076A9 /* Locale+Woo.swift in Sources */,
99229925
B5DB01B52114AB2D00A4F797 /* WooCrashLoggingStack.swift in Sources */,
99239926
26ED9660274328BC00FA00A1 /* SimplePaymentsSummaryViewModel.swift in Sources */,
@@ -10127,7 +10130,7 @@
1012710130
455DC3A327393C7E00D4644C /* OrderDatesFilterViewController.swift in Sources */,
1012810131
45B6F4EF27592A4000C18782 /* ReviewsView.swift in Sources */,
1012910132
268FD44727580A81008FDF9B /* LegacyCollectOrderPaymentUseCase.swift in Sources */,
10130-
B6F37970293798ED00718561 /* AnalyticsHubDayRangeData.swift in Sources */,
10133+
B6F37970293798ED00718561 /* AnalyticsHubTodayRangeData.swift in Sources */,
1013110134
269098B427D2BBFC001FEB07 /* ShippingInputTransformer.swift in Sources */,
1013210135
740987B321B87760000E4C80 /* FancyAnimatedButton+Woo.swift in Sources */,
1013310136
45F627B6253603AE00894B86 /* Product+DownloadSettingsViewModels.swift in Sources */,
@@ -10803,7 +10806,7 @@
1080310806
B910686027F1F28F00AD0575 /* GhostableViewController.swift in Sources */,
1080410807
AE8AEA8628084EC90054BDA2 /* MaxWidthPreference.swift in Sources */,
1080510808
DE19BB1A26C3B5DC00AB70D9 /* ShippingLabelCustomsFormItemDetailsViewModel.swift in Sources */,
10806-
B6F3796C293794A000718561 /* AnalyticsHubYearRangeData.swift in Sources */,
10809+
B6F3796C293794A000718561 /* AnalyticsHubYearToDateRangeData.swift in Sources */,
1080710810
2667BFE52530DCF4008099D4 /* RefundItemsValuesCalculationUseCase.swift in Sources */,
1080810811
AEE9A880293A3E5500227C92 /* RefreshablePlainList.swift in Sources */,
1080910812
B55BC1F121A878A30011A0C0 /* String+HTML.swift in Sources */,
@@ -10948,6 +10951,7 @@
1094810951
02DE5CA9279F857D007CBEF3 /* Double+Rounding.swift in Sources */,
1094910952
02A65301246AA63600755A01 /* ProductDetailsFactory.swift in Sources */,
1095010953
D449C51D26DE6B5000D75B02 /* LargeTitle.swift in Sources */,
10954+
B6E7DB64293A7C390049B001 /* AnalyticsHubYesterdayRangeData.swift in Sources */,
1095110955
456396B625C82691001F1A26 /* ShippingLabelFormStepTableViewCell.swift in Sources */,
1095210956
03FBDA9D263AD49200ACE257 /* CouponListViewController.swift in Sources */,
1095310957
023930612918F36400B2632F /* DomainSelectorView.swift in Sources */,

0 commit comments

Comments
 (0)