lib/fugit/duration.rb in fugit-0.9.6 vs lib/fugit/duration.rb in fugit-1.0.0
- old
+ new
@@ -95,13 +95,13 @@
s.string
end
class << self
- def to_plain_s(o); do_parse(o).to_plain_s; end
- def to_iso_s(o); do_parse(o).to_iso_s; end
- def to_long_s(o, opts={}); do_parse(o).to_long_s(opts); end
+ def to_plain_s(o); do_parse(o).deflate.to_plain_s; end
+ def to_iso_s(o); do_parse(o).deflate.to_iso_s; end
+ def to_long_s(o, opts={}); do_parse(o).deflate.to_long_s(opts); end
end
# Warning: this is an "approximation", months are 30 days and years are
# 365 days, ...
#
@@ -168,10 +168,12 @@
self.class.allocate.init(nil, h)
end
def add_to_time(t)
+ t = ::EtOrbi.make_time(t)
+
INFLA_KEYS.each do |k, a|
v = @h[k]; next unless v
t = t + v * a[:s]
@@ -190,38 +192,38 @@
elsif at[1] < 1
n, m = -at[1] / 12, -at[1] % 12
at[0], at[1] = at[0] - n, m
end
- t = Time.send(t.utc? ? :utc : :local, *at)
+ t = ::EtOrbi.make_time(at, t.zone)
end
t
end
def add(a)
case a
- when Numeric then add_numeric(a)
- when Fugit::Duration then add_duration(a)
- when String then add_duration(self.class.parse(a))
- when Time then add_to_time(a)
- else fail ArgumentError.new(
- "cannot add #{a.class} instance to a Fugit::Duration")
+ when Numeric then add_numeric(a)
+ when Fugit::Duration then add_duration(a)
+ when String then add_duration(self.class.parse(a))
+ when ::Time, EtOrbi::EoTime then add_to_time(a)
+ else fail ArgumentError.new(
+ "cannot add #{a.class} instance to a Fugit::Duration")
end
end
alias + add
def substract(a)
case a
- when Numeric then add_numeric(-a)
- when Fugit::Duration then add_duration(-a)
- when String then add_duration(-self.class.parse(a))
- when Time then opposite.add_to_time(a)
- else fail ArgumentError.new(
- "cannot substract #{a.class} instance to a Fugit::Duration")
+ when Numeric then add_numeric(-a)
+ when Fugit::Duration then add_duration(-a)
+ when String then add_duration(-self.class.parse(a))
+ when ::Time, ::EtOrbi::EoTime then add_to_time(a)
+ else fail ArgumentError.new(
+ "cannot substract #{a.class} instance to a Fugit::Duration")
end
end
alias - substract
def ==(o)
@@ -233,10 +235,10 @@
def hash
@h.hash
end
- def next_time(from=Time.now)
+ def next_time(from=::EtOrbi::EoTime.now)
add(from)
end
protected