Finding earliest start date date and oldest end data of a note's children

I have a fun question.

Can anyone think of an efficient way to evaluate a note’s children and return back to the parent’s $StartDate the youngest date from all the children’s $StartDates and put the oldest $EndDate in the parent’s $EndDate? I presume this will be done by an edict. It will require building a list of the Childrens’ $StartDates, sorting, and picking the youngest, and a list of the childrens’ $EndDates, sorting, and picking the oldest $EndDate. I can build the list, NP. But then what? How would you sort dates in a list? I tried .min and .max, but that did not work. Ideas?

If you can convert the date to a string in YY-MM-DD format, then alphabetizing the strings would be the same as a date sort.

If you use:

$MyList = collect(children,$StartDate).sort;

You get a list of entires like this 2013-02-09T22:39:25Z, the string coercion is automatic and given the format we can sort.

Now for the $StartDate, get:

$StartDate = date($MyList.at(0));

Mote details to follow but that’s the gist.

1 Like

Set the sort method of the agent or container to sort by StartDate. Then get $StartDate(child) and $StartDate(lastChild).

No need to convert the date to a string; Tinderbox knows how to sort date attributes.

I used my Starter (as it already has dated notes in it) file originally and debugged like so:

$MyList=collect_if(children,$StartDate,$StartDate).sort;
$StartDate = date($MyList.at(0));
$MyListA = collect_if(children,$EndDate,$EndDate).sort;
$EndDate = date(MyListA.at(-1));
$MyNumber = $MyList.count;
$MyNumberA = $MyListA.count;

Why collect_if? I’m assuming you don’t want start/end that aren’t set (i.e. "never’). Note that the query $StartDate is the short query form of $StartDate!=“never”, i.e. it has a date value.

Now, to roll it up into one-liners with no interim attribute-stashing of values:

$StartDate=date(collect_if(children,$StartDate,$StartDate).sort.at(0));
$EndDate=date(collect_if(children,$EndDate,$EndDate).sort.at(-1));

Nice example of both nested and chained action operators. The first line above unpacks as:

  • get (collect) a list the $StartDate for all child notes that have a $StartDate value.
  • sort that list
  • get the first list item
  • using that latter item string use it to make a Date object and use it to set $StartDate.