Skip to content

Commit

Permalink
Return early in Time#add_span if arguments are zero (crystal-lang#5787)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and RX14 committed Mar 8, 2018
1 parent 9d2dfbb commit 224d489
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,13 @@ struct Time
end

# Returns a `Time` that is this number of *seconds* and *nanoseconds* later.
#
# Negative values are subtracted, meaning an earlier point in time.
def add_span(seconds : Int, nanoseconds : Int) : Time
if seconds == 0 && nanoseconds == 0
return self
end

seconds = total_seconds + seconds
nanoseconds = self.nanosecond.to_i64 + nanoseconds

Expand Down

0 comments on commit 224d489

Please sign in to comment.