Class: DateTime::Deta
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Class Method Summary collapse
Instance Method Summary collapse
- #display(include_seconds = true) ⇒ Object
-
#initialize(seconds) ⇒ Deta
constructor
A new instance of Deta.
-
#to_a ⇒ Object
to [years, months, days, hours, minutes, seconds].
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
#days ⇒ Object (readonly)
Returns the value of attribute days.
52 53 54 |
# File 'lib/tagen/date.rb', line 52 def days @days end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
52 53 54 |
# File 'lib/tagen/date.rb', line 52 def hours @hours end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
52 53 54 |
# File 'lib/tagen/date.rb', line 52 def minutes @minutes end |
#months ⇒ Object (readonly)
Returns the value of attribute months.
52 53 54 |
# File 'lib/tagen/date.rb', line 52 def months @months end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
52 53 54 |
# File 'lib/tagen/date.rb', line 52 def seconds @seconds end |
#years ⇒ Object (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.
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_a ⇒ Object
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 |