Time::Span -

# struct Time::Span

- Time::Span
- Struct
- Value
- Object

## 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(10, 10, 10)          # => 10:10:10
    Time::Span.new(10, 10, 10, 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(20, 10, 10)
    span.hours   # => 20
    span.minutes # => 10
    span.seconds # => 10

Calculation:

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

## Included Modules

- Comparable(Time::Span)

## Defined in:

## Constant Summary

MAX = `new(seconds: Int64::MAX, nanoseconds: 999999999)`
MIN = `new(seconds: Int64::MIN, nanoseconds: -999999999)`
ZERO = `new(nanoseconds: 0)`

## Constructors

- .new(days : Int, hours : Int, minutes : Int, seconds : Int, nanoseconds : Int = 0)
- .new(hours : Int, minutes : Int, seconds : Int)
- .new(*, seconds : Int, nanoseconds : Int)
- .new(*, nanoseconds : Int)

## Class Method Summary

- .zero : Time::Span

## Instance Method Summary

- #*(number : Float) : Time::Span

  Returns a `Time::Span` that is number times longer.

- #*(number : Int) : Time::Span

  Returns a `Time::Span` that is number times longer.

- #+ : self
- #+(other : self) : Time::Span
- #- : Time::Span
- #-(other : self) : Time::Span
- #/(other : self) : Float64
- #/(number : Float) : Time::Span

  Returns a `Time::Span` that is divided by number.

- #/(number : Int) : Time::Span

  Returns a `Time::Span` that is divided by number.

- #<=>(other : self)
- #abs : Time::Span

  Returns the absolute (non-negative) amount of time this `Time::Span` represents by removing the sign.

- #ago : Time

  Returns a `Time` that happens earlier by `self` than the current time.

- #days : Int64

  Returns the number of full days in this time span.

- #duration : Time::Span

  Alias of `#abs`.

- #from_now : Time

  Returns a `Time` that happens later by `self` than the current time.

- #hours : Int32

  Returns the number of full hours of the day (`0..23`) in this time span.

- #inspect(io : IO) : Nil
- #microseconds : Int32

  Returns the number of microseconds of the second (`0..999999`) in this time span.

- #milliseconds : Int32

  Returns the number of milliseconds of the second (`0..999`) in this time span.

- #minutes : Int32

  Returns the number of full minutes of the hour (`0..59`) in this time span.

- #nanoseconds : Int32

  Returns the number of nanoseconds of the second (`0..999_999_999`) in this time span.

- #seconds : Int32

  Returns the number of full seconds of the minute (`0..59`) in this time span.

- #to_f : Float64

  Alias of `#total_seconds`.

- #to_i : Int64

  Returns the number of full seconds.

- #total_days : Float64

  Converts to a (possibly fractional) number of days.

- #total_hours : Float64

  Converts to a (possibly fractional) number of hours.

- #total_milliseconds : Float64

  Converts to a number of milliseconds.

- #total_minutes : Float64

  Converts to a (possibly fractional) number of minutes.

- #total_nanoseconds : Float64

  Converts to a number of nanoseconds.

- #total_seconds : Float64

  Converts to a (possibly fractional) number of seconds.

- #total_weeks : Float64

  Converts to a (possibly fractional) number of weeks.

- #zero? : Bool

### Instance methods inherited from module `Comparable(Time::Span)`

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(other : T) >=

### Instance methods inherited from struct `Struct`

==(other) : Bool ==, hash(hasher) hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io : IO) : Nil to_s

### Instance methods inherited from struct `Value`

==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup

### Instance methods inherited from class `Object`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash(hasher)
hash hash, inspect(io : IO) : Nil
inspect : String inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") to_pretty_json, to_s : String
to_s(io : IO) : Nil to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try, unsafe_as(type : T.class) forall T unsafe_as

### Constructor methods inherited from class `Object`

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self from_json, from_yaml(string_or_io : String | IO) : self from_yaml

## Constructor Detail

def self.new(days : Int, hours : Int, minutes : Int, seconds : Int, nanoseconds : Int = 0) #
def self.new(hours : Int, minutes : Int, seconds : Int) #
def self.new(*, seconds : Int, nanoseconds : Int) #
def self.new(*, nanoseconds : Int) #

## Class Method Detail

def self.zero : Time::Span #

## Instance Method Detail

def *(number : Float) : Time::Span #

Returns a `Time::Span` that is number times longer.

def *(number : Int) : Time::Span #

Returns a `Time::Span` that is number times longer.

def + : self #
def +(other : self) : Time::Span #
def - : Time::Span #
def -(other : self) : Time::Span #
def /(other : self) : Float64 #
def /(number : Float) : Time::Span #

Returns a `Time::Span` that is divided by number.

def /(number : Int) : Time::Span #

Returns a `Time::Span` that is divided by number.

def <=>(other : self) #
def abs : Time::Span #

Returns the absolute (non-negative) amount of time this `Time::Span` represents by removing the sign.

def ago : Time #

Returns a `Time` that happens earlier by `self` than the current time.

def days : Int64 #

Returns the number of full days in this time span.

    (5.days + 25.hours).days # => 6_i64

def duration : Time::Span #

Alias of `#abs`.

def from_now : Time #

Returns a `Time` that happens later by `self` than the current time.

def hours : Int32 #

Returns the number of full hours of the day (`0..23`) in this time span.

def inspect(io : IO) : Nil #
def microseconds : Int32 #

Returns the number of microseconds of the second (`0..999999`) in this time span.

def milliseconds : Int32 #

Returns the number of milliseconds of the second (`0..999`) in this time span.

def minutes : Int32 #

Returns the number of full minutes of the hour (`0..59`) in this time span.

def nanoseconds : Int32 #

Returns the number of nanoseconds of the second (`0..999_999_999`) in this time span.

def seconds : Int32 #

Returns the number of full seconds of the minute (`0..59`) in this time span.

def to_f : Float64 #

Alias of `#total_seconds`.

def to_i : Int64 #

Returns the number of full seconds.

def total_days : Float64 #

Converts to a (possibly fractional) number of days.

    (36.hours).total_days # => 1.5

def total_hours : Float64 #

Converts to a (possibly fractional) number of hours.

def total_milliseconds : Float64 #

Converts to a number of milliseconds.

def total_minutes : Float64 #

Converts to a (possibly fractional) number of minutes.

def total_nanoseconds : Float64 #

Converts to a number of nanoseconds.

def total_seconds : Float64 #

Converts to a (possibly fractional) number of seconds.

def total_weeks : Float64 #

Converts to a (possibly fractional) number of weeks.

    (4.weeks + 5.days + 6.hours).total_weeks # => 4.75

def zero? : Bool #