From ddba049455ade1d153088da45fc1792ad17069c4 Mon Sep 17 00:00:00 2001 From: Jin <22962980+JYC333@users.noreply.github.com> Date: Wed, 2 Apr 2025 23:46:35 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Use=20dayjs=20to=20hand?= =?UTF-8?q?le=20ordinal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/date_notes.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/services/date_notes.ts b/src/services/date_notes.ts index 6ec861968..f0690792e 100644 --- a/src/services/date_notes.ts +++ b/src/services/date_notes.ts @@ -12,10 +12,12 @@ import dayjs from "dayjs"; import type { Dayjs } from "dayjs"; import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js"; import quarterOfYear from "dayjs/plugin/quarterOfYear.js"; +import advancedFormat from "dayjs/plugin/advancedFormat.js"; import cloningService from "./cloning.js"; dayjs.extend(isSameOrAfter); dayjs.extend(quarterOfYear); +dayjs.extend(advancedFormat); const CALENDAR_ROOT_LABEL = "calendarRoot"; const YEAR_LABEL = "yearNote"; @@ -41,13 +43,6 @@ const MONTH_TRANSLATION_IDS = [ "months.december" ]; -/** produces 1st, 2nd, 3rd, 4th, 21st, 31st for 1, 2, 3, 4, 21, 31 */ -function ordinal(dayNumber: number) { - const suffixes = ["th", "st", "nd", "rd"]; - const suffix = suffixes[(dayNumber - 20) % 10] || suffixes[dayNumber] || suffixes[0]; - return `${dayNumber}${suffix}`; -} - type TimeUnit = 'year' | 'quarter' | 'month' | 'week' | 'day'; const baseReplacements = { @@ -103,7 +98,7 @@ function getJournalNoteTitle(rootNote: BNote, timeUnit: TimeUnit, dateObj: Dayjs // Day related '{dayInMonthPadded}': numberStr.padStart(2, '0'), - '{ordinal}': ordinal(number), + '{ordinal}': dateObj.format('Do'), '{weekDay}': weekDay, '{weekDay3}': weekDay.substring(0, 3), '{weekDay2}': weekDay.substring(0, 2)