# 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
# 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
# File date/delta.rb, line 185
def self.diff(d1, d2) new(d1.ajd - d2.ajd) end
# File date/delta.rb, line 143
def initialize(delta)
@delta = delta
@__ca__ = {}
end
# 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
# File date/delta.rb, line 205
def dhms() self.class.delta_to_dhms(@delta) end
# File date/delta.rb, line 217
def minutes() dhms[4] end
# File date/delta.rb, line 240
def nonzero?() unless zero? then self end
# File date/delta.rb, line 219
def second_fractions() dhms[6] end
# File date/delta.rb, line 218
def seconds() dhms[5] 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 see Improve the docs, or visit Documenting-ruby.org.