@@ -77,27 +77,9 @@ public class AnalyticsHubTimeRangeSelection {
7777
7878// MARK: - Time Range Selection Type
7979extension AnalyticsHubTimeRangeSelection {
80- enum SelectionType : CaseIterable , Equatable , Hashable {
81- /// Wee need to provide a custom `allCases` because the `.custom(Date?, Date?)`case disables its synthetization.
82- ///
83- static var allCases : [ AnalyticsHubTimeRangeSelection . SelectionType ] {
84- [
85- ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . analyticsHub) ? . custom( start: nil , end: nil ) : nil ,
86- . today,
87- . yesterday,
88- . lastWeek,
89- . lastMonth,
90- . lastQuarter,
91- . lastYear,
92- . weekToDate,
93- . monthToDate,
94- . quarterToDate,
95- yearToDate
96- ] . compactMap { $0 }
97- }
80+ enum SelectionType : Equatable {
9881
99- // When adding a new case, remember to add it to `allCases`.
100- case custom( start: Date ? , end: Date ? )
82+ case custom( start: Date , end: Date )
10183 case today
10284 case yesterday
10385 case lastWeek
@@ -109,33 +91,6 @@ extension AnalyticsHubTimeRangeSelection {
10991 case quarterToDate
11092 case yearToDate
11193
112- var description : String {
113- switch self {
114- case . custom:
115- return Localization . custom
116- case . today:
117- return Localization . today
118- case . yesterday:
119- return Localization . yesterday
120- case . lastWeek:
121- return Localization . lastWeek
122- case . lastMonth:
123- return Localization . lastMonth
124- case . lastQuarter:
125- return Localization . lastQuarter
126- case . lastYear:
127- return Localization . lastYear
128- case . weekToDate:
129- return Localization . weekToDate
130- case . monthToDate:
131- return Localization . monthToDate
132- case . quarterToDate:
133- return Localization . quarterToDate
134- case . yearToDate:
135- return Localization . yearToDate
136- }
137- }
138-
13994 /// The granularity that should be used to request stats from the given SelectedType
14095 ///
14196 var granularity : StatsGranularityV4 {
@@ -171,33 +126,6 @@ extension AnalyticsHubTimeRangeSelection {
171126 }
172127 }
173128
174- var tracksIdentifier : String {
175- switch self {
176- case . custom:
177- return " Custom "
178- case . today:
179- return " Today "
180- case . yesterday:
181- return " Yesterday "
182- case . lastWeek:
183- return " Last Week "
184- case . lastMonth:
185- return " Last Month "
186- case . lastQuarter:
187- return " Last Quarter "
188- case . lastYear:
189- return " Last Year "
190- case . weekToDate:
191- return " Week to Date "
192- case . monthToDate:
193- return " Month to Date "
194- case . quarterToDate:
195- return " Quarter to Date "
196- case . yearToDate:
197- return " Year to Date "
198- }
199- }
200-
201129 init ( _ statsTimeRange: StatsTimeRangeV4 ) {
202130 switch statsTimeRange {
203131 case . today:
@@ -217,12 +145,8 @@ extension AnalyticsHubTimeRangeSelection {
217145private extension AnalyticsHubTimeRangeSelection . SelectionType {
218146 func toRangeData( referenceDate: Date , timezone: TimeZone , calendar: Calendar ) -> AnalyticsHubTimeRangeData ? {
219147 switch self {
220- case let . custom( start? , end? ) :
148+ case let . custom( start, end) :
221149 return AnalyticsHubCustomRangeData ( start: start, end: end, timezone: timezone, calendar: calendar)
222- case . custom:
223- // Nil custom dates are not supported but can exists when the user has selected the custom range option but hasn't choosen dates yet.
224- // To properly fix this, we should decouple UI selection types, from ranges selection types.
225- return nil
226150 case . today:
227151 return AnalyticsHubTodayRangeData ( referenceDate: referenceDate, timezone: timezone, calendar: calendar)
228152 case . yesterday:
@@ -255,17 +179,6 @@ extension AnalyticsHubTimeRangeSelection {
255179 }
256180
257181 enum Localization {
258- static let custom = NSLocalizedString ( " Custom " , comment: " Title of the Analytics Hub Custom selection range " )
259- static let today = NSLocalizedString ( " Today " , comment: " Title of the Analytics Hub Today's selection range " )
260- static let yesterday = NSLocalizedString ( " Yesterday " , comment: " Title of the Analytics Hub Yesterday selection range " )
261- static let lastWeek = NSLocalizedString ( " Last Week " , comment: " Title of the Analytics Hub Last Week selection range " )
262- static let lastMonth = NSLocalizedString ( " Last Month " , comment: " Title of the Analytics Hub Last Month selection range " )
263- static let lastQuarter = NSLocalizedString ( " Last Quarter " , comment: " Title of the Analytics Hub Last Quarter selection range " )
264- static let lastYear = NSLocalizedString ( " Last Year " , comment: " Title of the Analytics Hub Last Year selection range " )
265- static let weekToDate = NSLocalizedString ( " Week to Date " , comment: " Title of the Analytics Hub Week to Date selection range " )
266- static let monthToDate = NSLocalizedString ( " Month to Date " , comment: " Title of the Analytics Hub Month to Date selection range " )
267- static let quarterToDate = NSLocalizedString ( " Quarter to Date " , comment: " Title of the Analytics Hub Quarter to Date selection range " )
268- static let yearToDate = NSLocalizedString ( " Year to Date " , comment: " Title of the Analytics Hub Year to Date selection range " )
269182 static let selectionTitle = NSLocalizedString ( " Date Range " , comment: " Title of the range selection list " )
270183 static let noCurrentPeriodAvailable = NSLocalizedString ( " No current period available " ,
271184 comment: " A error message when it's not possible to acquire "
0 commit comments