Cloud Spanner API - Class Google::Cloud::Spanner::Interval (v2.27.0)

Reference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Interval.

Interval

Represents an interval of time by storing the time components in months, days and nanoseconds.

Inherits

  • Object

Example

require "google/cloud/spanner"

iso_8601_string = "P1Y2M3DT4H5M6S"
interval = Google::Cloud::Spanner::Interval::parse iso_8601_string

puts interval # "P1Y2M3DT4H5M6S"

Methods

.from_days

def self.from_days(days) -> Interval

Returns an Interval instance with the given days.

Parameter
  • days (Integer)
Returns

.from_microseconds

def self.from_microseconds(microseconds) -> Interval

Returns an Interval instance with the given microseconds.

Parameter
  • microseconds (Integer)
Returns

.from_milliseconds

def self.from_milliseconds(milliseconds) -> Interval

Returns an Interval instance with the given milliseconds.

Parameter
  • milliseconds (Integer)
Returns

.from_months

def self.from_months(months) -> Interval

Returns an Interval instance with the given months.

Parameter
  • months (Integer)
Returns

.from_nanoseconds

def self.from_nanoseconds(nanoseconds) -> Interval

Returns an Interval instance with the given nanoseconds.

Parameter
  • nanoseconds (Integer)
Returns

.from_seconds

def self.from_seconds(seconds) -> Interval

Returns an Interval instance with the given seconds.

Parameter
  • seconds (Integer)
Returns

.parse

def self.parse(interval_string) -> Google::Cloud::Spanner::Interval

Parses an ISO8601 string and returns an Interval instance.

The accepted format for the ISO8601 standard is: P[n]Y[n]M[n]DT[n]H[n]M[n[.fraction]]S where n represents an integer number.

Parameter
  • interval_string (String) — An ISO8601 formatted string.
Raises
  • (ArgumentError)
Example
require "google/cloud/spanner"

iso_8601_string = "P1Y2M3DT4H5M6S"
interval = Google::Cloud::Spanner::Interval::parse iso_8601_string

puts interval # "P1Y2M3DT4H5M6S"

#==

def ==(other) -> Boolean
Alias Of: #eql?

Standard value equality check for this object.

Parameter
  • other (Object) — An object to compare with.
Returns
  • (Boolean)

#days

def days() -> Integer
Returns
  • (Integer) — The numbers of days in the time interval.

#eql?

def eql?(other) -> Boolean
Aliases

Standard value equality check for this object.

Parameter
  • other (Object) — An object to compare with.
Returns
  • (Boolean)

#hash

def hash() -> Integer

Generate standard hash code for this object.

Returns
  • (Integer)

#months

def months() -> Integer
Returns
  • (Integer) — The numbers of months in the time interval.

#nanoseconds

def nanoseconds() -> Integer
Returns
  • (Integer) — The numbers of nanoseconds in the time interval.

#to_s

def to_s() -> String

Converts the [Interval] to an ISO8601 Standard string.

Returns
  • (String) — The interval's ISO8601 string representation.