Module | ActionView::Helpers::DateHelper |
In: |
lib/rails/localized_action_view.rb
|
distance_of_time_in_words | -> | old_distance_of_time_in_words |
alias_method :orig_date_select, :date_select
Blend default options with localized :order option
# File lib/rails/localized_action_view.rb, line 82 82: def date_select(object_name, method, options = {}) 83: options.reverse_merge!( :order => :date_helper_order ) 84: orig_date_select(object_name, method, options) 85: end
alias_method :orig_datetime_select, :datetime_select
Blend default options with localized :order option
# File lib/rails/localized_action_view.rb, line 89 89: def datetime_select(object_name, method, options = {}) 90: options.reverse_merge!( :order => :date_helper_order ) 91: orig_datetime_select(object_name, method, options) 92: end
# File lib/rails/localized_action_view.rb, line 10 10: def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false) 11: from_time = from_time.to_time if from_time.respond_to?(:to_time) 12: to_time = to_time.to_time if to_time.respond_to?(:to_time) 13: distance_in_minutes = (((to_time - from_time).abs)/60).round 14: distance_in_seconds = ((to_time - from_time).abs).round 15: 16: case distance_in_minutes 17: when 0..1 18: return (distance_in_minutes==0) ? :date_helper_less_than_a_minute.l : :date_helper_one_minute.l unless include_seconds 19: case distance_in_seconds 20: when 0..5 then format( :date_helper_less_than_x_seconds.l , 5 ) 21: when 6..10 then format( :date_helper_less_than_x_seconds.l , 10 ) 22: when 11..20 then format( :date_helper_less_than_x_seconds.l , 20 ) 23: when 21..40 then :date_helper_half_a_minute.l 24: when 41..59 then :date_helper_less_than_a_minute.l 25: else :date_helper_one_minute.l 26: end 27: 28: when 2..44 then format(:date_helper_x_minutes.l, distance_in_minutes) 29: when 45..89 then :date_helper_one_hour.l 30: when 90..1439 then format( :date_helper_x_hours.l , (distance_in_minutes.to_f / 60.0).round ) 31: when 1440..2879 then :date_helper_one_day.l 32: when 2880..43199 then format( :date_helper_x_days.l , (distance_in_minutes / 1440).round ) 33: when 43200..86399 then :date_helper_one_month.l 34: when 86400..525959 then format( :date_helper_x_months.l , (distance_in_minutes / 43200).round ) 35: when 525960..1051919 then :date_helper_one_year.l 36: else format( :date_helper_x_years.l , (distance_in_minutes / 525960).round ) 37: end 38: end
# File lib/rails/localized_action_view.rb, line 94 94: def select_month(date, options = {}) 95: val = date ? (date.kind_of?(Fixnum) ? date : date.month) : '' 96: if options[:use_hidden] 97: hidden_html(options[:field_name] || 'month', val, options) 98: else 99: month_options = [] 100: monthnames = :date_helper_month_names.l 101: abbr_monthnames = :date_helper_abbr_month_names.l 102: month_names = options[:use_month_names] || (options[:use_short_month] ? abbr_monthnames : monthnames) 103: month_names.unshift(nil) if month_names.size < 13 104: 1.upto(12) do |month_number| 105: month_name = if options[:use_month_numbers] 106: month_number 107: elsif options[:add_month_numbers] 108: month_number.to_s + ' - ' + month_names[month_number] 109: else 110: month_names[month_number] 111: end 112: 113: month_options << ((val == month_number) ? 114: %(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) : 115: %(<option value="#{month_number}">#{month_name}</option>\n) 116: ) 117: end 118: select_html(options[:field_name] || 'month', month_options, options) 119: end 120: end