From 980c64d951f028bdf0669e2a2022ba48abe80159 Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Wed, 31 Dec 2008 16:14:09 +0100 Subject: [PATCH] add some option in select_hour helper: :hour_step, :hour_start, :hour_end --- actionpack/lib/action_view/helpers/date_helper.rb | 12 ++++++- actionpack/test/template/date_helper_test.rb | 32 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 4305617..1869eb1 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -441,7 +441,13 @@ module ActionView # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. # The hour can also be substituted for a hour number. - # Override the field name using the :field_name option, 'hour' by default. + # Option available : + # * :field_name : Override the field name option, 'hour' by + # default. + # * :hour_step : Define a step in each hour. in select, 1 by + # default + # * :hour_start : Define the hour of start : 0 by default + # * :hour_end : Define the hour of end : 23 by default # # ==== Examples # my_time = Time.now + 6.hours @@ -672,7 +678,9 @@ module ActionView if @options[:use_hidden] || @options[:discard_hour] build_hidden(:hour, hour) else - build_options_and_select(:hour, hour, :end => 23) + build_options_and_select(:hour, hour, :step => @options[:hour_step], + :start => (@options[:hour_start] || 0), + :end => (@options[:hour_end] || 23)) end end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 6ec01b7..54bac74 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -456,6 +456,38 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18), :prompt => 'Choose hour') end + def test_select_hour_with_define_start + expected = %(\n" + + assert_dom_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18), :hour_start => 9) + end + + def test_select_hour_with_define_end + expected = %(\n" + + assert_dom_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18), :hour_end => 20) + end + + def test_select_hour_with_define_start_and_end + expected = %(\n" + + assert_dom_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18), :hour_start => 9, :hour_end => 20) + end + + def test_select_hour_with_step + expected = %(\n" + + assert_dom_equal expected, select_hour(Time.mktime(2003, 8, 16, 8, 4, 18), :hour_step => 2) + end + def test_select_minute expected = %(