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"; "use strict";
const noteService = require('./notes'); const noteService = require('./notes');
const becca = require('../becca/becca');
const attributeService = require('./attributes'); const attributeService = require('./attributes');
const dateUtils = require('./date_utils'); const dateUtils = require('./date_utils');
const sql = require('./sql'); const sql = require('./sql');
const protectedSessionService = require('./protected_session'); const protectedSessionService = require('./protected_session');
const cls = require("./cls");
const searchService = require('../services/search/services/search'); const searchService = require('../services/search/services/search');
const SearchContext = require('../services/search/search_context'); const SearchContext = require('../services/search/search_context');
const hoistedNoteService = require("./hoisted_note"); const hoistedNoteService = require("./hoisted_note");
@ -29,13 +27,6 @@ function createNote(parentNote, noteTitle) {
}).note; }).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} */ /** @returns {BNote} */
function getRootCalendarNote() { function getRootCalendarNote() {
let rootNote; let rootNote;
@ -162,6 +153,14 @@ function getDayNoteTitle(rootNote, dayNumber, dateObj) {
.replace(/{weekDay2}/g, weekDay.substr(0, 2)); .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} */ /** @returns {BNote} */
function getDayNote(dateStr, rootNote = null) { function getDayNote(dateStr, rootNote = null) {
if (!rootNote) { if (!rootNote) {