Module Informix::Interval
In: lib/informix/interval.rb

The Interval module provides shortcuts for creating IntervalYTM and IntervalDTS objects

Methods

Public Class methods

Shortcut to create an IntervalDTS object.

  Interval.day_to_second(days = 0, hours = 0,
                         minutes = 0, seconds = 0)          => interval
  Interval.day_to_second(:days => dd, :hours => hh,
                         :minutes => mm, :seconds => ss)    => interval

  Interval.day_to_second(5, 3)                      # => '5 03:00:00.00000'
  Interval.day_to_second(0, 2, 0, 30)               # => '0 02:00:30.00000'
  Interval.day_to_second(:hours=>2.5)               # => '0 02:30:00.00000'
  Interval.day_to_second(:seconds=>Rational(151,10))# => '0 00:00:15.10000'
  Interval.day_to_second(:seconds=> 20.13)          # => '0 00:00:20.13000'
  Interval.day_to_second(:days=>1.5, :hours=>2)     # => '1 14:00:00.00000'

[Source]

     # File lib/informix/interval.rb, line 255
255:     def self.day_to_second(*args)
256:       if args.size == 1 && Hash === args[0]
257:         h = args[0]
258:         days, hours, minutes, seconds = h[:days], h[:hours], h[:minutes],
259:                                         h[:seconds]
260:       elsif args.size <= 5 && args.all? {|e| Numeric === e || e.nil? }
261:         days, hours, minutes, seconds = args
262:       else
263:         raise TypeError, "Expected Numerics or a Hash"
264:       end
265:       days ||= 0; hours ||= 0; minutes ||= 0; seconds ||= 0
266:       if ![days, hours, minutes, seconds].all? {|e| Numeric === e && e >= 0 }
267:         raise ArgumentError, "Expected Numerics >= 0"
268:       end
269:       from_seconds(days*24*60*60 + hours*60*60 + minutes*60 + seconds)
270:     end

Shortcut to create an IntervalYTM object.

  Interval.from_months(3)   #=>  '0-03'
  Interval.from_months(71)  #=>  '5-11'

[Source]

     # File lib/informix/interval.rb, line 238
238:     def self.from_months(months)
239:       IntervalYTM.new(months)
240:     end

Shortcut to create an IntervalDTS object.

  Interval.from_seconds(9000)               #=> '0 02:30:00.00000'
  Interval.from_seconds(Rational(151, 10))  #=> '0 00:00:15.10000'

[Source]

     # File lib/informix/interval.rb, line 276
276:     def self.from_seconds(seconds)
277:       IntervalDTS.new(seconds)
278:     end

Shortcut to create an IntervalYTM object.

  Interval.year_to_month(years = 0, months = 0)       =>  interval
  Interval.year_to_month(:years => yy, :months => mm) =>  interval

  Interval.year_to_month(5)                           #=>  '5-00'
  Interval.year_to_month(0, 3)                        #=>  '0-03'
  Interval.year_to_month(5, 3)                        #=>  '5-03'
  Interval.year_to_month(:years => 5.5)               #=>  '5-06'
  Interval.year_to_month(:months => 3)                #=>  '0-03'
  Interval.year_to_month(:years => 5.5, :months => 5) #=>  '5-11'

[Source]

     # File lib/informix/interval.rb, line 219
219:     def self.year_to_month(*args)
220:       if args.size == 1 && Hash === args[0]
221:         years, months = args[0][:years], args[0][:months]
222:       elsif args.size <= 2 && args.all? {|e| Numeric === e }
223:         years, months = args
224:       else
225:         raise TypeError, "Expected Numerics or a Hash"
226:       end
227:       years ||= 0; months ||= 0
228:       if ![years, months].all? {|e| Numeric === e && e >= 0 }
229:         raise ArgumentError, "Expected Numerics >= 0"
230:       end
231:       from_months(years*12 + months.to_i)
232:     end

[Validate]