Update macros.js

This commit is contained in:
Hydroerotic 2024-05-11 13:52:31 +03:00 committed by GitHub
parent f421139402
commit 432be2ee57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 0 deletions

View File

@ -259,6 +259,25 @@ function diceRollReplace(input, invalidRollPlaceholder = '') {
});
}
/* Returns the difference between two times. Works with any time format acceptable by moment().
* Can work with {{date}} {{time}} macros
*/
function timeDiffReplace(input) {
const timeDiffPattern = /{{timeDiff::(.*?)::(.*?)}}/gi;
const output = input.replace(timeDiffPattern, (match, matchPart1, matchPart2) => {
const time1 = new moment(matchPart1);
const time2 = new moment(matchPart2);
const timeDifference = moment.duration(time1.diff(time2));
return timeDifference.humanize();
});
return output;
}
/**
* Substitutes {{macro}} parameters in a string.
* @param {string} content - The string to substitute parameters in.