mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +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:
parent
340312fa80
commit
e29e745b96
@ -318,6 +318,8 @@ The currently supported template variables are:
|
||||
| `{{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 |
|
||||
| `{{#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
|
||||
|
||||
|
@ -11,6 +11,15 @@ Mustache.escape = 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) {
|
||||
// new template variables can be added here
|
||||
// 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));
|
||||
};
|
||||
},
|
||||
bowm: time.formatMsToLocal(beginningOfWeek(1), time.dateFormat()),
|
||||
bows: time.formatMsToLocal(beginningOfWeek(0), time.dateFormat()),
|
||||
};
|
||||
|
||||
return Mustache.render(input, view);
|
||||
|
Loading…
Reference in New Issue
Block a user