From c29db9f210c81a757e035ee6c8e1a055f6b676b3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 13 Apr 2005 05:15:41 +0000 Subject: Added minute_step as an option to select_minute (and the helpers that use it) to jump in larger increments than just 1 minute. At 15, it would return 0, 15, 30, 45 options #1085 [ordwaye@evergreen.edu] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1154 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/date_helper.rb | 3 ++- actionpack/test/template/date_helper_test.rb | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 9abf436390..591fe91b4e 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added minute_step as an option to select_minute (and the helpers that use it) to jump in larger increments than just 1 minute. At 15, it would return 0, 15, 30, 45 options #1085 [ordwaye@evergreen.edu] + * Fixed that an exception would be thrown when an empty form was submitted #1090 [jan@ulbrich-boerwang.de] * Moved TextHelper#human_size to NumberHelper#number_to_human_size, but kept an deprecated alias to the old method name diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 9ffafe70b4..6f9545983c 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -114,11 +114,12 @@ module ActionView end # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. + # Also can return a select tag with options by minute_step from 0 through 59 with the 00 minute selected # The minute can also be substituted for a minute number. def select_minute(datetime, options = {}) minute_options = [] - 0.upto(59) do |minute| + 0.step(59, options[:minute_step] || 1) do |minute| minute_options << ((datetime && (datetime.kind_of?(Fixnum) ? datetime : datetime.min) == minute) ? "\n" : "\n" diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index fa51ef8253..ab5cfc1c7a 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -164,6 +164,14 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_minute(Time.mktime(2003, 8, 16, 8, 4, 18), :include_blank => true) end + def test_select_minute_with_blank_and_step + expected = %(\n" + + assert_equal expected, select_minute(Time.mktime(2003, 8, 16, 8, 4, 18), { :include_blank => true , :minute_step => 15 }) + end + def test_select_minute_nil_with_blank expected = %(\n) + expected << %(\n\n\n\n\n) + expected << "\n" + + assert_equal expected, select_minute(nil, { :include_blank => true , :minute_step => 15 }) + end + def test_select_second expected = %(