Added KOITO_DATE_FORMAT option to choose how the dates are displayed

This commit is contained in:
joffrey-b 2026-04-21 11:17:47 +02:00
parent 0ec7b458cc
commit 61d5f2f5f0
10 changed files with 53 additions and 9 deletions

View file

@ -52,7 +52,15 @@ function timeSince(date: Date) {
return "just now";
}
export { timeSince };
function formatDate(date: Date, format: string): string {
if (!format) return date.toLocaleDateString();
const dd = String(date.getDate()).padStart(2, "0");
const mm = String(date.getMonth() + 1).padStart(2, "0");
const yyyy = String(date.getFullYear());
return format.replace("DD", dd).replace("MM", mm).replace("YYYY", yyyy);
}
export { timeSince, formatDate };
type hsl = {
h: number;
@ -119,3 +127,4 @@ const timeListenedString = (seconds: number) => {
export { hexToHSL, timeListenedString, getRewindYear, getRewindParams };
export type { hsl };