Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return early in Time#add_span if arguments are zero #5787

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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