Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • date/delta.rb
  • date/delta/parser.rb

Class/Module Index [+]

Quicksearch

Date::Delta

Public Class Methods

delta_to_dhms(delta) click to toggle source
 
               # File date/delta.rb, line 111
def self.delta_to_dhms(delta)
  fr = delta.imag.abs
  y,   fr = fr.divmod(12)
  m,   fr = fr.divmod(1)

  if delta.imag < 0
    y = -y
    m = -m
  end

  fr = delta.real.abs
  ss,  fr = fr.divmod(SECONDS_IN_DAY) # 4p
  d,   ss = ss.divmod(86400)
  h,   ss = ss.divmod(3600)
  min, s  = ss.divmod(60)

  if delta.real < 0
    d = -d
    h = -h
    min = -min
    s = -s
  end

  return y, m, d, h, min, s, fr
end
            
dhms_to_delta(y, m, d, h, min, s, fr) click to toggle source
 
               # File date/delta.rb, line 137
def self.dhms_to_delta(y, m, d, h, min, s, fr)
  fr = 0 if fr == 0
  Complex(0, y.to_i * 12 + m.to_i) +
    Rational(d * 86400 + h * 3600 + min * 60 + (s + fr), 86400) # 4p
end
            
diff(d1, d2) click to toggle source
 
               # File date/delta.rb, line 185
def self.diff(d1, d2) new(d1.ajd - d2.ajd) end
            
new(delta) click to toggle source
 
               # File date/delta.rb, line 143
def initialize(delta)
  @delta = delta
  @__ca__ = {}
end
            
Also aliased as: new!
new(arg=0, h=0, min=0, s=0) click to toggle source
 
               # File date/delta.rb, line 150
def self.new(arg=0, h=0, min=0, s=0)
  if Hash === arg
    d = Complex(0)
    arg.each do |k, v|
      k = k.to_s.downcase
      unless UNITS4KEY[k]
        raise ArgumentError, "unknown keyword #{k}"
      end
      d += v * UNITS4KEY[k]
    end
  else
    d = dhms_to_delta(0, 0, arg, h, min, s, 0)
  end
  new!(d)
end
            
new!(delta) click to toggle source
Alias for: new
parse(str) click to toggle source
 
               # File date/delta.rb, line 177
def self.parse(str)
  d = begin (@@pa ||= Parser.new).parse(str)
      rescue Racc::ParseError
        raise ArgumentError, 'syntax error'
      end
  new!(d)
end
            

Public Instance Methods

days() click to toggle source
 
               # File date/delta.rb, line 215
def days() dhms[2] end
            
dhms() click to toggle source
 
               # File date/delta.rb, line 205
def dhms() self.class.delta_to_dhms(@delta) end
            
hours() click to toggle source
 
               # File date/delta.rb, line 216
def hours() dhms[3] end
            
mins() click to toggle source
Alias for: minutes
minutes() click to toggle source
 
               # File date/delta.rb, line 217
def minutes() dhms[4] end
            
Also aliased as: mins
months() click to toggle source
 
               # File date/delta.rb, line 214
def months() dhms[1] end
            
nonzero?() click to toggle source
 
               # File date/delta.rb, line 240
def nonzero?() unless zero? then self end
            
sec_fractions() click to toggle source
Alias for: second_fractions
second_fractions() click to toggle source
 
               # File date/delta.rb, line 219
def second_fractions() dhms[6] end
            
Also aliased as: sec_fractions
seconds() click to toggle source
 
               # File date/delta.rb, line 218
def seconds() dhms[5] end
            
Also aliased as: secs
secs() click to toggle source
Alias for: seconds
years() click to toggle source
 
               # File date/delta.rb, line 213
def years() dhms[0] end
            
zero?() click to toggle source
 
               # File date/delta.rb, line 239
def zero?() @delta.zero? end
            

Protected Instance Methods

delta() click to toggle source
 
               # File date/delta.rb, line 209
def delta() @delta end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus