Repository: urlaubsverwaltung/urlaubsverwaltung (java)

Issue:
Ganztägiges ICal Event wird von 00:00 Uhr bis 24:00 Uhr angezeigt, statt als ganztätiges Event in der Kalenderfreigabe
mit #4734 wurde das Verhalten von ganztägigen Events "geändert". Diese werden nun nicht mehr als ein gesonderter Eintrag angezeigt, sondern als ein Event von 00:00 Uhr bis 24:00 Uhr

![grafik](https://github.com/urlaubsverwaltung/urlaubsverwaltung/assets/142107/ed101787-b21c-4809-939e-463026580278)


Pull request description:
Fix calculation if ical
closes #4755

<!--

Thanks for contributing to the Urlaubsverwaltung.
Please review the following notes before submitting you pull request.

Please look for other issues or pull requests which already work on this topic. Is somebody already on it? Do you need to synchronize?

# Security Vulnerabilities

🛑 STOP! 🛑 If your contribution fixes a security vulnerability, please do not submit it.
Instead, please open a report of a security vulnerability via
[Report a security vulnerability](https://github.com/urlaubsverwaltung/urlaubsverwaltung/security/advisories/new)


# Describing Your Changes

If, having reviewed the notes above, you're ready to submit your pull request, please
provide a brief description of the proposed changes.

If they:
 🐞 fix a bug, please describe the broken behaviour and how the changes fix it.
    Please label with 'type: bug' and 'status: new'
    
 🎁 make an enhancement, please describe the new functionality and why you believe it's useful.
    Please label with 'type: enhancement' and 'status: new'
 
If your pull request relates to any existing issues,
please reference them by using the issue number prefixed with #.

-->


Patch:
diff --git a/src/main/java/org/synyx/urlaubsverwaltung/calendar/ICalService.java b/src/main/java/org/synyx/urlaubsverwaltung/calendar/ICalService.java
index 0ff3122cb..d1daedb24 100644
--- a/src/main/java/org/synyx/urlaubsverwaltung/calendar/ICalService.java
+++ b/src/main/java/org/synyx/urlaubsverwaltung/calendar/ICalService.java
@@ -24,6 +24,7 @@ import org.synyx.urlaubsverwaltung.person.Person;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.URI;
+import java.time.LocalDate;
 import java.time.ZonedDateTime;
 import java.util.List;
 import java.util.Optional;
@@ -95,12 +96,7 @@ public class ICalService {
 
         final VEvent event;
         if (absence.isAllDay()) {
-            if (isSameDay(startDateTime, endDateTime)) {
-                event = new VEvent(startDateTime, absence.getEventSubject());
-            } else {
-                event = new VEvent(startDateTime, endDateTime, absence.getEventSubject());
-            }
-            event.add(new XProperty("X-MICROSOFT-CDO-ALLDAYEVENT", "TRUE"));
+            event = generateAllDayEvent(absence.getEventSubject(), startDateTime, endDateTime);
         } else {
             event = new VEvent(startDateTime, endDateTime, absence.getEventSubject());
         }
@@ -123,6 +119,20 @@ public class ICalService {
         return Optional.of(event);
     }
 
+    private VEvent generateAllDayEvent(String eventSubject, ZonedDateTime startDateTime, ZonedDateTime endDateTime) {
+        final LocalDate startDate = startDateTime.toLocalDate();
+        final LocalDate endDate = endDateTime.toLocalDate();
+
+        final VEvent event;
+        if (isSameDay(startDate, endDate)) {
+            event = new VEvent(startDate, eventSubject);
+        } else {
+            event = new VEvent(startDate, endDate, eventSubject);
+        }
+        event.add(new XProperty("X-MICROSOFT-CDO-ALLDAYEVENT", "TRUE"));
+        return event;
+    }
+
     private Attendee generateAttendee(Absence absence) {
         final Attendee attendee = new Attendee(URI.create("mailto:" + absence.getPerson().getEmail()));
         attendee.add(REQ_PARTICIPANT);
@@ -131,8 +141,8 @@ public class ICalService {
         return attendee;
     }
 
-    private boolean isSameDay(ZonedDateTime startDateTime, ZonedDateTime endDate) {
-        return startDateTime.toLocalDate().isEqual(endDate.toLocalDate().minusDays(1));
+    private boolean isSameDay(LocalDate startDate, LocalDate endDate) {
+        return startDate.isEqual(endDate.minusDays(1));
     }
 
     private String generateUid(Absence absence) {


Test patch:
diff --git a/src/test/java/org/synyx/urlaubsverwaltung/calendar/ICalServiceTest.java b/src/test/java/org/synyx/urlaubsverwaltung/calendar/ICalServiceTest.java
index 4d591a297..e6ba4dd91 100644
--- a/src/test/java/org/synyx/urlaubsverwaltung/calendar/ICalServiceTest.java
+++ b/src/test/java/org/synyx/urlaubsverwaltung/calendar/ICalServiceTest.java
@@ -75,7 +75,7 @@ class ICalServiceTest {
                 REFRESH-INTERVAL:P1D
                 BEGIN:VEVENT
                 DTSTAMP:<removedByConversionMethod>
-                DTSTART;TZID=Etc/UTC:20190326T000000
+                DTSTART;VALUE=DATE:20190326
                 SUMMARY:Marlene Muster abwesend
                 X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
                 UID:F5C924EEB91550EBDD74CDA428649C8B
@@ -140,8 +140,8 @@ class ICalServiceTest {
                 REFRESH-INTERVAL:P1D
                 BEGIN:VEVENT
                 DTSTAMP:<removedByConversionMethod>
-                DTSTART;TZID=Etc/UTC:20190326T000000
-                DTEND;TZID=Etc/UTC:20190402T000000
+                DTSTART;VALUE=DATE:20190326
+                DTEND;VALUE=DATE:20190402
                 SUMMARY:Marlene Muster abwesend
                 X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
                 UID:D4C6D48B54BAED09F894FBDE0151381F
@@ -314,7 +314,7 @@ class ICalServiceTest {
                 X-MICROSOFT-CALSCALE:GREGORIAN
                 BEGIN:VEVENT
                 DTSTAMP:<removedByConversionMethod>
-                DTSTART;TZID=Etc/UTC:20190526T000000
+                DTSTART;VALUE=DATE:20190526
                 SUMMARY:Marlene Muster abwesend
                 X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
                 UID:22D8DC26F4271C049ED5601345B58D9C
@@ -352,7 +352,7 @@ class ICalServiceTest {
                 X-MICROSOFT-CALSCALE:GREGORIAN
                 BEGIN:VEVENT
                 DTSTAMP:<removedByConversionMethod>
-                DTSTART;TZID=Etc/UTC:20190526T000000
+                DTSTART;VALUE=DATE:20190526
                 SUMMARY:Marlene Muster abwesend
                 X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
                 UID:22D8DC26F4271C049ED5601345B58D9C
@@ -384,7 +384,7 @@ class ICalServiceTest {
                 X-MICROSOFT-CALSCALE:GREGORIAN
                 BEGIN:VEVENT
                 DTSTAMP:<removedByConversionMethod>
-                DTSTART;TZID=Etc/UTC:20190526T000000
+                DTSTART;VALUE=DATE:20190526
                 SUMMARY:Vertretung für Marlene Muster
                 X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
                 UID:D2A4772AEB3FD20D5F6997FCD8F28719