From 144bfe5f34793fd33d239e281f8ac05e126ded5b Mon Sep 17 00:00:00 2001 From: John Marsden Date: Tue, 30 Jan 2024 16:31:43 -0500 Subject: [PATCH] Add ordinalPadded day title generation template variable --- src/services/date_notes.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/date_notes.js b/src/services/date_notes.js index 69e2a06a0..83ab841c8 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -143,9 +143,12 @@ function getMonthNote(dateStr, rootNote = null) { function getDayNoteTitle(rootNote, dayNumber, dateObj) { const pattern = rootNote.getOwnedLabelValue("datePattern") || "{dayInMonthPadded} - {weekDay}"; const weekDay = DAYS[dateObj.getDay()]; + const dayVal = parseInt(dayNumber); + const ordinalSuffix = ordinalDaySuffix(dayVal); return pattern - .replace(/{ordinal}/g, ordinal(parseInt(dayNumber))) + .replace(/{ordinal}/g, `${dayVal}${ordinalSuffix}`) + .replace(/{ordinalPadded}/g, `${dayNumber}${ordinalSuffix}`) .replace(/{dayInMonthPadded}/g, dayNumber) .replace(/{isoDate}/g, dateUtils.utcDateStr(dateObj)) .replace(/{weekDay}/g, weekDay) @@ -153,12 +156,9 @@ function getDayNoteTitle(rootNote, dayNumber, dateObj) { .replace(/{weekDay2}/g, weekDay.substr(0, 2)); } -/** produces 1st, 2nd, 3rd, 4th, 21st, 31st for 1, 2, 3, 4, 21, 31 */ -function ordinal(dayNumber) { +function ordinalDaySuffix(dayNumber) { const suffixes = ["th", "st", "nd", "rd"]; - const suffix = suffixes[(dayNumber - 20) % 10] || suffixes[dayNumber] || suffixes[0]; - - return `${dayNumber}${suffix}`; + return suffixes[(dayNumber - 20) % 10] || suffixes[dayNumber] || suffixes[0]; } /** @returns {BNote} */