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

2.36.0 (latest) 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.0 2.24.0 2.23.0 2.22.0 2.21.0 2.20.0 2.19.1 2.18.1 2.17.0 2.16.1 2.15.0 2.14.0 2.13.0 2.12.1 2.11.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

```ruby
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**

- ([Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))

### .from_microseconds

    def self.from_microseconds(microseconds) -> Interval

Returns an Interval instance with the given microseconds.
**Parameter**

- **microseconds** (Integer)
**Returns**

- ([Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))

### .from_milliseconds

    def self.from_milliseconds(milliseconds) -> Interval

Returns an Interval instance with the given milliseconds.
**Parameter**

- **milliseconds** (Integer)
**Returns**

- ([Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))

### .from_months

    def self.from_months(months) -> Interval

Returns an Interval instance with the given months.
**Parameter**

- **months** (Integer)
**Returns**

- ([Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))

### .from_nanoseconds

    def self.from_nanoseconds(nanoseconds) -> Interval

Returns an Interval instance with the given nanoseconds.
**Parameter**

- **nanoseconds** (Integer)
**Returns**

- ([Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))

### .from_seconds

    def self.from_seconds(seconds) -> Interval

Returns an Interval instance with the given seconds.
**Parameter**

- **seconds** (Integer)
**Returns**

- ([Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))

### .parse

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

Parses an ISO8601 string and returns an Interval instance.


<br />

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.
**Returns**

- ([Google::Cloud::Spanner::Interval](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval))
**Raises**

- (ArgumentError)
**Example**

```ruby
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?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval#Google__Cloud__Spanner__Interval_eql?_instance_) 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**

- [#==](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Interval#Google__Cloud__Spanner__Interval_==_instance_)
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.