Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csv: add start and end time to csv export #866

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
""");
}

Expand Down Expand Up @@ -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
""");
}

Expand Down Expand Up @@ -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
""");
}

Expand All @@ -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
""");
}

Expand Down Expand Up @@ -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
""");
}

Expand Down Expand Up @@ -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
""");
}

Expand Down
Loading