Class: Informix::IntervalDTS

Inherits:
IntervalBase show all
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

Attributes inherited from IntervalBase

#val

Instance Method Summary collapse

Methods inherited from IntervalBase

#*, #+@, #-@, #/, #<=>, #to_a

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

#daysObject (readonly)

Returns the value of attribute days.



147
148
149
# File 'lib/informix/interval.rb', line 147

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



147
148
149
# File 'lib/informix/interval.rb', line 147

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



147
148
149
# File 'lib/informix/interval.rb', line 147

def minutes
  @minutes
end

#secondsObject (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_daysObject

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_hoursObject

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_minutesObject

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_sObject

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_secondsObject

Converts invl to seconds

invl.to_seconds  => numeric


202
# File 'lib/informix/interval.rb', line 202

def to_seconds; @val end