Class Informix::IntervalDTS
In: lib/informix/interval.rb
Parent: IntervalBase

The IntervalDTS class is an Interval class dedicated only to represent intervals in the scope DAY TO SECOND.

Methods

+   new   to_days   to_hours   to_minutes   to_s   to_seconds  

Attributes

days  [R] 
hours  [R] 
minutes  [R] 
seconds  [R] 

Public Class methods

Creates an IntervalDTS object with val as value.

  IntervalDTS.new(val)  =>  interval

[Source]

     # File lib/informix/interval.rb, line 152
152:     def initialize(val)
153:       super
154:       @days, @hours = @val.abs.divmod(24*60*60)
155:       @hours, @minutes = @hours.divmod(60*60)
156:       @minutes, @seconds = @minutes.divmod(60)
157:       if @val < 0
158:         @days = -@days; @hours = -@hours; @minutes = -@minutes;
159:         @seconds = -@seconds
160:       end
161:       @fields = [ @days, @hours, @minutes, @seconds ]
162:     end

Public Instance methods

interval + datetime => datetime interval + time => time

[Source]

     # File lib/informix/interval.rb, line 166
166:     def +(obj)
167:       case obj
168:       when DateTime
169:         obj + (Rational === @val ? @val/86400 : @val/86400.0)
170:       when Time
171:         obj + @val
172:       else
173:         super
174:       end
175:     end

Converts invl to days

  invl.to_days  => numeric

[Source]

     # File lib/informix/interval.rb, line 187
187:     def to_days; Rational === @val ? @val/60/60/24 : @val/60.0/60/24 end

Converts invl to hours

  invl.to_hours  => numeric

[Source]

     # File lib/informix/interval.rb, line 192
192:     def to_hours; Rational === @val ? @val/60/60 : @val/60.0/60 end

Converts invl to minutes

  invl.to_minutes  => numeric

[Source]

     # File lib/informix/interval.rb, line 197
197:     def to_minutes; Rational === @val ? @val/60 : @val/60.0 end

Returns an ANSI SQL standards compliant string representation

  invl.to_s   => string

[Source]

     # File lib/informix/interval.rb, line 180
180:     def to_s
181:       "%d %02d:%02d:%08.5f" % [@days, @hours.abs, @minutes.abs, @seconds.abs]
182:     end

Converts invl to seconds

  invl.to_seconds  => numeric

[Source]

     # File lib/informix/interval.rb, line 202
202:     def to_seconds; @val end

[Validate]