Module: FunCi::Tui::RelativeTime

Defined in:
lib/fun_ci/tui/relative_time.rb

Class Method Summary collapse

Class Method Details

.format(iso_timestamp, now: Time.now) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fun_ci/tui/relative_time.rb', line 8

def self.format(iso_timestamp, now: Time.now)
  elapsed = now - Time.parse(iso_timestamp)
  seconds = elapsed.to_i

  if seconds < 60
    "just now"
  elsif seconds < 3600
    "#{seconds / 60}m ago"
  else
    "#{seconds / 3600}h ago"
  end
end