Tinderbox v10 Icon

Sorting Date-type data

For detail on sorting a view using Date-types via Sort-group attributes, see Sorting Dates.

Sorting (lists) in action code requires knowing the differing implications of lexical vs. numerical sorting. If not familiar, read that article to better understand the rest of this article. The relevant issue is the two sort types sort the "never" Date-type value differently:

Does this list position matter?

No—except if we make assumptions that the "never" value is always in the same position. As, it turns out, it may be sorted first or last, some care is needed when working with sorted date lists.

Sort operators

A small number of action code operators perform sorts explicitly. That is their primary function, sorting lists (List and Sets:

Sets: Self-sorting lists

Be aware to that when placing Date-type data in a list, date is stored in a textual (string) for. The two attribute types behave differently:

List-creating operators

The collect(), collect_if(), and list() all return List-type content. The data is normally list of notes (as $Name/$Path/$ID/$IDString data) but can collect Date values directly if so coded by the user.

Operators with implied sort

The max(), min(), List.max(), and List.min(), implicitly sort data. They are intended for Number-type data, so if used—arguably incorrectly—on a list of Date values, this implies doing a numerical sort on a list of string values, albeit strings starting with numbers. As such any "never" value present will sort at the beginning of the list.

Beware .first and .last

Do not mistake List.first() and List.last() as implying earliest/latest date. They simply return the first item in the list or the last, the same as using list[0] or List.at(-1).

Other sort-related tasks