Merge pull request #4255 from Compositr/master

Add new datePattern and monthPattern replacers
This commit is contained in:
zadam 2023-09-13 00:19:04 +02:00 committed by GitHub
commit 65e53741e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,13 @@ function createNote(parentNote, noteTitle) {
}).note;
}
function ordinal(n) {
var s = ["th", "st", "nd", "rd"],
v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
}
/** @returns {BNote} */
function getRootCalendarNote() {
let rootNote;
@ -98,6 +105,8 @@ function getMonthNoteTitle(rootNote, monthNumber, dateObj) {
const monthName = MONTHS[dateObj.getMonth()];
return pattern
.replace(/{shortMonth3}/g, monthName.slice(0,3))
.replace(/{shortMonth4}/g, monthName.slice(0,4))
.replace(/{monthNumberPadded}/g, monthNumber)
.replace(/{month}/g, monthName);
}
@ -145,6 +154,7 @@ function getDayNoteTitle(rootNote, dayNumber, dateObj) {
const weekDay = DAYS[dateObj.getDay()];
return pattern
.replace(/{ordinal}/g, ordinal(parseInt(dayNumber)))
.replace(/{dayInMonthPadded}/g, dayNumber)
.replace(/{isoDate}/g, dateUtils.utcDateStr(dateObj))
.replace(/{weekDay}/g, weekDay)