This works on my system. Here's how the list is set up:
<$list filter="[!has[draft.of]tag[Stocks]]">
<$set name=bestbefore value={{!!bestbefore}}>
<$link to={{!!title}}><$view field="title"/> </$link> <$reveal type="match"
default=<<day-left>> text="YES">
@@color:red;( to be discarded )@@
</$reveal>
<br/>
</$set>
</$list>
This is basically Eric's way, except I'm changing how the variable date
gets passed.
Below is the revised javascript macro. In theory, you should be able to
use it with standard parameters (e.g. <<day-left {{!!mydate}}>>) in those
cases where you don't need the value used by the calling widget. But you
can't use it both ways at the same time, because the version with the
parameter takes precedence.
Be sure to make back-ups before testing.
Good luck,
Mark
/*\
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) {
var bb = this.getVariable("bestbefore") ;
var bestb4 = "" ;
if(bb) bestb4 = bb ;
if(bestbefore) bestb4 = bestbefore ;
//Make each date object.
var year= parseInt(bestb4.substring(0,4));
var month= parseInt(bestb4.substring(4,6));
var day= parseInt(bestb4.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";}
};
})();
--
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/36056402-adbd-4f1d-9b18-b12c6ac2f6e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.