Skip to content

Commit

Permalink
Merge pull request #4255 from Compositr/master
Browse files Browse the repository at this point in the history
Add new datePattern and monthPattern replacers
  • Loading branch information
zadam authored Sep 12, 2023
2 parents 9413cd2 + 542e257 commit 65e5374
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/services/date_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 65e5374

Please sign in to comment.