Module: DOTIW::Methods

Extended by:
Methods
Included in:
ActionView::Helpers::DateHelper, Methods
Defined in:
lib/dotiw/methods.rb

Instance Method Summary collapse

Instance Method Details

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



14
15
16
17
# File 'lib/dotiw/methods.rb', line 14

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

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



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dotiw/methods.rb', line 19

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

  options = options_with_scope(options)
  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



7
8
9
10
11
12
# File 'lib/dotiw/methods.rb', line 7

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

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



32
33
34
# File 'lib/dotiw/methods.rb', line 32

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