Create ranges from existing points with to() and range(), or parse endpoints and interval strings with standalone factories on dateRange(). Every range instance is immutable.
Inclusive dates vs half-open clocks
Calendar date ranges include their final day, because September 1 through September 7 means all seven days. Moment and clock ranges exclude their end so back-to-back slots meet without overlapping.
DateRange
new DateRange(start, end, options?)new DateRange(interval, options?)
Spans two calendar dates and includes both endpoints. Passing an end date earlier than the start date throws a RangeError.
new DateTimeRange(start, end, options?)new DateTimeRange(interval, options?)
Spans two moments, including start and excluding end. When the end input carries no explicit time zone, it is read in the start moment’s zone, and backwards endpoints throw a RangeError.
new TimeRange(start, end, options?)new TimeRange(interval, options?)
Spans two times of day, including start and excluding end. When the end time is earlier on the clock than the start time, the range wraps across midnight to model overnight hours.
import { time, timeRange } from 'native-dates';const dayShift = time('9:00am').to('5:00pm');const nightShift = timeRange('22:00', '06:00');dayShift.duration.hours; // 8nightShift.duration.hours; // 8
Properties
Every range exposes its formatted label, typed endpoints, kind tag, and measured length.
Property
Type
Description
text
string
Locale-formatted range string, such as 'Sep 1 – 7, 2026'.
start, end
CalendarDate | DateTime | Time
Start and end points matching the range class.
kind
'date' | 'datetime' | 'time'
Tag naming which kind of points the range holds.
duration
Duration
Full length anchored at start, counting the last day on date ranges and crossing midnight on overnight clock ranges.
Builds a range from this point to an end point or across a duration. On a calendar date, passing a length of 7 days lands six days after start because both endpoints are included.
Parameters
endPoint | DurationInput | numberrequired
Target endpoint of the same kind, duration input, or numeric count paired with unit.
unitUnit
Unit name when the first argument is a numeric count.
Returns
DateRange | DateTimeRange | TimeRange
A range matching the receiver's kind.
import { date, datetime, time } from 'native-dates';date('2026-09-01').to(7, 'days').toString(); // '2026-09-01/2026-09-07'datetime('2026-09-01T09:00Z', 'UTC').to(90, 'minutes').toString(); // '2026-09-01T09:00:00.000Z/2026-09-01T10:30:00.000Z'time('9:00am').to('5:00pm').toString(); // '09:00:00/17:00:00'
Returns the full calendar or clock unit enclosing a date or moment. Date ranges span the first through last day of the unit, while moment ranges span from the unit’s start until the start of the next unit.
Parameters
unitUnitrequired
Enclosing unit such as 'week', 'month', or 'day'.
firstDayWeekday
First day of the week when unit is 'week', overriding configure().
Checks whether a point or another range of the same kind lies inside this range. Date ranges include end, moment and clock ranges exclude it, and overnight clock ranges match times on either side of midnight.
Returns true when two ranges of the same kind share at least one day or instant. Back-to-back moment or clock slots where the first ends at the second’s start do not overlap.
Parameters
otherRange | stringrequired
Range instance or interval string of the same kind.
Returns a new range covering only the span shared by both ranges, or null when they are disjoint. Two overnight clock ranges that cross in two separate pieces throw a RangeError.
Parameters
otherRange | stringrequired
Range instance or interval string of the same kind.
Returns
DateRange | DateTimeRange | TimeRange | null
Overlapping range of the same kind, or null when disjoint.
const a = dateRange('2026-09-01', '2026-09-10');const b = dateRange('2026-09-05', '2026-09-15');a.intersection(b)?.toString(); // '2026-09-05/2026-09-10'a.intersection('2026-09-20/2026-09-25'); // null
equals()
range.equals(other): boolean
Returns true when both ranges have equal start and end points. Arrays of ranges also sort chronologically with compare().
Returns true when a moment or clock range has identical start and end points. Always returns false on a DateRange because a single calendar date spans one full day.
Walks forward from start by a positive unit or duration and returns every point inside the range. Steps count out from the starting point rather than chaining additions, so stepping monthly from January 31 lands on each month’s final day.
Parameters
stepUnit | DurationInput | numberrequired
Unit name such as 'day', duration input, or numeric count paired with unit.
Divides the range into contiguous sub-ranges of the given step size, clamping the final chunk to the range’s end. Accepts the same step arguments as points().
Converts a DateRange into a half-open DateTimeRange from midnight on the start day until midnight after the final day, matching timestamp query bounds. On a moment range, shifts both endpoints into the target time zone.
Calling in() on a clock range throws a RangeError because times of day have no calendar date.
Parameters
zoneZone
Target IANA zone, fixed offset, or 'UTC'. Defaults to the configured zone on DateRange.
Formats the range with localized Intl range formatting for presets and options objects, collapsing shared dates or months automatically. Token patterns like 'YYYY-MM-DD' format each endpoint with the pattern and join them with ' – '.
Returns the ISO 8601 interval string 'start/end', which parses back directly in the range factories. toJSON() returns the same string for JSON serialization.