Module: DOTIW::Methods
- Included in:
- ActionView::Helpers::DateHelper
- Defined in:
- lib/dotiw/methods.rb
Instance Method Summary collapse
- #distance_of_time(seconds, options = {}) ⇒ Object
- #distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {}) ⇒ Object
- #distance_of_time_in_words_hash(from_time, to_time, options = {}) ⇒ Object
- #time_ago_in_words(from_time, include_seconds_or_options = {}) ⇒ Object
Instance Method Details
#distance_of_time(seconds, options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/dotiw/methods.rb', line 12 def distance_of_time(seconds, = {}) [:include_seconds] ||= true _display_time_in_words DOTIW::TimeHash.new(seconds, nil, nil, ).to_hash, end |
#distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dotiw/methods.rb', line 17 def distance_of_time_in_words(from_time, to_time = 0, = {}, = {}) if .is_a?(Hash) = else [:include_seconds] ||= !! end return distance_of_time(from_time, ) if to_time == 0 hash = distance_of_time_in_words_hash(from_time, to_time, ) _display_time_in_words(hash, ) end |
#distance_of_time_in_words_hash(from_time, to_time, options = {}) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/dotiw/methods.rb', line 5 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(nil, from_time, to_time, ).to_hash end |
#time_ago_in_words(from_time, include_seconds_or_options = {}) ⇒ Object
29 30 31 |
# File 'lib/dotiw/methods.rb', line 29 def time_ago_in_words(from_time, = {}) distance_of_time_in_words(from_time, Time.current, ) end |