Seems that there is no macro or widget to accomplish such simple task.
I just want to know the number of minutes elapsed, which should be simple. Just a difference between the milliseconds then and now.
Regards
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...
(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;
};
})();
Danielo,
Perhaps something like this would serve as a starting place for what you want...
Thanks for providing such macro. However, I wanted to avoid the usage of javascript macros, and I wanted to create a pure tiddlywiki version.I really think that tiddlywiki, being advertised as something you can use as a diary, having journal facilities and that stuff, should provide better tools for date management.
Finally I made a very simple macro that fits my needs. However, I'm a bit disappointed with this situation.
Thanks for providing such macro. However, I wanted to avoid the usage of javascript macros, and I wanted to create a pure tiddlywiki version.I really think that tiddlywiki, being advertised as something you can use as a diary, having journal facilities and that stuff, should provide better tools for date management.Finally I made a very simple macro that fits my needs. However, I'm a bit disappointed with this situation.In any case, I save your macro for future reference.Regards
The fact that there is no support for date arithmetic in the core is because nobody has contributed it; in order for it to be implemented somebody has to do the work of writing the code, adding tests, checking it on different browsers etc. The fact that that hasn’t happened yet doesn’t mean that nobody thinks it’s a good idea, nor that anyone thinks it’s a bad idea. Asserting that TiddlyWiki “should” have a particular feature has very little impact
I’d suggest don't waste time being surprised or disappointed; just jump in and help where you can.
Ah. I misread your post. My mistake.
I would be interested in seeing your macro when you're ready to share it.
I think that could be a good first step