Class: Informix::IntervalDTS
- Inherits:
-
IntervalBase
- Object
- IntervalBase
- Informix::IntervalDTS
- Defined in:
- lib/informix/interval.rb
Overview
The IntervalDTS
class is an Interval class dedicated only to represent intervals in the scope DAY TO SECOND.
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.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Attributes inherited from IntervalBase
Instance Method Summary collapse
-
#+(obj) ⇒ Object
interval + datetime => datetime interval + time => time.
-
#initialize(val) ⇒ IntervalDTS
constructor
Creates an IntervalDTS object with
val
as value. -
#to_days ⇒ Object
Converts invl to days.
-
#to_hours ⇒ Object
Converts invl to hours.
-
#to_minutes ⇒ Object
Converts invl to minutes.
-
#to_s ⇒ Object
Returns an ANSI SQL standards compliant string representation.
-
#to_seconds ⇒ Object
Converts invl to seconds.
Methods inherited from IntervalBase
Constructor Details
#initialize(val) ⇒ IntervalDTS
Creates an IntervalDTS object with val
as value.
IntervalDTS.new(val) => interval
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/informix/interval.rb', line 152 def initialize(val) super @days, @hours = @val.abs.divmod(24*60*60) @hours, @minutes = @hours.divmod(60*60) @minutes, @seconds = @minutes.divmod(60) if @val < 0 @days = -@days; @hours = -@hours; @minutes = -@minutes; @seconds = -@seconds end @fields = [ @days, @hours, @minutes, @seconds ] end |
Instance Attribute Details
#days ⇒ Object (readonly)
Returns the value of attribute days.
147 148 149 |
# File 'lib/informix/interval.rb', line 147 def days @days end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
147 148 149 |
# File 'lib/informix/interval.rb', line 147 def hours @hours end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
147 148 149 |
# File 'lib/informix/interval.rb', line 147 def minutes @minutes end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
147 148 149 |
# File 'lib/informix/interval.rb', line 147 def seconds @seconds end |
Instance Method Details
#+(obj) ⇒ Object
interval + datetime => datetime
interval + time => time
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/informix/interval.rb', line 166 def +(obj) case obj when DateTime obj + (Rational === @val ? @val/86400 : @val/86400.0) when Time obj + @val else super end end |
#to_days ⇒ Object
Converts invl to days
invl.to_days => numeric
187 |
# File 'lib/informix/interval.rb', line 187 def to_days; Rational === @val ? @val/60/60/24 : @val/60.0/60/24 end |
#to_hours ⇒ Object
Converts invl to hours
invl.to_hours => numeric
192 |
# File 'lib/informix/interval.rb', line 192 def to_hours; Rational === @val ? @val/60/60 : @val/60.0/60 end |
#to_minutes ⇒ Object
Converts invl to minutes
invl.to_minutes => numeric
197 |
# File 'lib/informix/interval.rb', line 197 def to_minutes; Rational === @val ? @val/60 : @val/60.0 end |
#to_s ⇒ Object
Returns an ANSI SQL standards compliant string representation
invl.to_s => string
180 181 182 |
# File 'lib/informix/interval.rb', line 180 def to_s "%d %02d:%02d:%08.5f" % [@days, @hours.abs, @minutes.abs, @seconds.abs] end |
#to_seconds ⇒ Object
Converts invl to seconds
invl.to_seconds => numeric
202 |
# File 'lib/informix/interval.rb', line 202 def to_seconds; @val end |