Skip to content

Commit

Permalink
small refactor of ordinal() func
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Nov 3, 2023
1 parent 6dd466d commit 809ffa0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/services/date_notes.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 809ffa0

Please sign in to comment.