When filtering content by date in a facet, it's often preferable to do so with a relative date such as “last week”, rather than with an absolute date such as “February 1st 2021”. To accommodate relative dates, Headless accepts an alternative string format for date facets.
This format contains 3 parts: <PERIOD>-<AMOUNT>-<UNIT>.
The relative period of time.
pastnownextThe unit of time.
When period is set to now, the unit doesn't have to be defined.
minutehourdayweekmonthquarteryearThe amount of the unit of time.
When period is set to now, the amount doesn't have to be defined.
Examples:
nowpast-2-weeknext-1-yearThe following example code shows how to use the buildDateRange utility to build date ranges.
buildDateRange({
start: {period: 'past', unit: 'week', amount: 2},
end: {period: 'now'},
});
// returns {start: 'past-2-week', end: 'now', endInclusive: false, state: 'idle'}