I have a list of sorted OffsetDateTime dates:
[2021-05-21T11:00-04:00, 2021-05-21T12:00-04:00, 2021-05-21T13:00-04:00, 2021-05-21T14:00-04:00, 2021-05-21T15:00-04:00, 2021-05-21T15:30-04:00, 2021-05-21T15:45-04:00, 2021-05-21T17:00-04:00]
I'd like to create a list of objects with a start and end date like the following:
{start: 2021-05-21T11:00-04:00, end: 2021-05-21T12:00-04:00}
{start: 2021-05-21T12:00-04:00, end: 2021-05-21T13:00-04:00}
{start: 2021-05-21T13:00-04:00, end: 2021-05-21T14:00-04:00}
{start: 2021-05-21T14:00-04:00, end: 2021-05-21T15:00-04:00}
{start: 2021-05-21T15:00-04:00, end: 2021-05-21T15:30-04:00}
{start: 2021-05-21T15:30-04:00, end: 2021-05-21T15:45-04:00}
{start: 2021-05-21T15:45-04:00, end: 2021-05-21T17:00-04:00}
Note that the start of the next date is the end of the previous date (Except first and last)
What I have so far...
// Create List<AppointmentAvailabilityBlock>
List<AppointmentAvailabilityBlock> appointmentAvailabilityBlockList = new ArrayList<>();
for (int i = 0; i < sortedTimes.size(); i+=2) {
OffsetDateTime start = sortedTimes.get(i);
OffsetDateTime end = sortedTimes.get(i+1);
appointmentAvailabilityBlockList.add(new AppointmentAvailabilityBlock(start, end));
}
But this outputs:
2021-05-21T11:00-04:00 2021-05-21T12:00-04:00
2021-05-21T13:00-04:00 2021-05-21T14:00-04:00
2021-05-21T15:00-04:00 2021-05-21T15:30-04:00
2021-05-21T15:45-04:00 2021-05-21T17:00-04:00