Determine when two datetime ranges overlap

I have two datetime intervals, and I want to identify the overlapping period between them. For instance, if I have intervals:

  • 01-12-2023 01:00:00 to 12-12-2023 15:00:00
  • 10-12-2023 11:00:00 to 24-12-2023 16:00:00

I need to retrieve the common interval, which in this case is 10-12-2023 11:00:00 to 12-12-2023 15:00:00. How can I achieve this in PHP, either using native functions or a library like Carbon?