Skip to content

Commit

Permalink
Merge pull request rails#5518 from rafaelfranca/minor-refactor
Browse files Browse the repository at this point in the history
Remove code duplication
  • Loading branch information
josevalim committed Mar 23, 2012
2 parents 9a26c90 + a26dcb6 commit 86cd1b1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions actionpack/lib/action_view/helpers/date_helper.rb
Expand Up @@ -626,7 +626,7 @@ def select_year(date, options = {}, html_options = {})
# <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>
#
Expand Down Expand Up @@ -674,11 +674,7 @@ def select_datetime
@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
Expand All @@ -701,11 +697,7 @@ def select_date
@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) }

Expand Down Expand Up @@ -807,6 +799,14 @@ def select_year
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
Expand Down

0 comments on commit 86cd1b1

Please sign in to comment.