18 lines
828 B
JavaScript
18 lines
828 B
JavaScript
import { fmtHM, fmtHMSUTC } from './helpers.mjs';
|
|
|
|
// Genera CSV (server-side: retorna string) — nombre preservado
|
|
export function exportCSV(pairs) {
|
|
if (!pairs?.length) return '';
|
|
const head = ['documento','nombre','fecha','desde','hasta','duracion_hhmm','duracion_min','obs'];
|
|
const rows = pairs.map(p => {
|
|
const fecha = p.fecha || p.isoDate || '';
|
|
const desde = p.desde_ms!=null ? fmtHMSUTC(p.desde_ms) : '';
|
|
const hasta = p.hasta_ms!=null ? fmtHMSUTC(p.hasta_ms) : '';
|
|
const durHHMM = p.durMins!=null ? fmtHM(p.durMins) : '';
|
|
const durMin = p.durMins!=null ? Math.round(p.durMins) : '';
|
|
return [p.doc, p.name || '', fecha, desde, hasta, durHHMM, durMin, p.obs || '']
|
|
.map(v => `"${String(v).replaceAll('"','""')}"`).join(',');
|
|
});
|
|
return head.join(',') + '\n' + rows.join('\n');
|
|
}
|