struct Time::Span

Overview

Time::Span represents one period of time.

A Time::Span initializes with the specified period. Different numbers of arguments generate a Time::Span in different length. Check all #new methods for details.

Time::Span.new(nanoseconds: 10_000)                           # => 00:00:00.000010000
Time::Span.new(hours: 10, minutes: 10, seconds: 10)           # => 10:10:10
Time::Span.new(days: 10, hours: 10, minutes: 10, seconds: 10) # => 10.10:10:10

Calculation between Time also returns a Time::Span.

span = Time.utc(2015, 10, 10) - Time.utc(2015, 9, 10)
span       # => 30.00:00:00
span.class # => Time::Span

Inspection:

span = Time::Span.new(hours: 20, minutes: 10, seconds: 10)
span.hours   # => 20
span.minutes # => 10
span.seconds # => 10

Calculation:

a = Time::Span.new(hours: 20, minutes: 10, seconds: 10)
b = Time::Span.new(hours: 10, minutes: 10, seconds: 10)
c = a - b # => 10:00:00
c.hours   # => 10

Included Modules

Defined in:

trashman/annotations.cr