{range:intvalues}

Description

Rewrites a dash-separated list of integers into a compact, human-readable run list. It splits intvalues on the dash -, casts each piece to an integer, sorts them ascending, then collapses every run of consecutive integers into a from-to span. Single values are printed alone; the spans and singles are joined with , (comma and space). So 1-4-5-6 becomes 1, 4-6 and 2008-2009-2010-2011 becomes 2008-2011.

Order does not matter: the input is sorted first, so 5-1-2-4-3 still yields 1-5.

Gotchas: input order is ignored but duplicates are not removed — a repeated value breaks a run, so 2020-2020-2021-2022 gives 2020, 2020-2022. A literal 0 is dropped (the splitter discards empty and zero-like pieces), and any non-numeric piece counts as 0 and is likewise dropped. Empty input produces empty output.

The natural source of intvalues is a multi-value field flattened with the {@field:-} getter, for example {range:{@year............:-}}, which turns the years stored on an item into a tidy span.

Parameters

intvalues required

The dash-separated list of integers to collapse. Each piece is cast to an integer, the whole list is sorted ascending, then consecutive integers are merged into from-to spans. Order is not significant; duplicates are kept (a repeat breaks a run); empty and zero-valued pieces are dropped. Commonly fed from a multi-value field via the field getter, e.g. the years on an item.

Examples

test{range:1-2-3-4}
Expected1-4
Actual1-4
Four consecutive integers collapse into a single from-to span.
test{range:1-4-5-6}
Expected1, 4-6
Actual1, 4-6
A lone value and a run combine: 1 stands alone, 4-5-6 becomes 4-6, joined with a comma and space.
test{range:2008-2009-2010-2011}
Expected2008-2011
Actual2008-2011
The canonical use: a contiguous list of years prints as one span.
test{range:5-1-2-4-3}
Expected1-5
Actual1-5
Values are sorted before collapsing, so a shuffled run still yields one span.
test{range:1-2-3-5-7-8-9}
Expected1-3, 5, 7-9
Actual1-3, 5, 7-9
Each gap starts a new group: 1-3, the single 5, then 7-9, comma-separated.
virtual{range:{@year............:-}}
Expected(the item's years as a compact span, e.g. 2019-2021, 2024 - depends on data)
The real-world pattern: flatten a multi-value field with the {@field:-} getter and hand the dash-joined values to range. Replace year............ with your field id. Output depends on the item's data.