Files
MajoorWaldi-ComfyUI-Majoor-…/js/utils/format.js
T
MajoorWaldi dc72be0139 feat: enhance JS testing and linting setup
- Added coverage reporting for Vitest with configuration in vitest.config.mjs
- Updated package.json to include new scripts for JS coverage, linting, and formatting
- Modified run_quality_gate.py to allow skipping ESLint and Prettier checks
- Introduced .prettierrc for consistent code formatting
- Created .prettierignore to exclude specific files and directories from formatting
2026-03-28 14:14:28 +01:00

39 lines
1.1 KiB
JavaScript

function parseDate(input) {
if (!input) return null;
// Try to parse as number (seconds) first, even if string
const num = Number(input);
if (!isNaN(num)) {
return new Date(num * 1000);
}
const date = new Date(input);
if (isNaN(date.getTime())) return null;
return date;
}
export function formatDate(input) {
const date = parseDate(input);
if (!date) return "";
const day = date.getDate().toString().padStart(2, "0");
const month = (date.getMonth() + 1).toString().padStart(2, "0");
return `${day}/${month}`;
}
export function formatTime(input) {
const date = parseDate(input);
if (!date) return "";
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
return `${hours}:${minutes}`;
}
// Format duration (seconds) to human readable string (e.g. 1m 30s)
export function formatDuration(seconds) {
if (!seconds) return "";
if (seconds < 60) return `${Math.round(seconds)}s`;
const m = Math.floor(seconds / 60);
const s = Math.round(seconds % 60);
return `${m}m ${s}s`;
}