Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/rbfind/humansiz.rb
Constant Summary collapse
- TIME_UNITS =
[ "seconds", 60, "minutes", 60, "hours", 24, "days", 7, "weeks", ]
Class Method Summary collapse
Instance Method Summary collapse
- #long ⇒ Object
-
#lsish ⇒ Object
:call-seq: time.lsish() -> str.
Class Method Details
.start ⇒ Object
152 153 154 |
# File 'lib/rbfind/humansiz.rb', line 152 def start @start ||= Time.now end |
.str_to_sec(str) ⇒ Object
122 123 124 125 |
# File 'lib/rbfind/humansiz.rb', line 122 def str_to_sec str str =~ /(\d*) *(\w*)/ to_sec $1.to_i, $2 end |
.to_sec(num, unit) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/rbfind/humansiz.rb', line 115 def to_sec num, unit TIME_UNITS.each_slice 2 do |nam,val| return num if nam.start_with? unit num *= val end raise "No time unit: #{unit}." end |
.to_unit(n) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/rbfind/humansiz.rb', line 108 def to_unit n u = TIME_UNITS.each_slice 2 do |nam,val| break nam if not val or n < val n /= val end "#{n}#{u[0]}" end |
Instance Method Details
#long ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/rbfind/humansiz.rb', line 142 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 ⇒ Object
:call-seq:
time.lsish() -> str
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 "
138 139 140 |
# File 'lib/rbfind/humansiz.rb', line 138 def lsish strftime "%e. %b " + (year == Time.start.year ? "%H:%M:%S" : "%Y ") end |