Class: DateTime::Deta

Inherits:
Object show all
Defined in:
lib/tagen/date.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ Deta

Returns a new instance of Deta.



54
55
56
57
58
59
60
61
# File 'lib/tagen/date.rb', line 54

def initialize(seconds)
  deta = seconds
  deta, @seconds = deta.divmod(60)
  deta, @minutes = deta.divmod(60)
  deta, @hours = deta.divmod(24)
  deta, @days = deta.divmod(30)
  @years, @months = deta.divmod(12)
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



52
53
54
# File 'lib/tagen/date.rb', line 52

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



52
53
54
# File 'lib/tagen/date.rb', line 52

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



52
53
54
# File 'lib/tagen/date.rb', line 52

def minutes
  @minutes
end

#monthsObject (readonly)

Returns the value of attribute months.



52
53
54
# File 'lib/tagen/date.rb', line 52

def months
  @months
end

#secondsObject (readonly)

Returns the value of attribute seconds.



52
53
54
# File 'lib/tagen/date.rb', line 52

def seconds
  @seconds
end

#yearsObject (readonly)

Returns the value of attribute years.



52
53
54
# File 'lib/tagen/date.rb', line 52

def years
  @years
end

Class Method Details

.deta(from, to) ⇒ DateTime::Deta

Returns deta.

Parameters:

Returns:



46
47
48
49
# File 'lib/tagen/date.rb', line 46

def deta(from, to)
  seconds = (from-to)*24*3600.to_i
  self.new(seconds)
end

Instance Method Details

#display(include_seconds = true) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tagen/date.rb', line 63

def display(include_seconds=true)
  ret = ""
  ret << "#{years} years " unless years == 0
  ret << "#{months} months " unless months == 0
  ret << "#{days} days " unless days==0
  ret << "#{hours} hours " unless hours == 0
  ret << "#{minutes} minutes " unless minutes == 0
  ret << "#{seconds} seconds" if include_seconds

  ret
end

#to_aObject

to [years, months, days, hours, minutes, seconds]



76
77
78
# File 'lib/tagen/date.rb', line 76

def to_a
  [ years, months, days, hours, minutes, seconds ]
end