class Time

Constants

TIME_UNITS

Public Class Methods

start() click to toggle source
# File lib/rbfind/humansiz.rb, line 153
def start
  @start ||= Time.now
end
str_to_sec(str) click to toggle source
# File lib/rbfind/humansiz.rb, line 123
def str_to_sec str
  str =~ /(\d*) *(\w*)/
  to_sec $1.to_i, $2
end
to_sec(num, unit) click to toggle source
# File lib/rbfind/humansiz.rb, line 115
def to_sec num, unit
  TIME_UNITS.each_pair do |nam,val|
    return num if nam.start_with? unit
    num *= val.to_i
    num.nonzero? or break
  end
  raise "No time unit: #{unit}."
end
to_unit(n) click to toggle source
# File lib/rbfind/humansiz.rb, line 108
def to_unit n
  u = TIME_UNITS.each_pair do |nam,val|
    break nam if not val or n < val
    n /= val
  end
  "#{n}#{u[0]}"
end

Public Instance Methods

long() click to toggle source
# File lib/rbfind/humansiz.rb, line 143
def long
  s = Time.start
  if year == s.year && month == s.month && day == s.day then
    strftime "==%H:%M:%S"
  else
    strftime "%Y-%m-%d"
  end
end
lsish() → str click to toggle source

Build a time string like in ls -l. When the year is the current, show the time. While ls doesn’t show the seconds, this will allways include them.

Time.now.lsish           #=> " 8. Oct 15:15:19"
file.stat.mtime.lsish    #=> " 1. Apr 2008    "
# File lib/rbfind/humansiz.rb, line 139
def lsish
  strftime "%e. %b " + (year == Time.start.year ? "%H:%M:%S" : "%Y    ")
end