Class: DateUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/svnx/util/dateutil.rb

Class Method Summary collapse

Class Method Details

.fmt_mmdd_hhmm(date) ⇒ Object



32
33
34
# File 'lib/svnx/util/dateutil.rb', line 32

def fmt_mmdd_hhmm date
  date.strftime "%m/%d %H:%M"
end

.relative_full(datetime, reltime = Time.now) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/svnx/util/dateutil.rb', line 8

def relative_full datetime, reltime = Time.now
  secs = (reltime - datetime).to_i
  if ago = to_time_units(secs)
    ago + " ago (" + fmt_mmdd_hhmm(datetime) + ")"
  else
    datetime.strftime "%Y/%m/%d %H:%M"
  end
end

.to_time_units(seconds) ⇒ Object

returns the value in seconds, minutes, hours, or days, if within a week



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/svnx/util/dateutil.rb', line 18

def to_time_units seconds
  secs = seconds.to_i

  if secs < 120
    "#{secs} seconds"
  elsif (min = secs / 60) < 120
    "#{min} minutes"
  elsif (hour = min / 60) < 72
    "#{hour} hours"
  elsif (day = hour / 24) < 7
    "#{day} days"
  end
end