Skip to content

Commit

Permalink
Drop unnecessary touch in EoTime#inc
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Dec 4, 2024
1 parent b758c91 commit c53cbf1
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions lib/et-orbi/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,38 +316,32 @@ def to_time_s

def inc(t, dir=1)

r =
case t
when ::Time, ::EtOrbi::EoTime
case t
when ::Time, ::EtOrbi::EoTime

fail ArgumentError.new(
"Cannot add #{t.class} to EoTime instance"
) if dir > 0
fail(
ArgumentError.new("Cannot add #{t.class} to EoTime instance")
) if dir > 0

@seconds + dir * t.to_f
@seconds + dir * t.to_f

when String
when String

false
false

else
else

if t.respond_to?(:to_f)
nt = self.dup; nt.seconds += dir * t.to_f; nt
elsif t.respond_to?(:to_i)
nt = self.dup; nt.seconds += dir * t.to_i; nt
else
false
end
if t.respond_to?(:to_f)
nt = self.dup; nt.seconds += dir * t.to_f; nt
elsif t.respond_to?(:to_i)
nt = self.dup; nt.seconds += dir * t.to_i; nt
else
false
end

fail ArgumentError.new(
"Cannot call add or subtract #{t.class} on EoTime instance"
) unless r

touch

r
end || fail(
ArgumentError.new(
"Cannot call add or subtract #{t.class} on EoTime instance"))
end

def localtime(zone=nil)
Expand Down

0 comments on commit c53cbf1

Please sign in to comment.