Calculate working hour putting into consideration break time

Maybe the solution is a script, but I’m really after is the time in hours between two dates, but only the business hours.
So Monday - Friday, 8.30am - 12.30pm and 1.30pm - 5.30pm.

just to be clear:
23/6/2022 8:30AM - 23/6/2022 5:30PM. => 8
23/6/2022 8:30AM - 24/6/2022 12:30PM => 12
23/6/2022 8:30AM - 24/6/2022 5:30PM => 16
24/6/2022 8:30AM - 27/6/2022 12:30PM => 12

23/6/2022 8:30AM - 23/6/2022 5:30PM. the result of the formula should be 8
in this case start date and end date have 8 working hours

the second one has this working hour:
23/6/2022 8:30AM - 23/6/2022 12:30AM
23/6/2022 1:30PM - 23/6/2022 5:30PM
24/6/2022 8:30AM - 24/6/2022 12:30PM
in total 12 hours

Do you have a solution for this? Is something like Microsoft project