Class: Vermillion::Helper::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/client/helper/time.rb

Class Method Summary collapse

Class Method Details

.formatted(time = nil) ⇒ Object

Use the following format for a given timestamp: “d/m/y @ H:M:S AM/PM” Params:

time

Optional time value, uses the current time if not provided, to format



27
28
29
30
# File 'lib/client/helper/time.rb', line 27

def self.formatted(time = nil)
  time = ::Time.now if time.nil?
  time.strftime("%e/%-m/%Y @ %I:%M:%S%P")
end

.human_readable(start, finish) ⇒ Object

Human readable strings to represent the length between two time objects Params:

start

Start time object

finish

End time object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/client/helper/time.rb', line 8

def self.human_readable(start, finish)
  seconds = finish.to_f - start.to_f

  if seconds < 60
    "No time at all!"
  else
    minutes = (seconds / 60).round(1)
    if minutes < 1
      "#{minutes} minute"
    else
      "#{minutes} minutes"
    end
  end
end