Tinderbox Forum

Calculating the start times for each topic in a presentation

Hi, I was wondering how to add the a number to a time? I’m trying to organise a workshop with a number of topics for the morning, with $Duration assigned to each. As this is constantly being changed with the addition and modification of each topic, I was hoping to automate the calculation and display of the start time for each topic.
I’ve tried $EndDate=(($StartDate).format(hh:mm)+time($Duration)); in the rule but have got it totally wrong! Attaching a sample file to hopefully explain what i’m trying to do.
Ideally, I’d like to

  1. Assign a start date and time for the session
  2. Have that start date be the basis for the start time for topic 1
  3. Then have the duration of topic 1 added to it to calculate the end time for topic 1 and then be assigned as the start time for topic 2
    and so on.

Apologies for what must be a very basic question - there’s a reason I stick to my day job!!! Thanks!
Peter
Sample TB.tbx (115.8 KB)

The easiest approach is to use a date expression. For example:

$StartDate=$StartDate(prevSibling)+"30 minutes";

DateExpression.tbx (86.6 KB)

Thanks for this, Mark! And would there be a way I could set the time added from a number attribute $Duration? I don’t seem to be able to do that with $StartDate=$StartDate(previousSibling)+"($Duration) minutes";

Try:

$StartDate(previousSibling)+($Duration + " minutes");

Note how we concatenate a Number ($Duration) value and a literal string using parentheses so the that concatenation with $StartDate is that we add a string like "30 minutes). Now we have Date-type data. Used ‘raw’ in a Display Expression we just get a long number string like 1651939560 (why? sup>†):

So, let’s format the Date data for reading on screen using a format string:

($StartDate(previousSibling)+($Duration + " minutes")).format("d MM y t")

Result:

Or, if we start the Display Expression with some text, Tinderbox will correctly guess we want a text version of the date. So, with a $DisplayExpression of:

"Session end:"+"\n"+$StartDate(previousSibling)+($Duration + " minutes")

Result:

But, note that Tinderbox has had to guess how that date info should be described, giving a more complex date string that perhaps we want. So, let us alter the $DisplayExpression to use a formatting of our choice, as tried above:

"Session end:"+"\n"+($StartDate(previousSibling)+($Duration + " minutes")).format("d MM y t")

Result:

More on date formatting codes.

File used for the above: DateExpression-ed.tbx (82.8 KB)

Sorry for long post but I figure a little explanation of the how and why might make the basic answer easier to adapt.

†. Because Date date is simply the number of milliseconds since the Unix epoch(i.e. from a fixed reference date knows to the OS/app). The app then turns that number into human readable dates. But, here, in raw state we just see the number

Thanks so much for taking the time to explain the background of this! I love the (slow) discoveries that keep coming up now that I’ve been emboldened by all the videos that you guys are putting out there!
Cheers, Peter

1 Like