aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-02 15:32:01 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-02 15:32:01 +0000
commitce58e5cd069ef1341b8a60be1690b2a912a0b85f (patch)
tree245cc4ceec9d1232a008d7d0ac0af4ca967ebd7f /actionpack/lib/action_view/helpers
parentf4b721904a26f631fbc6d7241b7f9480cc87ea47 (diff)
downloadrails-ce58e5cd069ef1341b8a60be1690b2a912a0b85f.tar.gz
rails-ce58e5cd069ef1341b8a60be1690b2a912a0b85f.tar.bz2
rails-ce58e5cd069ef1341b8a60be1690b2a912a0b85f.zip
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
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rwxr-xr-xactionpack/lib/action_view/helpers/date_helper.rb20
1 files changed, 20 insertions, 0 deletions
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 <tt>second</tt> 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 ?
+ "<option selected=\"selected\">#{leading_zero_on_single_digits(second)}</option>\n" :
+ "<option>#{leading_zero_on_single_digits(second)}</option>\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 <tt>minute</tt> can also be substituted for a minute number.
def select_minute(datetime, options = {})