Skip to content
Merged
Changes from 1 commit
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
17 changes: 14 additions & 3 deletions src/time/span.cr
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,21 @@ struct Time::Span
end

# Returns a `Time::Span` that is *number* times longer.
def *(number : Number) : Time::Span
def *(number : Int) : Time::Span
# TODO check overflow
Span.new(
seconds: to_i.to_i64 * number,
seconds: to_i * number,
nanoseconds: nanoseconds.to_i64 * number,
)
end

def /(number : Number) : Time::Span
# Returns a `Time::Span` that is *number* times longer.
def *(number : Float) : Time::Span
(total_nanoseconds * number).nanoseconds
end

# Return a `Time::Span` that is divided by *number*.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nice catch.

def /(number : Int) : Time::Span
seconds = to_i.tdiv(number)
nanoseconds = self.nanoseconds.tdiv(number)

Expand All @@ -313,6 +319,11 @@ struct Time::Span
)
end

# Returns a `Time::Span` that is divided by *number*.
def /(number : Float) : Time::Span
(total_nanoseconds / number).nanoseconds
end

def /(other : self) : Float64
total_nanoseconds.to_f64 / other.total_nanoseconds.to_f64
end
Expand Down