small refactor of ordinal() func

This commit is contained in:
zadam 2023-11-03 13:49:18 +01:00
parent 6dd466ddaf
commit 809ffa0c6e

View file

@ -1,12 +1,10 @@
"use strict";
const noteService = require('./notes');
const becca = require('../becca/becca');
const attributeService = require('./attributes');
const dateUtils = require('./date_utils');
const sql = require('./sql');
const protectedSessionService = require('./protected_session');
const cls = require("./cls");
const searchService = require('../services/search/services/search');
const SearchContext = require('../services/search/search_context');
const hoistedNoteService = require("./hoisted_note");
@ -29,13 +27,6 @@ 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;
@ -162,6 +153,14 @@ 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) {
const suffixes = ["th", "st", "nd", "rd"];
const suffix = suffixes[(dayNumber - 20) % 10] || suffixes[dayNumber] || suffixes[0];
return `${dayNumber}${suffix}`;
}
/** @returns {BNote} */
function getDayNote(dateStr, rootNote = null) {
if (!rootNote) {