>
>
> It is created using the NOW macro. It does not matter how it looks like, 
> as long as it is easy to calculate the time diff in minutes between them.
> I wanted to avoid creating a custom JS macro, but if it is the only way... 
>

Danielo,

Perhaps something like this would serve as a starting place for what you 
want...

(function(){
/*\
 Calculates the difference between two dates

<<datediff date1 date2 days>>

\*/

exports.name = "datediff";

exports.params = [
{ name: "date1" }, 
{ name: "date2"}, 
{ name: "units"},
];

/*
Run the macro
*/

exports.run = function(date1,date2,units) {

// If no date supplied use current date
if (date2=="") {
var d2=new Date();
var date2 = d2.toLocaleDateString();
}
if (date1==""){
var d1=new Date(5/1/1984);
}

var d1 = new Date(date1);
var d2 = new Date(date2);

switch(units){
case "weeks":
        var t2 = d2.getTime();
        var t1 = d1.getTime();

result = Math.floor(parseFloat((t2-t1)/(24*3600*1000*7))*100)/100+" weeks";
break;
case "minutes":
        var t2 = d2.getTime();
        var t1 = d1.getTime();
result = parseInt((t2-t1)/(60*1000)) + " minutes";

break;
case "months":
        var d1Y = d1.getFullYear();
        var d2Y = d2.getFullYear();
        var d1M = d1.getMonth();
        var d2M = d2.getMonth();
        var d1D = d1.getDate();
        var d2D = d1.getDate();

result =Math.floor(((d2M+12*d2Y+d2D/30)-(d1M+12*d1Y-d1D/30))*100)/100 + " 
months";
break;
case "years":
        var d1Y = d1.getFullYear();
        var d2Y = d2.getFullYear();
        var d1M = d1.getMonth();
        var d2M = d2.getMonth();
        var d1D = d1.getDate();
        var d2D = d1.getDate();

result =Math.floor(((d2M/12+d2Y+d2D/365)-(d1M/12+d1Y-d1D/365))*100)/100 + " 
years";

// result=parseFloat(d2.getFullYear()-d1.getFullYear()) + " years";
break;
default:
        var t2 = d2.getTime();
        var t1 = d1.getTime();
result = parseInt((t2-t1)/(24*3600*1000)) + " days";
}

return result;
};

})();


 

-- 
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/e9326388-fda3-4b7e-bd7d-c67c6ccdad8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to