Skip to content
Snippets Groups Projects
Commit 8e97a29e authored by uhensler's avatar uhensler
Browse files

OO-4630: Set correct end time of an recurring appointment

parent 4b3bdf05
No related branches found
No related tags found
No related merge requests found
......@@ -120,16 +120,10 @@ public class DateUtils {
* @return
*/
public static Date copyTime(Date date, Date from) {
Calendar fromCalendar = new GregorianCalendar();
fromCalendar.setTime(from);
Calendar toCalendar = new GregorianCalendar();
toCalendar.setTime(date);
toCalendar.set(Calendar.HOUR, fromCalendar.get(Calendar.HOUR));
toCalendar.set(Calendar.MINUTE, fromCalendar.get(Calendar.MINUTE));
toCalendar.set(Calendar.SECOND, fromCalendar.get(Calendar.SECOND));
return toCalendar.getTime();
LocalDateTime ldtDate = toLocalDateTime(date);
LocalDateTime ldtfrom = toLocalDateTime(from);
LocalDateTime localDateTime = LocalDateTime.of(ldtDate.toLocalDate(), ldtfrom.toLocalTime());
return toDate(localDateTime);
}
public static Date addDays(Date date, int days) {
......
......@@ -169,6 +169,10 @@ public class RecurringAppointmentsController extends FormBasicController {
private void doSaveReccuringAppointments() {
Date firstStart = recurringFirstEl.getDate();
Date firstEnd = recurringFirstEl.getSecondDate();
System.out.println(firstStart);
System.out.println(firstEnd);
Date last = recurringLastEl.getDate();
last = DateUtils.setTime(last, 23, 59, 59);
......@@ -185,6 +189,9 @@ public class RecurringAppointmentsController extends FormBasicController {
Date end = DateUtils.copyTime(start, firstEnd);
appointment.setEnd(end);
System.out.println(start);
System.out.println(end);
String location = locationEl.getValue();
appointment.setLocation(location);
......
......@@ -396,6 +396,8 @@ public class EditLectureBlockController extends FormBasicController {
}
lectureBlock.setStartDate(dateEl.getDate());
lectureBlock.setEndDate(dateEl.getSecondDate());
System.out.println(dateEl.getDate());
System.out.println(dateEl.getSecondDate());
int plannedLectures = Integer.parseInt(plannedLecturesEl.getSelectedKey());
lectureBlock.setPlannedLecturesNumber(plannedLectures);
......
......@@ -29,6 +29,7 @@ import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.List;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
/**
......@@ -50,12 +51,19 @@ public class DateUtilsTest {
@Test
public void shouldCopyTime() {
Date date = new GregorianCalendar(2020, 5, 1, 10, 0, 0).getTime();
Date from = new GregorianCalendar(2020, 8, 20, 8, 3, 2).getTime();
SoftAssertions softly = new SoftAssertions();
softly.assertThat(DateUtils.copyTime(
new GregorianCalendar(2020, 5, 1, 10, 0, 0).getTime(),
new GregorianCalendar(2020, 8, 20, 8, 3, 2).getTime())
).isEqualTo(new GregorianCalendar(2020, 5, 1, 8, 3, 2).getTime());
date = DateUtils.copyTime(date, from);
softly.assertThat(DateUtils.copyTime(
new GregorianCalendar(2020, 5, 1, 10, 0, 0).getTime(),
new GregorianCalendar(2020, 5, 1, 10, 0, 0).getTime())
).isEqualTo(new GregorianCalendar(2020, 5, 1, 10, 0, 0).getTime());
assertThat(date).isEqualTo(new GregorianCalendar(2020, 5, 1, 8, 3, 2).getTime());
softly.assertAll();
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment