From 970505ac88ffabfacf54b9cf481d2952c22dafe7 Mon Sep 17 00:00:00 2001 From: Manuel Rauber Date: Thu, 5 Sep 2024 14:32:32 +0200 Subject: [PATCH] fix: correctly export the CSV --- .../components/settings/settings.component.ts | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/app/components/settings/settings.component.ts b/src/app/components/settings/settings.component.ts index beeb10b..1c0036f 100644 --- a/src/app/components/settings/settings.component.ts +++ b/src/app/components/settings/settings.component.ts @@ -50,30 +50,32 @@ export default class SettingsComponent { const today = DateTime.now().set({ hour: 0, minute: 0, second: 0, millisecond: 0 }); const startDay = today.minus({ day: days }); const items = await firstValueFrom(this.timeTable.groupByDay$(startDay.toMillis(), today.toMillis())); - const rows = items.flatMap(item => [ + const rows = [ ['Date', 'Start Time', 'End Time', 'Duration', 'Is A Day Off?', 'Is a non work day?', 'description'], - ...item.items.map(timeEntry => [ - DateTime.fromMillis(item.utcDate).toISODate(), - DateTime.fromMillis(timeEntry.start).toISOTime({ - includeOffset: false, - includePrefix: false, - suppressMilliseconds: true, - suppressSeconds: true, - extendedZone: false, - }), - DateTime.fromMillis(timeEntry.end).toISOTime({ - includeOffset: false, - includePrefix: false, - suppressMilliseconds: true, - suppressSeconds: true, - extendedZone: false, - }), - millisecondsToHumanReadable(timeEntry.duration.toMillis()), - timeEntry.isADayOff, - timeEntry.isNonWorkday, - timeEntry.description, + ...items.flatMap(item => [ + ...item.items.map(timeEntry => [ + DateTime.fromMillis(item.utcDate).toISODate(), + DateTime.fromMillis(timeEntry.start).toISOTime({ + includeOffset: false, + includePrefix: false, + suppressMilliseconds: true, + suppressSeconds: true, + extendedZone: false, + }), + DateTime.fromMillis(timeEntry.end).toISOTime({ + includeOffset: false, + includePrefix: false, + suppressMilliseconds: true, + suppressSeconds: true, + extendedZone: false, + }), + millisecondsToHumanReadable(timeEntry.duration.toMillis()), + timeEntry.isADayOff, + timeEntry.isNonWorkday, + timeEntry.description, + ]), ]), - ]); + ]; const csv = rows.map(row => row.join(',')).join('\n'); const csvBlob = new Blob([csv], { type: 'text/csv;charset=utf-8' });