| Module | ActionView::Helpers::DateHelper |
| In: |
lib/gloc-rails-text.rb
|
| LOCALIZED_HELPERS | = | true |
| LOCALIZED_MONTHNAMES | = | {} |
| LOCALIZED_ABBR_MONTHNAMES | = | {} |
This method uses current_language to return a localized string.
# File lib/gloc-rails-text.rb, line 16
16: def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
17: from_time = from_time.to_time if from_time.respond_to?(:to_time)
18: to_time = to_time.to_time if to_time.respond_to?(:to_time)
19: distance_in_minutes = (((to_time - from_time).abs)/60).round
20: distance_in_seconds = ((to_time - from_time).abs).round
21:
22: case distance_in_minutes
23: when 0..1
24: return (distance_in_minutes==0) ? l(:actionview_datehelper_time_in_words_minute_less_than) : l(:actionview_datehelper_time_in_words_minute_single) unless include_seconds
25: case distance_in_seconds
26: when 0..5 then lwr(:actionview_datehelper_time_in_words_second_less_than, 5)
27: when 6..10 then lwr(:actionview_datehelper_time_in_words_second_less_than, 10)
28: when 11..20 then lwr(:actionview_datehelper_time_in_words_second_less_than, 20)
29: when 21..40 then l(:actionview_datehelper_time_in_words_minute_half)
30: when 41..59 then l(:actionview_datehelper_time_in_words_minute_less_than)
31: else l(:actionview_datehelper_time_in_words_minute)
32: end
33:
34: when 2..45 then lwr(:actionview_datehelper_time_in_words_minute, distance_in_minutes)
35: when 46..90 then l(:actionview_datehelper_time_in_words_hour_about_single)
36: when 90..1440 then lwr(:actionview_datehelper_time_in_words_hour_about, (distance_in_minutes.to_f / 60.0).round)
37: when 1441..2880 then lwr(:actionview_datehelper_time_in_words_day, 1)
38: else lwr(:actionview_datehelper_time_in_words_day, (distance_in_minutes / 1440).round)
39: end
40: end
This method has been modified so that a localized string can be appended to the day numbers.
# File lib/gloc-rails-text.rb, line 43
43: def select_day(date, options = {})
44: day_options = []
45: prefix = l :actionview_datehelper_select_day_prefix
46:
47: 1.upto(31) do |day|
48: day_options << ((date && (date.kind_of?(Fixnum) ? date : date.day) == day) ?
49: %(<option value="#{day}" selected="selected">#{day}#{prefix}</option>\n) :
50: %(<option value="#{day}">#{day}#{prefix}</option>\n)
51: )
52: end
53:
54: select_html(options[:field_name] || 'day', day_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
55: end
This method has been modified so that
# File lib/gloc-rails-text.rb, line 61
61: def select_month(date, options = {})
62: unless LOCALIZED_MONTHNAMES.has_key?(current_language)
63: LOCALIZED_MONTHNAMES[current_language] = [''] + l(:actionview_datehelper_select_month_names).split(',')
64: LOCALIZED_ABBR_MONTHNAMES[current_language] = [''] + l(:actionview_datehelper_select_month_names_abbr).split(',')
65: end
66:
67: month_options = []
68: month_names = options[:use_short_month] ? LOCALIZED_ABBR_MONTHNAMES[current_language] : LOCALIZED_MONTHNAMES[current_language]
69:
70: if options.has_key?(:min_date) && options.has_key?(:max_date)
71: if options[:min_date].year == options[:max_date].year
72: start_month, end_month = options[:min_date].month, options[:max_date].month
73: end
74: end
75: start_month = (options[:start_month] || 1) unless start_month
76: end_month = (options[:end_month] || 12) unless end_month
77: prefix = l :actionview_datehelper_select_month_prefix
78:
79: start_month.upto(end_month) do |month_number|
80: month_name = if options[:use_month_numbers]
81: "#{month_number}#{prefix}"
82: elsif options[:add_month_numbers]
83: month_number.to_s + ' - ' + month_names[month_number]
84: else
85: month_names[month_number]
86: end
87:
88: month_options << ((date && (date.kind_of?(Fixnum) ? date : date.month) == month_number) ?
89: %(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
90: %(<option value="#{month_number}">#{month_name}</option>\n)
91: )
92: end
93:
94: select_html(options[:field_name] || 'month', month_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
95: end
This method has been modified so that
# File lib/gloc-rails-text.rb, line 100
100: def select_year(date, options = {})
101: year_options = []
102: y = date ? (date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year) : Date.today.year
103:
104: start_year = options.has_key?(:min_date) ? options[:min_date].year : (options[:start_year] || y-5)
105: end_year = options.has_key?(:max_date) ? options[:max_date].year : (options[:end_year] || y+5)
106: step_val = start_year < end_year ? 1 : -1
107: prefix = l :actionview_datehelper_select_year_prefix
108:
109: start_year.step(end_year, step_val) do |year|
110: year_options << ((date && (date.kind_of?(Fixnum) ? date : date.year) == year) ?
111: %(<option value="#{year}" selected="selected">#{year}#{prefix}</option>\n) :
112: %(<option value="#{year}">#{year}#{prefix}</option>\n)
113: )
114: end
115:
116: select_html(options[:field_name] || 'year', year_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
117: end