feat: add new datePattern replacer {ordinal}

* {ordinal} is replaced with the ordinal date (e.g. 1st, 2nd, 3rd) etc.
This commit is contained in:
Compositr 2023-09-12 07:30:30 +10:00
parent 9413cd2296
commit 81d64e020e
No known key found for this signature in database
GPG Key ID: 411170F7641C3EA8

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;
@ -145,6 +152,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)