Fix date columns showing numbers instead of dates

This commit is contained in:
Christian Vidal Wolf
2026-03-29 17:17:50 +02:00
parent fac448153f
commit 2ed90234a7
2 changed files with 20 additions and 0 deletions
+10
View File
@@ -162,6 +162,16 @@ export default function App() {
} }
} }
// Handle date columns - Excel serial dates are numbers >= 25569 (Jan 1, 1970)
if (header.includes('date') || header.includes('launch') || header.includes('ready')) {
if (typeof val === 'number' && val >= 25569 && val <= 60000) {
const excelEpoch = new Date(1899, 11, 30);
const date = new Date(excelEpoch.getTime() + val * 86400000);
return date.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' });
}
return val;
}
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg']; const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
const shouldFormat = formatKeywords.some(kw => header.includes(kw)); const shouldFormat = formatKeywords.some(kw => header.includes(kw));
+10
View File
@@ -21,6 +21,16 @@ export function MatrixView({ data, headers }: MatrixViewProps) {
// Convert header to lowercase for checks // Convert header to lowercase for checks
const h = header.toLowerCase(); const h = header.toLowerCase();
// Handle date columns - Excel serial dates are numbers >= 25569 (Jan 1, 1970)
if (h.includes('date') || h.includes('launch') || h.includes('ready')) {
if (typeof val === 'number' && val >= 25569 && val <= 60000) {
const excelEpoch = new Date(1899, 11, 30);
const date = new Date(excelEpoch.getTime() + val * 86400000);
return date.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' });
}
return val;
}
// Always format weight/NW/GW/kg columns to 2 decimals — checked before any exclusion logic // Always format weight/NW/GW/kg columns to 2 decimals — checked before any exclusion logic
if (h.includes('nw') || h.includes('gw') || h.includes('weight') || h.includes('kg')) { if (h.includes('nw') || h.includes('gw') || h.includes('weight') || h.includes('kg')) {
if (typeof val === 'number') return val.toFixed(2); if (typeof val === 'number') return val.toFixed(2);