1+ import Experiments
12import Yosemite
23
34private extension StatsTimeRangeV4 {
4- func timeRangeText( startDate: Date , endDate: Date , selectedDate: Date , timezone: TimeZone ) -> String {
5- let selectedDateString = timeRangeSelectedDateFormatter ( timezone: timezone) . string ( from: selectedDate)
6- switch self {
7- case . today, . thisYear:
8- let dateBreadcrumbFormat = NSLocalizedString ( " %1$@ › %2$@ " , comment: " Displays a time range followed by a specific date/time " )
9- let timeRangeString = timeRangeText ( startDate: startDate, endDate: endDate, timezone: timezone)
10- return String . localizedStringWithFormat ( dateBreadcrumbFormat, timeRangeString, selectedDateString)
11- case . thisWeek, . thisMonth:
5+ func timeRangeText( startDate: Date , endDate: Date , selectedDate: Date , timezone: TimeZone , isMyStoreTabUpdatesEnabled: Bool ) -> String {
6+ let selectedDateString = timeRangeSelectedDateFormatter ( timezone: timezone,
7+ isMyStoreTabUpdatesEnabled: isMyStoreTabUpdatesEnabled)
8+ . string ( from: selectedDate)
9+
10+ if isMyStoreTabUpdatesEnabled {
1211 return selectedDateString
12+ } else {
13+ switch self {
14+ case . today, . thisYear:
15+ let dateBreadcrumbFormat = NSLocalizedString ( " %1$@ › %2$@ " , comment: " Displays a time range followed by a specific date/time " )
16+ let timeRangeString = timeRangeText ( startDate: startDate,
17+ endDate: endDate,
18+ timezone: timezone,
19+ isMyStoreTabUpdatesEnabled: isMyStoreTabUpdatesEnabled)
20+ return String . localizedStringWithFormat ( dateBreadcrumbFormat, timeRangeString, selectedDateString)
21+ case . thisWeek, . thisMonth:
22+ return selectedDateString
23+ }
1324 }
1425 }
1526
16- func timeRangeText( startDate: Date , endDate: Date , timezone: TimeZone ) -> String {
17- let dateFormatter = timeRangeDateFormatter ( timezone: timezone)
27+ func timeRangeText( startDate: Date , endDate: Date , timezone: TimeZone , isMyStoreTabUpdatesEnabled : Bool ) -> String {
28+ let dateFormatter = timeRangeDateFormatter ( timezone: timezone, isMyStoreTabUpdatesEnabled : isMyStoreTabUpdatesEnabled )
1829 switch self {
1930 case . today, . thisMonth, . thisYear:
2031 return dateFormatter. string ( from: startDate)
2132 case . thisWeek:
2233 let startDateString = dateFormatter. string ( from: startDate)
2334 let endDateString = dateFormatter. string ( from: endDate)
24- let format = NSLocalizedString ( " %1$@-%2$@ " , comment: " Displays a date range for a stats interval " )
35+ let format = isMyStoreTabUpdatesEnabled ?
36+ NSLocalizedString ( " %1$@ - %2$@ " , comment: " Displays a date range for a stats interval " ) :
37+ NSLocalizedString ( " %1$@-%2$@ " , comment: " Displays a date range for a stats interval in the legacy version " )
2538 return String . localizedStringWithFormat ( format, startDateString, endDateString)
2639 }
2740 }
2841
29- func timeRangeDateFormatter( timezone: TimeZone ) -> DateFormatter {
42+ func timeRangeDateFormatter( timezone: TimeZone , isMyStoreTabUpdatesEnabled : Bool ) -> DateFormatter {
3043 let dateFormatter : DateFormatter
3144 switch self {
3245 case . today:
@@ -36,7 +49,9 @@ private extension StatsTimeRangeV4 {
3649 case . thisWeek:
3750 dateFormatter = DateFormatter . Charts. chartAxisDayFormatter
3851 case . thisMonth:
39- dateFormatter = DateFormatter . Charts. chartAxisFullMonthFormatter
52+ dateFormatter = isMyStoreTabUpdatesEnabled ?
53+ DateFormatter . Charts. chartAxisFullMonthFormatter:
54+ DateFormatter . Charts. legacyChartAxisFullMonthFormatter
4055 case . thisYear:
4156 dateFormatter = DateFormatter . Charts. chartAxisYearFormatter
4257 }
@@ -45,15 +60,18 @@ private extension StatsTimeRangeV4 {
4560 }
4661
4762 /// Date formatter for a selected date for a time range.
48- func timeRangeSelectedDateFormatter( timezone: TimeZone ) -> DateFormatter {
63+ func timeRangeSelectedDateFormatter( timezone: TimeZone , isMyStoreTabUpdatesEnabled : Bool ) -> DateFormatter {
4964 let dateFormatter : DateFormatter
5065 switch self {
5166 case . today:
52- dateFormatter = DateFormatter . Charts. chartAxisHourFormatter
67+ dateFormatter = isMyStoreTabUpdatesEnabled ?
68+ DateFormatter . Charts. chartSelectedDateHourFormatter:
69+ DateFormatter . Charts. legacyChartSelectedDateHourFormatter
5370 case . thisWeek, . thisMonth:
5471 dateFormatter = DateFormatter . Charts. chartAxisDayFormatter
5572 case . thisYear:
56- dateFormatter = DateFormatter . Charts. chartAxisFullMonthFormatter
73+ dateFormatter = isMyStoreTabUpdatesEnabled ? DateFormatter . Charts. chartAxisFullMonthFormatter:
74+ DateFormatter . Charts. legacyChartAxisFullMonthFormatter
5775 }
5876 dateFormatter. timeZone = timezone
5977 return dateFormatter
@@ -67,20 +85,24 @@ struct StatsTimeRangeBarViewModel: Equatable {
6785 init ( startDate: Date ,
6886 endDate: Date ,
6987 timeRange: StatsTimeRangeV4 ,
70- timezone: TimeZone ) {
88+ timezone: TimeZone ,
89+ isMyStoreTabUpdatesEnabled: Bool = ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . myStoreTabUpdates) ) {
7190 timeRangeText = timeRange. timeRangeText ( startDate: startDate,
7291 endDate: endDate,
73- timezone: timezone)
92+ timezone: timezone,
93+ isMyStoreTabUpdatesEnabled: isMyStoreTabUpdatesEnabled)
7494 }
7595
7696 init ( startDate: Date ,
7797 endDate: Date ,
7898 selectedDate: Date ,
7999 timeRange: StatsTimeRangeV4 ,
80- timezone: TimeZone ) {
100+ timezone: TimeZone ,
101+ isMyStoreTabUpdatesEnabled: Bool = ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . myStoreTabUpdates) ) {
81102 timeRangeText = timeRange. timeRangeText ( startDate: startDate,
82103 endDate: endDate,
83104 selectedDate: selectedDate,
84- timezone: timezone)
105+ timezone: timezone,
106+ isMyStoreTabUpdatesEnabled: isMyStoreTabUpdatesEnabled)
85107 }
86108}
0 commit comments