aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-23 09:35:31 -0700
committerJosé Valim <jose.valim@gmail.com>2012-03-23 09:35:31 -0700
commit86cd1b1d4669a383881aec746cda425d515f16ac (patch)
tree1ed80d748fdbf32ef702848e6925392548b6bce3 /actionpack
parent9a26c9035f8d799bc88786f300dd260312ac5957 (diff)
parenta26dcb62714cfe1d23358c5753f9aad26c27fe29 (diff)
downloadrails-86cd1b1d4669a383881aec746cda425d515f16ac.tar.gz
rails-86cd1b1d4669a383881aec746cda425d515f16ac.tar.bz2
rails-86cd1b1d4669a383881aec746cda425d515f16ac.zip
Merge pull request #5518 from rafaelfranca/minor-refactor
Remove code duplication
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/date_helper.rb22
1 files changed, 11 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index be67042999..2bfc6371f5 100644
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -626,7 +626,7 @@ module ActionView
# <time datetime="2010-11-04" pubdate="pubdate">November 04, 2010</time>
#
# <%= time_tag Time.now do %>
- # <span>Right now</span>
+ # <span>Right now</span>
# <% end %>
# # => <time datetime="2010-11-04T17:55:45+01:00"><span>Right now</span></time>
#
@@ -674,11 +674,7 @@ module ActionView
@options[:discard_minute] ||= true if @options[:discard_hour]
@options[:discard_second] ||= true unless @options[:include_seconds] && !@options[:discard_minute]
- # If the day is hidden, the day should be set to the 1st so all month and year choices are valid. Otherwise,
- # February 31st or February 29th, 2011 can be selected, which are invalid.
- if @datetime && @options[:discard_day]
- @datetime = @datetime.change(:day => 1)
- end
+ set_day_if_discarded
if @options[:tag] && @options[:ignore_date]
select_time
@@ -701,11 +697,7 @@ module ActionView
@options[:discard_month] ||= true unless order.include?(:month)
@options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day)
- # If the day is hidden, the day should be set to the 1st so all month and year choices are valid. Otherwise,
- # February 31st or February 29th, 2011 can be selected, which are invalid.
- if @datetime && @options[:discard_day]
- @datetime = @datetime.change(:day => 1)
- end
+ set_day_if_discarded
[:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }
@@ -807,6 +799,14 @@ module ActionView
end
end
+ # If the day is hidden, the day should be set to the 1st so all month and year choices are
+ # valid. Otherwise, February 31st or February 29th, 2011 can be selected, which are invalid.
+ def set_day_if_discarded
+ if @datetime && @options[:discard_day]
+ @datetime = @datetime.change(:day => 1)
+ end
+ end
+
# Returns translated month names, but also ensures that a custom month
# name array has a leading nil element.
def month_names