From ce58e5cd069ef1341b8a60be1690b2a912a0b85f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 2 Jan 2005 15:32:01 +0000 Subject: Added DateHelper#select_time and DateHelper#select_second #373 [Scott Baron] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@311 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/date_helper.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 58dab783d5..f8c19d169d 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -76,6 +76,26 @@ module ActionView select_hour(datetime, options) + select_minute(datetime, options) end + # Returns a set of html select-tags (one for hour and minute) + def select_time(datetime = Time.now, options = {}) + h = select_hour(datetime, options) + select_minute(datetime, options) + (options[:include_seconds] ? select_second(datetime, options) : '') + end + + # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. + # The second can also be substituted for a second number. + def select_second(datetime, options = {}) + second_options = [] + + 0.upto(59) do |second| + second_options << ((datetime.kind_of?(Fixnum) ? datetime : datetime.sec) == second ? + "\n" : + "\n" + ) + end + + select_html("second", second_options, options[:prefix], options[:include_blank], options[:discard_type]) + end + # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. # The minute can also be substituted for a minute number. def select_minute(datetime, options = {}) -- cgit v1.2.3