Tinderbox Forum

Changing the Set value order

Is there a way to change the order values in a Set are displayed? I have a $Weekly attribute that is a set type. The values are Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. However, the order is not in week order and this order is displayed in the attribute browser. How do I get them to order Monday-Sunday?

As documented, a Set has no fixed sort order but it is generally as created (which is often in alphabetical order). As it is the (English) day names don’t follow simple coded sort order (A–Z, length of word, etc.).

How/where are you trying to display these. I ask as it’s no use making a suggestion only to find that is immediately some other process as-yet revealed (I don’t mean that unkindly).

Althuogh days of the week as a string have no encoded sort order., if they reflect actual dates (Date/Time attribute data) then see the Date.weekday property which—being numerical—has a natural Mon→Sun sort oder (sorry, no Sun→Sat option for reason obvious from the linked article).

Another option here, depending on what you are doing, is simply to store the day as a number or use a Look-up table.

If it seems like it should be simple, just arrived on my desk is a 384-page book—just about sorting names. I suspect the context of your task will make one of the ideas above relevant for the task.

Thanks Mark,

I’m trying to get them to sort in the Attribute browser.

So, within AB view categories, you want notes to sort by a stored weekday name string?

If so, I’d just make a Number-type attribute, e.g. $DayNumber, either set via your source Date attribute’s extracted weekday, e.g. $DayNumber = $YourSourceDateAttr.weekday;, or set the equivalent manually. Then set $DayNumber as the sort attribute.

Does that help?

Ok, so I didn’t quite get that! Sorry!

In the end your day number comment made me think about adding a number to the day set name, ie 1 Monday (yes Monday is the first day of the week; I’m look at you Tinderbox!). I then set the attribute browser to use my $Weekly attribute and to sort using my $Weekly attribute. I then sorted descending. However, all the notes where this attribute was not set appeared so I put this in the query, !$Weekly=="" to remove all notes without a value in the $Weekly attribute. Seems to be working!

OK, i’ve made a test rig to show this (TBX link at the end). In this test I’ve assumed notes have an $Owner who will be the AB view category within which we want to sort on the day name held in $DayName—which, as discussed, doesn’t work. I’ve demoed two solutions. In Test, I have set manually a 1–7 $DayNumber value for Mon–Sun $NameDay values. In Test2, I’m assuming the day name is actually derived from a date (here $StartDate) and use an edict to set $dayNumber thus:


In both tests the day of the week is the same in each test for test notes 1–4 (i.e. AA–DD and EE–II) as shown here:

AB view for Test1:

AB view for Test2:

Of course, the attribute names used here are just my example, all except $StartDate are user attributes in this case.

Here is the TBX. It has 3 tabs, all illustrated above: Day-sort.tbx (102.6 KB)

1 Like