ive had to deal with a fair share of this messy time logic, and ive found this library really useful
https://juxt.github.io/tick/
if you cant express it with the tools it gives you, it generally means youre making unsafe assumptions