Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Calculating "days since" for simple task assistant (Read 9845 times)
Sumner Gerard
Full Member
*
Offline



Posts: 359

Calculating "days since" for simple task assistant
Aug 03rd, 2008, 1:01pm
 
I record in a daybook somewhat irregularly recurring activities that don't necessary occur in sequence. Call activity one "jump up", activity two "run in circles" and activity three "dance and shout."  

I want to see in one convenient place how many days have passed since I last jumped, last ran in circles, last danced and shouted, etc.  For me more feature-filled task management assistants end up cluttered with so many jumps, runs, and shouts scattered among "due," "overdue," and "followup" that they end up too poorly maintained to be useful.

I can use agents to collect date-sorted occurrences of each tracked activity in separate containers and then use #last(JumpContainer, 1) | #last(RunContainer,1) | #last(ShoutContainer, 1) | .... in an agent query to collect the most recent occurrence of each activity.  

But I can't figure out how to do the date arithmetic for "days since" and have that dispayed in the relevant note titles. I tried "today"-Created + " days : " + $Name in DisplayExpression. I tried using a rule to set a number user attribute to "today"-created.  I tried using days(Created, "today"), which looked promising, but today assigns a value of 244 for a note Created "2008.07.31 9:28 PM".

The "News about Tinderbox" page on the website, referring to Tinderbox 3.6.2. (I'm running 4.2.5), states that " subtracting two dates and assigning the result to an integer yields the number of days between the two dates. "

aTbRef, describing "Date Attributes", states: "Dates can be added/subtracted/compared in mathematical fashion, as per number data types. The resulting 'string' can be formatted by means of date format codes."  aTbRef (under "Date Operators", which I found in a TBX version but can't seem to find by searching the online version) lists the days(date1,date2) I tried as described above.

I am obviously missing something obvious. Improperly mixing strings and numbers? How does one get "days since"?
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Calculating "days since" for simple task
Reply #1 - Aug 3rd, 2008, 1:15pm
 
If Date and Date2 are two Date attributes, and N is a numerical attribute, the rule

    N=$Date-$Date2    (corrected from earlier posting)

sets N to the number of days between Date and Date2.

If Date is a Date attribute, then the rule

    N=$Date-"June 1, 2008"

sets N to the number of days since June 1.  

   N=$Date="today"

gives the expected result, 31, if Date is September 3, 2008 4pm and today is August 3, 2008 2pm.

Back to top
 
« Last Edit: Aug 4th, 2008, 10:57am by Mark Bernstein »  
WWW   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Calculating "days since" for simple task assistant
Reply #2 - Aug 3rd, 2008, 8:57pm
 
Thanks. I was confused by the N=$Date-Date2 (instead of N=$Date-$Date2) and N=$Date="today" but, encouraged that I was close, resumed experimenting.  

It seems: a) one can't do the date arithmetic in DisplayExpression but must assign the result first to a numerical attribute, and b) one has to use N="today"-$Created (not my original N="today"-Created), where N is a numerical attribute I've named DaysSince.

DaysSince=days($Created, "today") as opposed to my original days(Created,"today") also seems to work.

So a rule DaysSince="today"-$Created or DaysSince=days($Created,"today") together with a DisplayExpression something like $Name + "  (" + format($DaysSince,0) + " days since)" seems to do the trick.


Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Calculating "days since" for simple task assistant
Reply #3 - Aug 4th, 2008, 4:52am
 
I think part of the problem is you've (unintentionally) conflated two issues: date arithmetic and parsing expressions. The problem arises because the common maths symbols (+-*/) all have other meanings in different contexts; plus is the string concatenate, minus can be a text hyphen, multiply can be a text asterisk, and divide can be either a forward slash or a POSIX path folder delimiter.

Regular Expressions inside TB itself can find these symbols in your data but ultimately it (TB) must rely on context to figure out whether '-' is a hyphen or a subtraction and so on. The flip side is that for the learner, such areas of confusion even if understood in principle aren't easy to predict when writing actions and rules. This thread is worth reading to get an understanding of why your DisplayExpression doesn't work as expected - you have to allow for how TB can mis-interpret your intent for text as maths and vice versa.

I'm sorry if the aTbRef page confused you (I'll review that text) but I think you interpreted it a little narrowly.  You can do maths using Date format attribute data, it is the final output of that maths that is a string (except where stated). The most usual exception are functions like days() that document that they return a number (of days) - this is so the figure can be used in further calculation.  With care it can be turned into a string. The latter is a scenario where you might want to use a secondary attribute - for instance to concatenate a number to a string to make it all a string before passing it through any further expression evaluation, such as DisplayExpression.

Remember, if you write a multi-part/stage action or rule that doesn't work, make a small test TBX (or test section in you TBX) and break out each stage and look at the result. That way you can see where TB is not giving you the result expected. Often the format of the incorrect result will indicate what's happening and help indicate an alternate approach. User attributes can help, if you think of them as like code variables; the counter-intuitive part is that each attribute exists for all notes and attributes are normally seen by users as being visible things - not under-the-hood calculations. If you get past that last oddity, TB's not phased by a few extra attributes.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Date arithmetic in DisplayExpression
Reply #4 - Aug 4th, 2008, 11:04am
 
Why doesn't $Date1-$Date2 return the expected value in DisplayExpression?

Tinderbox recognizes the special case where you're subtracting two dates in order to make a number. But DisplayExpression is assembling a string; Tinderbox isn't currently clever enough to anticipate what you want.



Back to top
 
 
WWW   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Calculating "days since" for simple task assistant
Reply #5 - Aug 4th, 2008, 4:10pm
 
Upon further investigation, it looks like we will be able to support the expected behavior for Date1-$Date2 in string contexts like DisplayExpression in an upcoming release.


Back to top
 
 
WWW   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Calculating "days since" for simple task assistant
Reply #6 - Aug 4th, 2008, 5:54pm
 
Thanks much to both for your helpful explanations and pointers. I'm sure I've conflated and confused quite a bit.  Definitely not the fault of aTbRef. It's a very valuable resource, as is the manual and this forum.

Other than placing demands on DisplayExpression parsing for which it is not thus far intended (instead assign values to attributes first and then assemble them in DisplayExpression), what tripped me up most, I think, was using 'Created' in a rule when TBX was looking for '$Created'. Am still a little vague as to why this is so. By contrast, 'today', '"today"', and '$today' all seem acceptable.  I suspect this may have to do with 'Created' being an attribute and 'today' not.




Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Calculating "days since" for simple task assistant
Reply #7 - Aug 4th, 2008, 6:13pm
 
A handy rule of thumb is that any attribute on the right side of an '=' assignment needs a $ prefix so TB knows to what you refer:
OK: MyAttr = $OtherAttr
Not OK: MyAttr = OtherAttr

Placeholders for dates (today, year, etc.) don't take a $ prefix.  If you use action code that refer to attributes, such as any(), said attributes also need a $ prefix.

Incidentally, you can use a $ on the left side of an assignment, though few examples use this syntax:
$MyAttr = $OtherAttr
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Calculating "days since" for simple task assistant
Reply #8 - Aug 5th, 2008, 5:12pm
 
And, it seems, you also can use a $ with date placeholders without unexpected results.

Thanks for the rule of thumb. It helps break my association of $ with strings that can't be added to numbers.  Interesting the $ is not generally used on both sides of an assignment.  Such, I guess, is the nature of idioms.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Calculating "days since" for simple task assistant
Reply #9 - Aug 5th, 2008, 6:12pm
 
Date placeholders - I certainly not acquire the habit of using $ with them - the fact that syntax works now is probably accidental and something that may get 'fixed' (due to unrelated work elsewhere) in later version.

With left-side attributes the 'rule' is in principle that you do use a $ prefix like the right-side but it may be omitted and usually is by long-standing users of the app (ergo older demos, examples, etc.).
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print