osem-fcy/app/helpers/home_helper.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2014-04-08 21:02:10 +02:00
##
# This class contains helper for the home views.
module HomeHelper
##
# 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)
2014-05-23 21:21:11 +05:30
def conference_date_string(start_date, end_date)
startstr = 'Unknown - '
endstr = 'Unknown'
2014-04-08 21:02:10 +02:00
# When the conference in the same motn
2014-05-23 21:21:11 +05:30
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')
2014-04-08 21:02:10 +02:00
else
2014-05-23 21:21:11 +05:30
startstr = start_date.strftime('%B %d, %Y - ')
endstr = end_date.strftime('%B %d, %Y')
2014-04-08 21:02:10 +02:00
end
result = startstr + endstr
result
end
end