Hello
Here is my macro
/*\
title: $:/_ppmt/macros/day-left.js
type: application/javascript
module-type: macro
Takes current day and best before date and return their difference in days
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "day-left";
exports.params = [
{name: "bestbefore"}
];
/*
Run the macro
*/
exports.run = function(bestbefore) {
//Make each date object.
var year= parseInt(bestbefore.substring(0,4));
var month= parseInt(bestbefore.substring(4,6));
var day= parseInt(bestbefore.substring(6,8));
var date1 = new Date(year, month, day);
var date2 = new Date();
//Find difference in milliseconds.
var elapsed = date1.getTime()-date2.getTime();
//Number of milliseconds in a day.
var dayMS = 86400000;
//Convert milliseconds to year months and days
var days_diff = Math.floor(elapsed/dayMS);
var result = days_diff;
if (result>10) { return "NO";}
else {return "YES";}
};
})();
On Tuesday, 1 November 2016 15:44:37 UTC, Mark S. wrote:
>
> Hi Philippe,
>
> Can you share your version of the day-diff.js macro?
>
> I notice that there is a small typographical error in Eric's post. It's
> the double arrow at the end of the first <$reveal> widget. Perhaps you
> caught that?
>
> Good luck!
> Mark
>
> On Tuesday, November 1, 2016 at 5:36:43 AM UTC-7, Philippe Le Toquin wrote:
>>
>> HI Eric,
>>
>> I have tried you method but it is still not working. It is better in the
>> sense that it doesn't print the part I only want to print when it matches
>> but even when it is matching it still stays invisible. The only way to
>> reveal is to set type to nomatch.
>> :(
>>
>> Philippe
>>
>> On Tuesday, 1 November 2016 00:12:48 UTC, Eric Shulman wrote:
>>>
>>> On Monday, October 31, 2016 at 3:45:29 PM UTC-7, Philippe Le Toquin
>>> wrote:
>>>>
>>>> What I would ideally like to do is that the text in red (to be
>>>> discarded) only appears if the return of the macro is YES.
>>>> I would like to use the RevealWidget but can't make it works. Here is
>>>> what I tried
>>>> * <$link to={{!!title}}><$view field="title"/> </$link> <$reveal
>>>> type="match" state="<$macrocall $name="day-left"
>>>> bestbefore={{!!bestbefore}} />" text="YES">@@color:red;( to be
>>>> discarded )@@ </$reveal>
>>>> but the result of that is not working. Instead it displays:
>>>>
>>>
>>> While the "text" param can contain any desired text, macro call, or
>>> transclusion syntax, the "state" param can only be used to specify a
>>> TextReference (i.e., a target tiddler field or a DataTiddler property in
>>> which to store the current state value).
>>>
>>> To use a macro value instead of a stored state value, *omit* the "state"
>>> param entirely and use the "default" param instead... something like this:
>>>
>>> <$reveal type="match" default=<<day-left bestbefore={{!!bestbefore}}>>
>>> text="YES">>
>>> @@color:red;( to be discarded )@@
>>> </$reveal>
>>>
>>> That should do it. Let me know how it goes.
>>>
>>> enjoy,
>>> -e
>>> Eric Shulman
>>> TiddlyTools / ELS Design Studios
>>> InsideTiddlyWiki: The Missing Manuals
>>>
>>>
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/af293a6d-b8f6-4203-a8e1-ec30f2aa865c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.