Class: Time

Inherits:
Object show all
Defined in:
lib/feldtruby/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.human_readable_timestr(seconds, insertSpace = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/feldtruby/time.rb', line 28

def Time.human_readable_timestr(seconds, insertSpace = false)
  sp = insertSpace ? " " : ""
  if seconds < 1e-4
    "%.2f#{sp}usec" % (seconds*1e6)
  elsif seconds < 1e-1
    "%.2f#{sp}msec" % (seconds*1e3)
  elsif seconds > 60*60.0
    "%.2f#{sp}hours" % (seconds/3600.0)
  elsif seconds > 60.0
    "%.2f#{sp}mins" % (seconds/60.0)
  else
    "%.2f#{sp}sec" % seconds
  end
end

.timestamp(options = {:short => false}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/feldtruby/time.rb', line 20

def Time.timestamp(options = {:short => false})
  if options[:short]
    Time.now.strftime("%y%m%d %H:%M.%S")
  else
    Time.now.strftime("%Y%m%d %H:%M.%S")
  end
end

Instance Method Details

#micro_secondsObject

Number of microseconds since Unix epoch.



9
10
11
# File 'lib/feldtruby/time.rb', line 9

def micro_seconds
  (to_i * 1_000_000) + (nsec / 1_000)
end

#milli_secondsObject

Number of milliseconds since Unix epoch.



4
5
6
# File 'lib/feldtruby/time.rb', line 4

def milli_seconds
  (to_i * 1000) + (nsec / 1_000_000)
end

#nano_secondsObject

Number of nanoseconds since Unix epoch.



14
15
16
# File 'lib/feldtruby/time.rb', line 14

def nano_seconds
  (to_i * 1_000_000_000) + nsec
end