Declarative constructor: name the timeframe vocabulary tokens in coarsest-
to-finest order. The Cartesian product of their labels becomes the leaf
table; the part of the year a leaf stands for is the product of its
tokens' shares, scaled to year_fraction, and is stated as share,
width and weight (see the section below). A later token is nested in
the earlier ones: the members
of its timeframe are named by the path of labels down to it (m01_h00
for hour h00 of month m01), and those of the last token are the leaf
timeslices.
Convenience shortcut. Names listed in calendar_catalog() build the
catalog design (with coverage_class/regularity metadata attached; the
m12_md* family uses a dedicated ragged month/day builder). Any other
name is parsed as _-joined tokens and dispatched to
calendar_build(). The leading y_ prefix (year-qualified) is
stripped and recorded in meta$year_qualified.
Usage
calendar_build(
...,
name = NULL,
desc = "",
year_start = list(month = 1L, day = 1L),
utc_offset_minutes = 0L,
year_fraction = 1
)
calendar(name, ...)Arguments
- ...
Passed through to
calendar_build()(year_start,utc_offset_minutes,year_fraction,desc).- name
Character scalar — a token-style calendar name (
"d365","d365_h24","m12_h24","q4_h24", ...).- desc
Free-text description.
- year_start
list(month = , day = ); defaults to January 1. A nontrivial anchor makes the model year span[year_start(y), year_start(y + 1)), anchorsYDAY/YEARto it, and rotates the MONTH/QUARTER member order so the anchor month comes first – labels stay Gregorian (m04is April, always).- utc_offset_minutes
Integer minutes; defaults to 0 (UTC). Local time = UTC + offset; e.g.
330Lfor IST (UTC+5:30). Constant offsets only.- year_fraction
Year fraction covered. Defaults to 1.
Share, width and weight of the built calendar
The finest token decides how the length of a leaf timeslice is stated
(see the section of the same name in Calendar).
An hourly token (
h24) gives the timeframeHOUR, whose unit is one hour:shareis one hour of the year (1/8760 of a 365-day year; 1/8784, 1/8736 or 1/8640 for a year of 366, 364 or 360 dated days),widthis 1 andweightis the number of times the hour repeats. After a token of dated days (d365_h24) that is 1. Otherwise the hour is one of an average day and the weight is the days it stands for: 31 form01_h00ofm12_h24, 90 forWIN_h12ofs4_h24.A token of hour types (
hp3) gives the timeframeHOURas well, with timeslices that are blocks of hours, in their order within a day:DAY(h06-h16) is 11 hours wide,PEAK(h17-h20) 4 andNIGHT(h21-h05) 9. The share is one hour and the weight is the days the block stands for (1 ond365_hp3, 90 ons4_hp3).A token of weekdays or day types (
wd7,wk2) has no unit: the share of a timeslice is its own length within a week (one day for a weekday, five days forWORKDAY), the width is 1 and the weight is the number of weeks.Any other finest token (
m12,q4,d365,w52, ...) gives timeslices that are their own unit: the share is the timeslice's own length, width 1, weight 1.
The units stated by tokens are recorded in meta$units (HOUR = 1).
The share of a timeslice of HOUR is one hour in every calendar, and a
calendar that gives it another share is rejected; the hours a timeslice
spans are its width. The hour of the day is read from single hours
(tsl2hour()); it is not defined for a block.
Fiscal calendars
The catalog ships April-start fiscal designs – fy04_m12,
fy04_m12_h24, fy04_q4, fy04_q4_h24, fy04_d365, fy04_d365_h24
– for reporting systems whose year runs April..March (India, Japan).
The model year y spans [y-04-01, y+1-04-01) and the anchored YEAR
is the STARTING Gregorian year (Indian "FY 2021-22" is model year
2021). Labels stay Gregorian (m04 is April, Q2 is Apr-Jun); the
fiscal identity lives in the anchored YEAR/YDAY and the April-first
member order. The entries are defined in UTC like the rest of the
catalog – data already in Indian local time maps as-is, and true-UTC
instants use calendar("fy04_m12", utc_offset_minutes = 330L) (IST).
Other anchors follow the same pattern by argument, e.g.
calendar("m12", year_start = list(month = 7L, day = 1L)).
Examples
cal <- calendar_build("d365", "h24", name = "d365_h24")
cal
#> Calendar: d365_h24
#> Timeframes (2):
#> - YDAY (365) [token: d365, alignment: drop_feb29]
#> - HOUR (8760) [token: h24, unit: 1 h]
#> Leaf timeslices: 8760
#> year_fraction: 1
#> year_start: month=1, day=1
#> utc_offset_minutes: 0
cal2 <- calendar_build("m12", "h24")
cal2
#> Calendar: m12_h24
#> Timeframes (2):
#> - MONTH (12) [token: m12]
#> - HOUR (288) [token: h24, unit: 1 h]
#> Leaf timeslices: 288
#> year_fraction: 1
#> year_start: month=1, day=1
#> utc_offset_minutes: 0
calendar("d365_h24")
#> Calendar: d365_h24
#> Timeframes (2):
#> - YDAY (365) [token: d365, alignment: drop_feb29]
#> - HOUR (8760) [token: h24, unit: 1 h]
#> Leaf timeslices: 8760
#> year_fraction: 1
#> year_start: month=1, day=1
#> utc_offset_minutes: 0
calendar("m12_h24")
#> Calendar: m12_h24
#> Timeframes (2):
#> - MONTH (12) [token: m12]
#> - HOUR (288) [token: h24, unit: 1 h]
#> Leaf timeslices: 288
#> year_fraction: 1
#> year_start: month=1, day=1
#> utc_offset_minutes: 0
