LanguageValues and typesStandard typesMaths and data
Range
On this page
The values of one ordered type from a start up to, but not including, an end.
Use it for spans of your own type, such as a price band, and name the type inside it: Range<Grams>. For days, use DateRange. For moments, use InstantRange.
Shape
| Field | Type | Required? |
|---|---|---|
start |
T |
No |
end |
T |
No |
Write every field when you build one, and give a field that isn't required as none.
Its parts keep these rules, and a value that breaks one fails with the rule's name:
start_not_after_end: start <= end
Example
var example: Range<CalendarDate> = Range { start: "2026-10-01" end: none }assert range.contains(example, CalendarDate("2026-10-25"))
text.parse(raw, as: Range<CalendarDate>) reads one from text that comes from outside. Text that isn't one at all fails malformed, such as 2026-10-01, 2026-11-01/2026-10-01 or 2026-10-01/tomorrow.
This operation gives one: range.intersection.
Good to know
- Give
nonefor an end with no limit, so the example runs from 1 October onwards. range.contains,range.overlapsandrange.intersectionwork on it.==tells you whether two are the same.<andlist.sort_bydon't take it, so sort by one of its parts instead.
In JSON
An object of its parts, in a request, a response or json.write:
{"start":"2026-10-01","end":"2026-11-01"}{"start":"2026-10-01","end":null}{"start":null,"end":"2026-11-01"}
When you read one, a field that isn't required may be left out, or sent as null.
Details
Text form, storage, how it is shown, and operations
Range is in the group Maths and data, and has been in Jadpo since 0.1.0.
Text form
text.from writes one standard text form, the same form text.parse reads back: 2026-10-01/2026-11-01, 2026-10-01/.. and ../2026-11-01.
How it is stored
It is stored in one column named for the field, of type daterange. ../2026-11-01 is stored as daterange(NULL::date, '2026-11-01'::date, '[)').
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb and format: TimeFormat.date_medium:
| Value | Shown |
|---|---|
2026-10-01/2026-11-01 |
1 Oct 2026 – 1 Nov 2026 |
2026-10-01/.. |
1 Oct 2026 – … |
../2026-11-01 |
… – 1 Nov 2026 |
../.. |
… – … |
Operations
range.contains(range: Range<T>, value: T) -> Bool: Whethervalueis insiderange.range.intersection(a: Range<T>, b: Range<T>) -> Range<T>?: The partaandbshare;nonewhen they don't overlap.range.overlaps(a: Range<T>, b: Range<T>) -> Bool: Whetheraandbshare at least one value.
It also takes text.parse, text.from, text.format, json.read, json.write and ==. How every standard type behaves says how they work.
Markdown for agents: /docs/types/type-range.md.Built from Jadpo main at aee2e8f.