The goog.date.Interval Class

goog.date.Interval(opt_years, opt_months, opt_days, opt_hours, opt_minutes, opt_seconds)

Class representing a date/time interval. Used for date calculations.

 new goog.date.Interval(0, 1) // One month
 new goog.date.Interval(0, 0, 3, 1) // Three days and one hour
 new goog.date.Interval(goog.date.Interval.DAYS, 1) // One day
 
opt_years {number|string=}
Years or string representing date part.
opt_months {number=}
Months or number of whatever date part specified by first parameter.
opt_days {number=}
Days.
opt_hours {number=}
Hours.
opt_minutes {number=}
Minutes.
opt_seconds {number=}
Seconds.

.DAYS {string}

Days constant for the date parts.

.HOURS {string}

Hours constant for the date parts.

.MINUTES {string}

Minutes constant for the date parts.

.MONTHS {string}

Months constant for the date parts.

.SECONDS {string}

Seconds constant for the date parts.

.YEARS {string}

Years constant for the date parts.

.add(interval)

Adds the Interval in the argument to this Interval field by field.

interval {goog.date.Interval}
The Interval to add.

.clone()

returns {!goog.date.Interval}
A clone of the interval object.

.equals(other)

Tests whether the given interval is equal to this interval. Note, this is a simple field-by-field comparison, it doesn't account for comparisons like "12 months == 1 year".

other {goog.date.Interval}
The interval to test.
returns {boolean}
Whether the intervals are equal.

.fromIsoString(duration)

Parses an XML Schema duration (ISO 8601 extended).

duration {string}
An XML schema duration in textual format. Recurring durations and weeks are not supported.
returns {goog.date.Interval}
The duration as a goog.date.Interval or null if the parse fails.
@see
http://www.w3.org/TR/xmlschema-2/#duration

.getInverse()

returns {!goog.date.Interval}
Negative of this interval.

.getTotalSeconds()

Gets the total number of seconds in the time interval. Assumes that months and years are empty.

returns {number}
Total number of seconds in the interval.

.isZero()

returns {boolean}
Whether all fields of the interval are zero.

.times(n)

Calculates n * (this interval) by memberwise multiplication.

n {number}
An integer.
returns {!goog.date.Interval}
n * this.

.toIsoString(opt_verbose)

Serializes goog.date.Interval into XML Schema duration (ISO 8601 extended).

opt_verbose {boolean=}
Include zero fields in the duration string.
returns {?string}
An XML schema duration in ISO 8601 extended format, or null if the interval contains both positive and negative fields.
@see
http://www.w3.org/TR/xmlschema-2/#duration