From 3b9600ec8c396d2d960861baadb904506fc05e87 Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Fri, 27 Sep 2024 13:45:05 +0200 Subject: [PATCH] csv: add start and end time to csv export --- .../report/ReportCsvService.java | 9 ++++-- src/main/resources/messages.properties | 2 ++ src/main/resources/messages_en.properties | 2 ++ .../report/ReportCsvServiceIT.java | 2 +- .../report/ReportCsvServiceTest.java | 28 +++++++++---------- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/focusshift/zeiterfassung/report/ReportCsvService.java b/src/main/java/de/focusshift/zeiterfassung/report/ReportCsvService.java index a34c3bbab..857529a12 100644 --- a/src/main/java/de/focusshift/zeiterfassung/report/ReportCsvService.java +++ b/src/main/java/de/focusshift/zeiterfassung/report/ReportCsvService.java @@ -8,6 +8,7 @@ import java.io.PrintWriter; import java.text.NumberFormat; +import java.time.LocalTime; import java.time.Month; import java.time.Year; import java.time.YearMonth; @@ -74,11 +75,13 @@ private void writeHeader(Locale locale, PrintWriter writer) { final String date = messageSource.getMessage("report.csv.header.date", new Object[]{}, locale); final String givenName = messageSource.getMessage("report.csv.header.person.givenName", new Object[]{}, locale); final String familyName = messageSource.getMessage("report.csv.header.person.familyName", new Object[]{}, locale); + final String start = messageSource.getMessage("report.csv.header.start", new Object[]{}, locale); + final String end = messageSource.getMessage("report.csv.header.end", new Object[]{}, locale); final String workedHours = messageSource.getMessage("report.csv.header.workedHours", new Object[]{}, locale); final String comment = messageSource.getMessage("report.csv.header.comment", new Object[]{}, locale); final String isBreak = messageSource.getMessage("report.csv.header.break", new Object[]{}, locale); - writer.println(String.format("%s;%s;%s;%s;%s;%s", date, givenName, familyName, workedHours, comment, isBreak)); + writer.println(String.format("%s;%s;%s;%s;%s;%s;%s;%s", date, givenName, familyName, start, end, workedHours, comment, isBreak)); } private void writeWeek(ReportWeek reportWeek, Locale locale, PrintWriter writer) { @@ -99,10 +102,12 @@ private String reportDayEntryToCsvLine(ReportDayEntry reportDayEntry, NumberForm final String date = dateFormatter.formatDate(reportDayEntry.start().toLocalDate()); final String givenName = reportDayEntry.user().givenName(); final String familyName = reportDayEntry.user().familyName(); + final LocalTime start = reportDayEntry.start().toLocalTime(); + final LocalTime end = reportDayEntry.end().toLocalTime(); final String hoursWorked = numberFormat.format(reportDayEntry.workDuration().hoursDoubleValue()); final String comment = reportDayEntry.comment(); final boolean isBreak = reportDayEntry.isBreak(); - return String.format("%s;%s;%s;%s;%s;%s", date, givenName, familyName, hoursWorked, comment, isBreak); + return String.format("%s;%s;%s;%s;%s;%s;%s;%s", date, givenName, familyName, start, end, hoursWorked, comment, isBreak); } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 72ed8ad6b..d3cbc1f6f 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -305,6 +305,8 @@ report.weekly.csv.filename=zeiterfassung-bericht-{0,number,#}-kw{1}.csv report.csv.header.date=Datum report.csv.header.person.givenName=Vorname report.csv.header.person.familyName=Nachname +report.csv.header.start=Von +report.csv.header.end=Bis report.csv.header.workedHours=erfasste Stunden report.csv.header.comment=Kommentar report.csv.header.break=Pause diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index e3ad55c66..fd27be36f 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -304,6 +304,8 @@ report.weekly.csv.filename=zeiterfassung-report-{0,number,#}-kw{1}.csv report.csv.header.date=Date report.csv.header.person.givenName=Given name report.csv.header.person.familyName=Family name +report.csv.header.start=From +report.csv.header.end=To report.csv.header.workedHours=Worked hours report.csv.header.comment=Comment report.csv.header.break=Break diff --git a/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceIT.java b/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceIT.java index 5842c3b84..5750321fc 100644 --- a/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceIT.java +++ b/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceIT.java @@ -33,7 +33,7 @@ class ReportCsvServiceIT extends SingleTenantTestContainersBase { private UserManagementService userManagementService; @ParameterizedTest - @CsvSource({"de,Datum;Vorname;Nachname;erfasste Stunden;Kommentar;Pause", "en,Date;Given name;Family name;Worked hours;Comment;Break"}) + @CsvSource({"de,Datum;Vorname;Nachname;Von;Bis;erfasste Stunden;Kommentar;Pause", "en,Date;Given name;Family name;From;To;Worked hours;Comment;Break"}) void ensureI18nHeader(String languageTag, String expectedHeader) { final PrintWriter printWriter = mock(PrintWriter.class); diff --git a/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceTest.java b/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceTest.java index 46b26039d..d49ecaf92 100644 --- a/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceTest.java +++ b/src/test/java/de/focusshift/zeiterfassung/report/ReportCsvServiceTest.java @@ -75,7 +75,7 @@ void ensureWeekReportCsvWithEmptyReport() { sut.writeWeekReportCsv(Year.of(2021), 1, Locale.GERMAN, new UserId("batman"), printWriter); assertThat(stringWriter).hasToString(""" - report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break + report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break """); } @@ -103,8 +103,8 @@ void ensureWeekReportCsvRoundsWorkedHoursToTwoDigit() { sut.writeWeekReportCsv(Year.of(2021), 1, Locale.GERMAN, batmanId, printWriter); assertThat(stringWriter).hasToString(""" - report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break - 04.01.2021;Bruce;Wayne;0,500;hard work;false + report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break + 04.01.2021;Bruce;Wayne;10:00;10:30;0,500;hard work;false """); } @@ -143,10 +143,10 @@ void ensureWeekReportCsvContainsSummarizedInfoPerDay() { sut.writeWeekReportCsv(Year.of(2021), 1, Locale.GERMAN, batmanId, printWriter); assertThat(stringWriter).hasToString(""" - report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break - 04.01.2021;Bruce;Wayne;1,000;hard work;false - 04.01.2021;Bruce;Wayne;1,000;hard work;false - 05.01.2021;Bruce;Wayne;8,000;hard work;false + report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break + 04.01.2021;Bruce;Wayne;10:00;11:00;1,000;hard work;false + 04.01.2021;Bruce;Wayne;14:00;15:00;1,000;hard work;false + 05.01.2021;Bruce;Wayne;09:00;17:00;8,000;hard work;false """); } @@ -166,7 +166,7 @@ void ensureMonthReportCsvWithEmptyReport() { sut.writeMonthReportCsv(YearMonth.of(2021, 1), Locale.GERMAN, new UserId("batman"), printWriter); assertThat(stringWriter).hasToString(""" - report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break + report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break """); } @@ -200,8 +200,8 @@ void ensureMonthReportCsvRoundsWorkedHoursToTwoDigit() { sut.writeMonthReportCsv(YearMonth.of(2021, 1), Locale.GERMAN, batmanId, printWriter); assertThat(stringWriter).hasToString(""" - report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break - 04.01.2021;Bruce;Wayne;0,500;hard work;false + report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break + 04.01.2021;Bruce;Wayne;10:00;10:30;0,500;hard work;false """); } @@ -245,10 +245,10 @@ void ensureMonthReportCsvContainsSummarizedInfoPerDay() { sut.writeMonthReportCsv(YearMonth.of(2021, 1), Locale.GERMAN, batmanId, printWriter); assertThat(stringWriter).hasToString(""" - report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break - 04.01.2021;Bruce;Wayne;1,000;hard work;false - 04.01.2021;Bruce;Wayne;1,000;hard work;false - 05.01.2021;Bruce;Wayne;8,000;hard work;false + report.csv.header.date;report.csv.header.person.givenName;report.csv.header.person.familyName;report.csv.header.start;report.csv.header.end;report.csv.header.workedHours;report.csv.header.comment;report.csv.header.break + 04.01.2021;Bruce;Wayne;10:00;11:00;1,000;hard work;false + 04.01.2021;Bruce;Wayne;14:00;15:00;1,000;hard work;false + 05.01.2021;Bruce;Wayne;09:00;17:00;8,000;hard work;false """); }