Class: Toro::Monitor::TimeFormatter

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Helpers::DateHelper
Defined in:
lib/toro/monitor/time_formatter.rb

Class Method Summary collapse

Class Method Details

.distance_of_time(from_time, to_time) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/toro/monitor/time_formatter.rb', line 7

def distance_of_time(from_time, to_time)
  replacements = {
    'less than ' => '',
    'about ' => '',
    ' days' => 'd',
    ' day' => 'd',
    ' hours' => 'h',
    ' hour' => 'h',
    ' minutes' => 'm',
    ' minute' => 'm',
    ' seconds' => 's',
    ' second' => 's'
  }
  phrase = distance_of_time_in_words(from_time, to_time, include_seconds: true)
  replacements.each { |from, to| phrase.gsub!(from, to) }
  phrase
end