Module: Binxtils::SetPeriod
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/binxtils/set_period.rb
Constant Summary collapse
- PERIOD_TYPES =
%w[hour day month year week all next_week next_month].freeze
Instance Method Summary collapse
-
#set_period ⇒ Object
For setting periods, particularly for graphing.
Instance Method Details
#set_period ⇒ Object
For setting periods, particularly for graphing
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/binxtils/set_period.rb', line 14 def set_period set_timezone # Set time period @period ||= params[:period] if @period == "custom" if params[:start_time].present? @start_time = Binxtils::TimeParser.parse(params[:start_time], @timezone) @end_time = Binxtils::TimeParser.parse(params[:end_time], @timezone) || latest_period_date @start_time, @end_time = @end_time, @start_time if @start_time > @end_time else set_time_range_from_period end elsif params[:search_at].present? @period = "custom" @search_at = Binxtils::TimeParser.parse(params[:search_at], @timezone) offset = params[:period].present? ? params[:period].to_i : 10.minutes.to_i @start_time = @search_at - offset @end_time = @search_at + offset else set_time_range_from_period end # Add this render_chart in here so we don't have to define it in all the controllers @render_chart = Binxtils::InputNormalizer.boolean(params[:render_chart]) @time_range = @start_time..@end_time end |