When you have complex patterns, you generally need a complex solution. See this topic for working code that implements a generic solution for any repeating shift schedule:
If you aren't using PostgreSQL, you will have to substitute other ways to use table-returning functions. (Good luck with that.)