How to update a list of dates by time

I’m working on a time calculator app that uses three dates: Start Date, End Date, and a Reference Date. I pick these dates using a calendar picker. The app uses a repeating group, and instead of saving the dates as states or directly from the calendar picker, I want to base them on the reference date.

In the repeating group, there are two date-time pickers: one for the start date and one for the end date. The idea is that I can update the dates using the time pickers, starting from midnight, but I’m having trouble with the conditions for updating the dates more than once.

The issue is when I try to change a date, sometimes it duplicates or resets to the wrong date. For example, if I have 10/21/24 and 10/22/24, and I change 10/22/24, the app might reset it to 10/21/24 instead of updating properly.

What I’m doing to update the dates is using a “remove” function to remove the old date, and then adding the new date (based on the time picker) back in, combining it with the reference date.

What I want to do any can’t figure out the logic is before I update the list make sure that just the date of time I’m updating matches the proper parent group dates. I tried change hours 0 minutes 0 and seconds 0 then updating but still hasn’t worked. I can do this in coding in 5 minutes but I can’t figure it out in bubble.