Returns an error code if this Interval is invalid, or null if the Interval is valid
Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
Returns the count of minutes, hours, days, months, or years included in the Interval, even in part. Unlike length this counts sections of the calendar, not periods of time, e.g. specifying 'day' asks 'what dates are included in this interval?', not 'how many days long is this interval?'
Optional
unit: keyof DurationObject = "milliseconds"the unit of time to count.
Returns whether this Interval's start and end are both in the same unit of time
the unit of time to check sameness on
Return an Interval representing the intersection of this Interval and the specified Interval. Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals. Returns null if the intersection is empty, meaning, the intervals don't intersect.
Returns the length of the Interval in the specified unit.
Optional
unit: keyof DurationObject = "milliseconds"the unit (such as 'hours' or 'days') to return the length in.
Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes
Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC())
Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 }))
"Sets" the start and/or end dates. Returns a newly-constructed Interval.
the values to set
Return a Duration representing the time spanned by this interval.
Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }
Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }
Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 }
Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }
Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }
Optional
unit: keyof DurationObject | (keyof DurationObject)[] = "milliseconds"the unit or units (such as 'hours' or 'days') to include in the duration.
options that affect the creation of the Duration
Returns a string representation of this Interval formatted according to the specified format string.
the format string. This string formats the start and end time. See toFormat for details.
options
Returns an ISO 8601-compliant string representation of this Interval.
https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
The same options as toISO
Returns an ISO 8601-compliant string representation of date of this Interval. The time components are ignored.
https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
Returns an ISO 8601-compliant string representation of time of this Interval. The date components are ignored.
https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
The same options as toISO
Static
afterStatic
beforeStatic
fromStatic
fromISOCreate an Interval from an ISO 8601 string.
Accepts <start>/<end>
, <start>/<duration>
, and <duration>/<end>
formats.
https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
the ISO string to parse
Optional
opts: DateTimeOptions = {}Static
invalidCreate an invalid Interval.
simple string of why this Interval is invalid. Should not contain parameters or anything else data-dependent
Optional
explanation: stringlonger explanation, may include parameters and other useful debugging information
Static
isStatic
mergeStatic
xorGenerated using TypeDoc
An Interval object represents a half-open interval of time, where each endpoint is a DateTime. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.
Here is a brief overview of the most commonly used methods and getters in Interval: