LanguageValues and typesStandard typesTime and calendar
Duration
On this page
An exact length of time, to the millisecond: 90 minutes is PT1H30M.
Use it for timeouts and gaps between two instants. For a month, which has no fixed length, use CalendarPeriod.
Shape
One value, with no fields to fill in. As text it reads PT26H.
Example
Duration(90m)text.parse(raw, as: Duration) reads one from text that comes from outside. Text that isn't one at all fails malformed, such as 5 minutes, P or PT.
This operation gives one: temporal.between.
Good to know
- In code, write a unit after the number:
500ms,30s,90m,2h,14d.mis minutes, not metres. temporal.betweengives the one between two instants.==tells you whether two are the same, and<andlist.sort_bycompare and sort them.
In JSON
A string, in a request, a response or json.write:
"PT5M""PT1H30M""PT26H"
Details
Text form, storage, how it is shown, and operations
Duration is in the group Time and calendar, 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: PT5M, PT1H30M and PT26H.
How it is stored
It is stored in one column named for the field, of type bigint. PT1H30M is stored as 5400000.
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
PT5M |
5 minutes |
PT1H30M |
1 hour, 30 minutes |
PT26H |
1 day, 2 hours |
Operations
temporal.between(start: Instant, end: Instant) -> Duration: How long fromstarttoend:end - start.
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-duration.md.Built from Jadpo main at aee2e8f.