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

The IntervalYTM class is an Interval class dedicated only to represent intervals in the scope YEAR TO MONTH.

Methods

+   new   to_months   to_s   to_years  

Attributes

months  [R] 
years  [R] 

Public Class methods

Creates an IntervalYTM object with val as value.

  IntervalYTM.new(val)  =>  interval

[Source]

     # File lib/informix/interval.rb, line 106
106:     def initialize(val)
107:       super
108:       @val = val.to_i
109:       @years, @months = @val.abs.divmod 12
110:       if @val < 0
111:         @years = -@years
112:         @months = -@months
113:       end
114:       @fields = [ @years, @months ]
115:     end

Public Instance methods

interval + date => date interval + datetime => datetime

[Source]

     # File lib/informix/interval.rb, line 119
119:     def +(obj)
120:       case obj
121:       when Date, DateTime
122:         obj >> @val
123:       else
124:         super
125:       end
126:     end

Converts invl to months

  invl.to_months  => numeric

[Source]

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

Returns an ANSI SQL standards compliant string representation

  invl.to_s   => string

[Source]

     # File lib/informix/interval.rb, line 131
131:     def to_s; "%d-%02d" % [@years, @months.abs] end

Converts a invl to years

  invl.to_years  => numeric

[Source]

     # File lib/informix/interval.rb, line 136
136:     def to_years; Rational === @val ? @val/12 : @val/12.0 end

[Validate]