Removed conference_date_string_helper, moved date_string to application_controller

Deleted home_helper.rb
This commit is contained in:
Gopesh Tulsyan 2014-07-10 21:29:07 +05:30
parent 85e9fdc643
commit c68c6394bc
6 changed files with 34 additions and 40 deletions

View file

@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :get_conferences
before_filter :store_location
helper_method :date_string
def store_location
session[:return_to] = request.fullpath if request.get? and controller_name != "user_sessions" and controller_name != "sessions"
@ -76,4 +77,32 @@ class ApplicationController < ActionController::Base
def not_found
raise ActionController::RoutingError.new('Not Found')
end
##
# Returns a string build from the start and end date of the given conference.
#
# If the conference starts and ends in the same month and year
# * %B %d - %d, %Y (January 17 - 21 2014)
# If the conference ends in another month but in the same year
# * %B %d - %B %d, %Y (January 31 - February 02 2014)
# All other cases
# * %B %d, %Y - %B %d, %Y (December 30, 2013 - January 02, 2014)
def date_string(start_date, end_date)
startstr = 'Unknown - '
endstr = 'Unknown'
# When the conference in the same month
if start_date.month == end_date.month && start_date.year == end_date.year
startstr = start_date.strftime('%B %d - ')
endstr = end_date.strftime('%d, %Y')
elsif start_date.month != end_date.month && start_date.year == end_date.year
startstr = start_date.strftime('%B %d - ')
endstr = end_date.strftime('%B %d, %Y')
else
startstr = start_date.strftime('%B %d, %Y - ')
endstr = end_date.strftime('%B %d, %Y')
end
result = startstr + endstr
result
end
end