Module: ActionView::Helpers::DateHelper
- Defined in:
- lib/dotiw.rb
Instance Method Summary collapse
- #distance_of_time(seconds, options = {}) ⇒ Object
- #distance_of_time_in_percent(from_time, current_time, to_time, options = {}) ⇒ Object
- #distance_of_time_in_words(from_time, to_time, include_seconds = false, options = {}) ⇒ Object
- #distance_of_time_in_words_hash(from_time, to_time, options = {}) ⇒ Object
- #old_distance_of_time_in_words ⇒ Object
Instance Method Details
#distance_of_time(seconds, options = {}) ⇒ Object
20 21 22 |
# File 'lib/dotiw.rb', line 20 def distance_of_time(seconds, = {}) display_time_in_words DOTIW::TimeHash.new(seconds).to_hash, end |
#distance_of_time_in_percent(from_time, current_time, to_time, options = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/dotiw.rb', line 30 def distance_of_time_in_percent(from_time, current_time, to_time, = {}) [:precision] ||= 0 distance = to_time - from_time result = ((current_time - from_time) / distance) * 100 number_with_precision(result, ).to_s + "%" end |
#distance_of_time_in_words(from_time, to_time, include_seconds = false, options = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/dotiw.rb', line 24 def distance_of_time_in_words(from_time, to_time, include_seconds = false, = {}) return old_distance_of_time_in_words(from_time, to_time, include_seconds, ) if .delete(:vague) hash = distance_of_time_in_words_hash(from_time, to_time, ) display_time_in_words(hash, include_seconds, ) end |
#distance_of_time_in_words_hash(from_time, to_time, options = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/dotiw.rb', line 13 def distance_of_time_in_words_hash(from_time, to_time, = {}) from_time = from_time.to_time if !from_time.is_a?(Time) && from_time.respond_to?(:to_time) to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time) DOTIW::TimeHash.new((from_time - to_time).abs, from_time, to_time, ).to_hash end |
#old_distance_of_time_in_words ⇒ Object
11 |
# File 'lib/dotiw.rb', line 11 alias_method :old_distance_of_time_in_words, :distance_of_time_in_words |