Tinderbox Forum

Formatting Interval

If an interval is “-27 days 23:59:55” how would I format the export code so that it only shows “-27 days”?

I think my notes or wrong or Interval.format() doesn’t work as documented. I had expected this to work:


But, if fairness ‘d’ is the days of a Date in date format terms. What we actually want is Interval.day :


which returns a number of whole days from the source interval. Currently, a negative is not parsed, but we can fix that with this code (line breaks for clarity:

   $MyNumber=$MyInterval.day * -1;

[Edit, it transpires the .format() call in the last example isn’t needed so it’s now gone!]

Thanks. How would I make this work in export code? I’ve tried variations of this:

^if^^value($SigningGap)^<0^ -^value($SigningGap).substr(0,1))^ days^else^^value($SigningGap.day)^ days^endif^

The above is rendering everything positive, e.g. 27 days rather than -27 days.


You don’t say what what data type $SigningGap is. Regardless, your ^if()^ statement is improperly formed as there are no parentheses around the condition query. I think you meant to write (line breaks for clarity only):

   -^value($SigningGap).substr(0,1))^ days
   ^value($SigningGap.day)^ days

Does that help?


that won’t work as this line doesn’t make sense (unbalanced parentheses):

   -^value($SigningGap).substr(0,1))^ days

I think you were trying to write:

   -^value($SigningGap.substr(0,1))^ days

though even then, that code will emit the string “-- days”. I don’t think you want that. Read on in my next reply.

Further EDIT

Keep reading for a better solution for a simple test for a negative interval. My method above was driven by assuming I was dealing with a string (because I’d tried .format() first). It works but a better solution emerges below.


does work to check for a negative and $SigningGap is an Interval; then I think you can use simpler code Again line breaks for clarity only):

   -^value($SigningGap.day)^ days
   ^value($SigningGap.day)^ days

Tip If you are getting unbalanced pairs of ( ) or { } as you type your code, add complete pairs, and type inside. IOW, type ^value()^ then move the cursor inside the (now balanced parentheses) and start typing the nested code.

Drawing on the above, I’ve improved my previous tests for a negative internal. See demo with in-doc and export solutions.: Interval-test.tbx (91.2 KB)

Interval-test.tbx 2021-01-25 15-20-32

Thanks, but something, even with your demo, seems to be wrong. When I use this now all the numbers are negative, rather than positive. I created a new note using your demo and made the number positive instead of negative.

It previews as negative,

For the life of me, I can’t figure this out.

The original use case for interval data was managing track durations in music recordings. In that scenario, negative intervals are an error.

(OK: perhaps after an especially bad performance, you might say “that’s 8 minutes and 13 seconds of my life I’ll never get back” and then find yourself pleasantly surprised that you did, in fact, receive a refund. But Tinderbox 8 isn’t fully equipped for metaphysics.)

I’ll take a look at this.

Funny, thanks, Mark. Here is my use case. I’m in a contract dispute. I want to show how LATE my client is based on expected deliverables. Note, based on this effort I’m building a really cool communications analysis response template that I’ll share, once we can figure this out.

Note: Worst case, I’ll dump the negative interval into another string and they use that, but I’d prefer to not have to jump through those hoops.

Tinderbox really helped me, quickly analyze 3 years of contracts and the last month of disputed communications, in about 90 minutes. Such a great tool!

1 Like

Working on it…

OK, is seems the implied coercion in ^if(Interval<0)^ seems not to work in export code but i’ve fixed it (code is in the demo file).

Interval-test.tbx 2021-01-25 19-24-25

See: Interval-test.tbx (104.9 KB)

1 Like

Dude, you are a rock STAR!!! Thank you so much.