Module: ActionView::Helpers::DateHelper

Defined in:
lib/dotiw/action_view_ext/helpers/date_helper.rb

Instance Method Summary collapse

Instance Method Details

#distance_of_time(seconds, options = {}) ⇒ Object



13
14
15
16
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 13

def distance_of_time(seconds, options = {})
  options[:include_seconds] ||= true
  display_time_in_words DOTIW::TimeHash.new(seconds, nil, nil, options).to_hash, options
end

#distance_of_time_in_percent(from_time, current_time, to_time, options = {}) ⇒ Object



30
31
32
33
34
35
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 30

def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
  options[:precision] ||= 0
  distance = to_time - from_time
  result = ((current_time - from_time) / distance) * 100
  number_with_precision(result, options).to_s + "%"
end

#distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 18

def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
  if include_seconds_or_options.is_a?(Hash)
    options = include_seconds_or_options
  else
    options[:include_seconds] ||= !!include_seconds_or_options
  end
  return distance_of_time(from_time, options) if to_time == 0
  return old_distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague)
  hash = distance_of_time_in_words_hash(from_time, to_time, options)
  display_time_in_words(hash, options)
end

#distance_of_time_in_words_hash(from_time, to_time, options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 6

def distance_of_time_in_words_hash(from_time, to_time, options = {})
  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(nil, from_time, to_time, options).to_hash
end

#old_distance_of_time_in_words ⇒ Object



4
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 4

alias_method :old_distance_of_time_in_words, :distance_of_time_in_words

#old_time_ago_in_words ⇒ Object



37
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 37

alias_method :old_time_ago_in_words, :time_ago_in_words

#time_ago_in_words(from_time, include_seconds_or_options = {}) ⇒ Object



39
40
41
# File 'lib/dotiw/action_view_ext/helpers/date_helper.rb', line 39

def time_ago_in_words(from_time, include_seconds_or_options = {})
  distance_of_time_in_words(from_time, Time.now, include_seconds_or_options)
end