I’m trying to set up a schedule in the form of a list of notes that automatically adjust the start and end times of all notes if I change the start time of the first or change the duration
My idea was to chain them together with a rule:
$StartDate=$EndDate(prevSibling)
And to set the $EndDate of each with a second part of the rule:
$EndDate=$StartDate+$Duration minutes
where $Duration is a user attribute of number type
This doesn’t work, however, but I can’t see why not.
Breaking it down, I find that on its own,
$EndDate=$StartDate+10 minutes
gives the expected result, but replacing the “10” with “$Duration” fails, even though $Duration is a number variable
You might want to use the interval data type for $Duration, rather than numeric type. Your model works for me if I use interval.
Also, be careful not to use the first rule ($StartDate=$EndDate(prevSibling)) with the first note in a container, because it will always give the result of none, since there is no “previous sibling” for the first note.
I concur with @PaulWalters that the best approach is an interval as it is specifically designed for (intervals of) time. but, if you don’t like/understand those, can you use a Number attribute here? Yes. Let’s investigate…
$EndDate=$StartDate+10 minutes
is better written as
$EndDate=$StartDate+"10 minutes";
But even better is:
$EndDate=date($StartDate +"10 minutes");
Now if Number-type attribute $Duration has a value of 10 this achieves the same as above)
The extra parentheses are to ensure Tinderbox combines $Duration with the literal string “minutes” which can only reconcile to a string which then works inside date() for interval addition/subtraction.
Paul/Mark, many thanks. I must have missed the introduction of the Interval attribute type – a lot of my Tbx knowledge was gleaned a few versions back now – it’s clearly the right solution here. A quick change of attribute type and it all works perfectly, as I’d originally intended.
I’ve just added a bit of extra content to aTbRef’s note on the interval(date1,date2) function, linked to above, in order to try and clarify things a bit more.