Dave,

I am at a computer now so I can give a more reasonable answer than before.

The day-diff macro takes the date split up into year month and day input 
separately, it can't take a YYYYMMDD string like you are describing. You 
can try to split them up using a sequence of filters, but I think that just 
replacing the code in the macro with yours is going to be simpler and give 
you exactly what you want.

Anyway, the tables show the input parameters for each of the macros, so 
year1 is the starting year and year2 is the ending year, it gives 
year1-year2 in the output. The day and month inputs are the same with day1 
and month1 being the start and day2 and month2 the end.

Modifying the macro to work with your function is less difficult than it 
probably seems, but it took a lot of trial and error for me to figure that 
out. To keep you from having to spend so much time on it here is how you 
could modify the day-diff.js tiddler to work with your code, or with any 
other javascript macro:


1. Change the second line so that the title is something else, otherwise it 
will overwrite the same tiddler and probably cause confusion if you share 
it.
2. Change the description, if your macro is going to do something 
different, at the moment the description is the part that says 'Takes two 
dates and returns their difference in days', it can be as long as you want 
it to be but it must have the emptyline above it. I am not certain it needs 
the empty line below but it may.
3. Change the line exports.name = "day-diff"; so that day-diff is whatever 
name you want to give the macro, this is what you use the call the macro 
either as <<day-diff.... or in <$macro-call $name=day-diff....
4. Change the export.params = [...] so that the array is an array of 
objects, one per input to your function, in the same format as they already 
are, ie {name: parameterName}
5. Change the exports.run = function ... so that the function is your 
function. It should have the same inputs as listed in the export.params 
array lists.

The javascript in the macro can be as complex as you want, and you can 
define multiple functions, the one that is listed in the exports.run line 
is the one that gets run.

The function should return a string that is whatever you need the result of 
the macro to be.

As a warning, while you can make the macro change the state of the wiki by 
changing values in tiddler fields it is generally not a good idea. A macro 
gets evaluated every time it is rendered and if evaluating the macro 
changes a widget or tiddler that causes the macro call to be re-rendered 
you end up with an infinite loop or other unexpected behaviour.

And to answer your other question about the parameter names, they are 
whatever you give in the exports.params array. So you have <$macro-call 
$name=day-diff year1=1098 year2=2012/> or <<day-diff year1:1098 year2:2012>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/5e4badd1-bb40-44e9-be82-ea46b36bb8a2%40googlegroups.com.

Reply via email to