Added Date Format setting to Opened Card.

Thanks to xet7 !

Fixes #2011,
fixes #1176
This commit is contained in:
Lauri Ojansivu 2025-10-20 01:36:44 +03:00
parent 516552cce6
commit 2dd3916f7e
8 changed files with 161 additions and 13 deletions

View file

@ -354,6 +354,10 @@
"custom-field-text": "Text",
"custom-fields": "Custom Fields",
"date": "Date",
"date-format": "Date Format",
"date-format-yyyy-mm-dd": "YYYY-MM-DD HH:MM",
"date-format-dd-mm-yyyy": "DD-MM-YYYY HH:MM",
"date-format-mm-dd-yyyy": "MM-DD-YYYY HH:MM",
"decline": "Decline",
"default-avatar": "Default avatar",
"delete": "Delete",

View file

@ -36,6 +36,44 @@ export function formatDate(date) {
return `${year}-${month}-${day}`;
}
/**
* Format a date according to user's preferred format
* @param {Date|string} date - Date to format
* @param {string} format - Format string (YYYY-MM-DD, DD-MM-YYYY, MM-DD-YYYY)
* @param {boolean} includeTime - Whether to include time (HH:MM)
* @returns {string} Formatted date string
*/
export function formatDateByUserPreference(date, format = 'YYYY-MM-DD', includeTime = true) {
const d = new Date(date);
if (isNaN(d.getTime())) return '';
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
const hours = String(d.getHours()).padStart(2, '0');
const minutes = String(d.getMinutes()).padStart(2, '0');
let dateString;
switch (format) {
case 'DD-MM-YYYY':
dateString = `${day}-${month}-${year}`;
break;
case 'MM-DD-YYYY':
dateString = `${month}-${day}-${year}`;
break;
case 'YYYY-MM-DD':
default:
dateString = `${year}-${month}-${day}`;
break;
}
if (includeTime) {
return `${dateString} ${hours}:${minutes}`;
}
return dateString;
}
/**
* Format a time to HH:mm format
* @param {Date|string} date - Date to format