Sha256: f1686fce624405f1a7332b8206b9bd7a7efece9efef70aced270e377f4740744

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module TimecopConsole
  class MainController < ::ApplicationController
    skip_filter :handle_timecop_offset

    def update
      if date_select_format?
        year   = params['timecop']['current_time(1i)']
        month  = params['timecop']['current_time(2i)']
        day    = params['timecop']['current_time(3i)']
        hour   = params['timecop']['current_time(4i)']
        minute = params['timecop']['current_time(5i)']
        second = Time.now.sec
      else
        # backward compatible format
        year   = params[:year]
        month  = params[:month]
        day    = params[:day]
        hour   = params[:hour]
        minute = params[:min]
        second = params[:sec]
      end

      session[SESSION_KEY_NAME] = Time.zone.local(year, month, day, hour, minute, second)
      redirect_to :back
    end

    def reset
      session[SESSION_KEY_NAME] = nil
      redirect_to :back
    end

    private

      # http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select
      def date_select_format?
        params['timecop'].present? && params['timecop']['current_time(1i)'].present?
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timecop-console-0.3.1 app/controllers/timecop_console/main_controller.rb