1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-30 08:26:59 +02:00

Desktop: add {{bowm}} and {{bows}} - Beginning Of Week (Monday/Sunday) (#4023)

* add {{bowm}} and {{bows}} - Beginning Of Week (Monday/Sunday)

In certain situation it is useful to reference the beginning of the week.
Unfortunately the current system does not allow to that, not even with a custom datetime format.

I've also added the 2 new template variables to the documentation.

* README: better wording
This commit is contained in:
Helmut K. C. Tessarek 2020-11-12 13:41:37 -05:00 committed by GitHub
parent 340312fa80
commit e29e745b96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -318,6 +318,8 @@ The currently supported template variables are:
| `{{time}}` | Current time formatted based on the settings format | 13:00 | | `{{time}}` | Current time formatted based on the settings format | 13:00 |
| `{{datetime}}` | Current date and time formatted based on the settings format | 01/01/19 1:00 PM | | `{{datetime}}` | Current date and time formatted based on the settings format | 01/01/19 1:00 PM |
| `{{#custom_datetime}}` | Current date and/or time formatted based on a supplied string (using [moment.js](https://momentjs.com/) formatting) | `{{#custom_datetime}}M d{{/custom_datetime}}` | | `{{#custom_datetime}}` | Current date and/or time formatted based on a supplied string (using [moment.js](https://momentjs.com/) formatting) | `{{#custom_datetime}}M d{{/custom_datetime}}` |
| `{{bowm}}` | Date of the beginning of the week (when week starts on Monday) based on the settings format | |
| `{{bows}}` | Date of the beginning of the week (when week starts on Sunday) based on the settings format | |
# Searching # Searching

View File

@ -11,6 +11,15 @@ Mustache.escape = text => {
return text; return text;
}; };
function beginningOfWeek(index) {
// index: 0 for Sunday, 1 for Monday
const thisDate = new Date();
const day = thisDate.getDay(),
diff = day >= index ? day - index : 6 - day;
return new Date().setDate(thisDate.getDate() - diff);
}
TemplateUtils.render = function(input) { TemplateUtils.render = function(input) {
// new template variables can be added here // new template variables can be added here
// If there are too many, this should be moved to a new file // If there are too many, this should be moved to a new file
@ -24,6 +33,8 @@ TemplateUtils.render = function(input) {
return render(time.formatMsToLocal(new Date().getTime(), text)); return render(time.formatMsToLocal(new Date().getTime(), text));
}; };
}, },
bowm: time.formatMsToLocal(beginningOfWeek(1), time.dateFormat()),
bows: time.formatMsToLocal(beginningOfWeek(0), time.dateFormat()),
}; };
return Mustache.render(input, view); return Mustache.render(input, view);