Tinderbox v10 Icon

Dates and filtering non-dates

A Date-type attribute always has a value. The default value is "never", which when views as string isn't what would normally be considered an actual date. Taxes aren't paid on the date of "never" but on an actual day.

However, the default value is useful, as it allows detection of dates that should have a valid date value but do not (yet!). But, in contrast, what if the need is to address only valid dates within lists of Date-type values? This is were some understanding of sorting dates is necessary (see parent article).

There is no currently no 'first date' or last date' operator that auto-ignores default "never".

Avoiding lists with default values

One approach is plan ahead when collecting lists of dates and to avoid any default values. Thus:

$MyList = collect(children,$StartDate) 

might include values of never. But the latter can be avoided by instead using either of:

$MyList = collect_if(children, $StartDate!="never",$StartDate) 

$MyList = collect_if(children, $StartDate,$StartDate)  (shorter less obviously explicit form)

Now $MyList cannot contain a non-date as the collecting process filters out all "never" values.

But what if another process results in a list of dates that might contain a date? It might be templating to do this:

$MyDates = $MyList - "never"; WRONG!

This only works if $MyList contains zero or one occurrences of "never" as it removes the value only once. If two or more $MyList still contains unwanted values. Better is to iterate the list into a new list only retaining valid' dates. If the list is of date string (date values):

	$MyList.each(anItem){
		if(anItem != "never"){
			$MyList2 += anItem
		}
	};

Here two List-type attributes are used, but these could as easily be list-type variables. That holds to the next example as well.

If the list is path/ID date for notes, the non-dates can be filtered like this (assuming the dates are in attribute $StartDate:

	$MyList.each(aNote){
		if($StartDate(anItem) != "never"){
			$MyList2 += $StartDate(anItem)
		}
	};

If used often these tests could be used in a user function for easy re-use.