struct Time::Span

Overview

Time::Span represents one period of time.

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

Time::Span.new(10000)          # => 00:00:00.001
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.new(2015, 10, 10) - Time.new(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

Defined in:

time/span.cr

Constant Summary

MaxValue = new(Int64::MAX)
MinValue = new(Int64::MIN)
TicksPerDay = TicksPerHour * 24
TicksPerHour = TicksPerMinute * 60
TicksPerMillisecond = 10000_i64
TicksPerMinute = TicksPerSecond * 60
TicksPerSecond = TicksPerMillisecond * 1000
Zero = new(0)

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Comparable(self)

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

Instance methods inherited from struct Struct

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

Instance methods inherited from struct Value

==(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 hash, inspect(io : IO)
inspect
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
to_s(io : IO)
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) : self from_yaml

Constructor Detail

def self.from(value, tick_multiplicator) : self #

View source
def self.new(days, hours, minutes, seconds, milliseconds) #

View source
def self.new(days, hours, minutes, seconds) #

View source
def self.new(hours, minutes, seconds) #

View source
def self.new(ticks) #

View source

Class Method Detail

def self.zero #

View source

Instance Method Detail

def *(number : Number) #

View source
def +(other : self) #

View source
def + #

View source
def -(other : self) #

View source
def - #

View source
def /(number : Number) #

View source
def /(other : self) #

View source
def <=>(other : self) #

View source
def abs #

View source
def ago #

View source
def days #

View source
def duration #

View source
def from_now #

View source
def hours #

View source
def inspect(io : IO) #

View source
def milliseconds #

View source
def minutes #

View source
def seconds #

View source
def ticks : Int64 #

View source
def to_f #

View source
def to_i #

View source
def total_days #

View source
def total_hours #

View source
def total_milliseconds #

View source
def total_minutes #

View source
def total_seconds #

View source
def total_weeks #

View source
def zero? #

View source