An even better solution would be the Pathfinder Kingmaker system, but that would be a larger amount of work.
With the PF system, some time happen when you storm the fortress, everyone shouts; Hurry up! You need to quickly get to the main hall and defeat that !name! bad boy. But you lie down in front of the door of his room and sleep like a baby. Such immersion...
I have no idea of what you are even talking about.
The point of the PF system is that you can set camp anywhere there's enough ground space and if not in close proximity of enemies.
And then you can choose between a shorter resting time that just use up supplies or taking longer and hunting for food.
it's a system that works in synchrony with the fact that you often have limited time to achieve certain goals, so you can't be EXCEEEDINGLY wasteful with your rests.
The specific of when you rest exactly is irrelevant, not to mention mostly up to the player.
If anything, your frankly silly complaint about the possibility of resting just before an important fight applies to pretty much any other relevant title in the genre. PF is the one that disincentivized that behavior the most.