@@ -2,29 +2,24 @@ module StatsHelper
2
2
def market_share_distribution_chart ( search_params )
3
3
url = market_share_distribution_data_path ( search : search_params )
4
4
title = t ( 'stats.market_share.distribution.chart_title' ,
5
- date : title_period ( search_params [ :start_date ] ,
6
- search_params [ :end_date ] ) )
5
+ date : title_period ( search_params [ :end_date ] ) )
7
6
tag . div ( nil , data : chart_data_params ( url : url , title : title , type : __method__ . to_s ) ) do
8
7
tag . div ( preloader , class : 'pie_chart' )
9
8
end
10
9
end
11
10
12
- # rubocop:disable Metrics/MethodLength
13
11
def market_share_growth_rate_chart ( search_params )
14
12
url = market_share_growth_rate_data_path ( search : search_params )
15
13
title = t ( 'stats.market_share.growth_rate.chart_title' ,
16
- date : title_period ( search_params [ :start_date ] ,
17
- search_params [ :end_date ] ) )
14
+ date : title_period ( search_params [ :end_date ] ) )
18
15
subtitle = t ( 'stats.market_share.growth_rate.chart_subtitle' ,
19
- date : title_period ( search_params [ :compare_to_start_date ] ,
20
- search_params [ :compare_to_end_date ] ) )
16
+ date : title_period ( search_params [ :compare_to_end_date ] ) )
21
17
tag . div ( nil , data : chart_data_params ( url : url , title : title , type : __method__ . to_s ,
22
18
subtitle : subtitle ,
23
19
translations : date_translations ( search_params ) ) ) do
24
20
data_type_radio_buttons + tag . div ( preloader , class : 'bar_chart' )
25
21
end
26
22
end
27
- # rubocop:enable Metrics/MethodLength
28
23
29
24
private
30
25
@@ -46,14 +41,22 @@ def data_type_radio_buttons(tags: [])
46
41
end
47
42
end
48
43
49
- def title_period ( start_date , end_date , period : '' )
50
- period += "#{ translate_date ( to_date ( start_date ) ) } - " if start_date . present?
44
+ def title_period ( end_date , period : '' )
51
45
period += translate_date ( to_date ( end_date ) ) . to_s
46
+
52
47
period
53
48
end
54
49
55
50
def to_date ( month_year )
56
- Date . strptime ( month_year , '%m.%y' )
51
+ parsed_date = Date . strptime ( month_year , '%m.%y' )
52
+
53
+ current_date = Time . zone . today
54
+
55
+ if parsed_date . month == current_date . month && parsed_date . year == current_date . year
56
+ current_date
57
+ else
58
+ parsed_date . end_of_month
59
+ end
57
60
end
58
61
59
62
def translate_date ( date )
@@ -76,6 +79,7 @@ def date_translations(params, dates: {})
76
79
compare_to_end_date = to_date ( params [ :compare_to_end_date ] )
77
80
dates [ params [ :end_date ] ] = translate_date ( end_date )
78
81
dates [ params [ :compare_to_end_date ] ] = translate_date ( compare_to_end_date )
82
+
79
83
dates
80
84
end
81
85
end
0 commit comments