aha. OK. Try this but backup your wiki first, this is untested:
/*\
THIS IS A MODIFIED COPY
title: $:/stobot/macros/dateadd.js
type: application/javascript
module-type: macro
Takes a base date and adds days, months or years
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "dateadd";
exports.params = [
{name: "basedate"},
{name: "days"},
{name: "months"},
{name: "years"},
{name: "template"}
];
/*
Run the macro
*/
exports.run = function(basedate, days, months, years, template) {
//Make each date object.
if (basedate === "") {
var newdate = new Date();
} else {
var baseyear = basedate.substr(0,4);
var basemonth = basedate.substr(4,2);
var baseday = basedate.substr(6,2);
var newdate = new Date(Number(baseyear), Number(basemonth)-1,
Number(baseday), 0, 0, 0);
}
var new_year = Number(newdate.getFullYear())+Number(years);
var new_month = Number(newdate.getMonth())+Number(months);
var new_day = Number(newdate.getDate())+Number(days);
var output_date = new Date(new_year, new_month, new_day, 0, 0, 0);
var result = (output_date.getFullYear()*10000) +
((output_date.getMonth()+1)*100) + (output_date.getDate());
if(template === ""){
return result;
} else {
return $tw.utils.formatDateString(output_date,template);
}
};
})();
If this works, suggest you rename it (both in the comment at the top and
the tiddler title) to avoid confusion in the future.
On Friday, April 24, 2020 at 1:41:36 PM UTC+2, Stobot wrote:
>
> Sorry if I was unclear Saq. The macro doesn't generate the format, it
> generates the date. I need to pass <$view> a date *other than today* and
> have it apply the formatting.
>
> I should point out in case anyone else finds it helpful, while Jed's
> add-time.js (
> http://inmysocks.tiddlyspot.com/#%24%3A%2Finmysocks%2Fmacros%2Fadd-time.js)
> is great, it didn't let me start with any other date than today, which I
> was able to tweak. This code (below) is what I'd love to add a parameter
> string to so that I can also pass it "YYYY-MM-DD". I hope that makes more
> sense.
>
> /*\
> title: $:/stobot/macros/dateadd.js
> type: application/javascript
> module-type: macro
>
> Takes a base date and adds days, months or years
>
> \*/
> (function(){
>
> /*jslint node: true, browser: true */
> /*global $tw: false */
> "use strict";
>
> /*
> Information about this macro
> */
>
> exports.name = "dateadd";
>
> exports.params = [
> {name: "basedate"},
> {name: "days"},
> {name: "months"},
> {name: "years"}
> ];
>
> /*
> Run the macro
> */
> exports.run = function(basedate, days, months, years) {
>
> //Make each date object.
>
> if (basedate === "") {
> var newdate = new Date();
> } else {
> var baseyear = basedate.substr(0,4);
> var basemonth = basedate.substr(4,2);
> var baseday = basedate.substr(6,2);
> var newdate = new Date(Number(baseyear), Number(basemonth)-1, Number(
> baseday), 0, 0, 0);
> }
>
> var new_year = Number(newdate.getFullYear())+Number(years);
> var new_month = Number(newdate.getMonth())+Number(months);
> var new_day = Number(newdate.getDate())+Number(days);
>
> var output_date = new Date(new_year, new_month, new_day, 0, 0, 0);
>
> var result = (output_date.getFullYear()*10000) + ((output_date.getMonth
> ()+1)*100) + (output_date.getDate());
>
> 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 view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/95fb63de-9824-46f5-ae00-465ebfaace4a%40googlegroups.com.