Skip to content
Browse files

DRY this baby up

  • Loading branch information...
1 parent 610e4d9 commit 8bce6e761d52afd68bb06ca9ff8222f072e06cc8 @asanghi asanghi committed
Showing with 4 additions and 23 deletions.
  1. +4 −23 actionpack/lib/action_view/helpers/date_helper.rb
View
27 actionpack/lib/action_view/helpers/date_helper.rb
@@ -716,10 +716,8 @@ def select_minute
def select_hour
if @options[:use_hidden] || @options[:discard_hour]
build_hidden(:hour, hour)
- elsif @options[:ampm]
- build_select(:hour, build_ampm_options(hour, :end => 23))
else
- build_options_and_select(:hour, hour, :end => 23)
+ build_options_and_select(:hour, hour, :end => 23, :ampm => @options[:ampm])
end
end
@@ -828,24 +826,6 @@ def build_options_and_select(type, selected, options = {})
build_select(type, build_options(selected, options))
end
- def build_ampm_options(selected, options = {})
- start = options.delete(:start) || 0
- stop = options.delete(:end) || 23
- step = options.delete(:step) || 1
- options.reverse_merge!({:leading_zeros => true})
- leading_zeros = options.delete(:leading_zeros)
-
- select_options = []
- start.step(stop, step) do |i|
- text = AMPM_TRANSLATION[i]
- value = leading_zeros ? sprintf("%02d", i) : i
- tag_options = { :value => value }
- tag_options[:selected] = "selected" if selected == i
- select_options << content_tag(:option, text, tag_options)
- end
- (select_options.join("\n") + "\n").html_safe
- end
-
# Build select option html from date value and options
# build_options(15, :start => 1, :end => 31)
# => "<option value="1">1</option>
@@ -855,7 +835,7 @@ def build_options(selected, options = {})
start = options.delete(:start) || 0
stop = options.delete(:end) || 59
step = options.delete(:step) || 1
- options.reverse_merge!({:leading_zeros => true})
+ options.reverse_merge!({:leading_zeros => true, :ampm => false})
leading_zeros = options.delete(:leading_zeros)
select_options = []
@@ -863,7 +843,8 @@ def build_options(selected, options = {})
value = leading_zeros ? sprintf("%02d", i) : i
tag_options = { :value => value }
tag_options[:selected] = "selected" if selected == i
- select_options << content_tag(:option, value, tag_options)
+ text = options[:ampm] ? AMPM_TRANSLATION[i] : value
+ select_options << content_tag(:option, text, tag_options)
end
(select_options.join("\n") + "\n").html_safe
end

0 comments on commit 8bce6e7

Please sign in to comment.
Something went wrong with that request. Please try again.