LanguageValues and typesStandard typesTime and calendar
CalendarPeriod
On this page
An amount of calendar time in years, months and days: P1Y2M10D.
Use it for "one month from now", where a month is a month however many days it has. For an exact amount of time, use Duration.
Shape
| Field | Type | Required? |
|---|---|---|
years |
Int |
Yes |
months |
Int |
Yes |
days |
Int |
Yes |
Example
CalendarPeriod { years: 1 months: 2 days: 10 }text.parse(raw, as: CalendarPeriod) reads one from text that comes from outside. Text that isn't one at all fails malformed, such as 1 month, P or PT1H.
This operation gives one: temporal.period_between.
Good to know
- Two values are equal only part by part, so one month doesn't equal 30 days, and
<doesn't take them. ==tells you whether two are the same.<andlist.sort_bydon't take it, so sort by one of its parts instead.
In JSON
A string, in a request, a response or json.write:
"P1Y2M10D""P1M""P-1M-3D"
Details
Text form, storage, how it is shown, and operations
CalendarPeriod 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: P1Y2M10D, P1M and P-1M-3D.
How it is stored
It is stored in 3 columns, each named for the field, _ and its suffix. This is P-1M-3D:
| Column | Type | Holds |
|---|---|---|
<field>_years |
integer |
0 |
<field>_months |
integer |
-1 |
<field>_days |
integer |
-3 |
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
P1Y2M10D |
1 year, 2 months, 10 days |
P1M |
1 month |
P-1M-3D |
-1 month, -3 days |
P0D |
0 days |
Operations
temporal.period_between(start: CalendarDate, end: CalendarDate) -> CalendarPeriod: Whole years, months and days fromstarttoend, sostartplus the period isend; each part negative whenendis earlier.
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-calendar-period.md.Built from Jadpo main at aee2e8f.