Quiet hours that wrap midnight
transcript
Ana wants quiet nights. Twenty two hundred to seven. It is 23:30 and a promo arrives. Should it buzz her phone? Easy rule. Hard to get right.
The obvious check is start less than or equal to now, less than end. But twenty two is not less than seven. The test is never true. So the promo buzzes her at 23:30.
When the window wraps, the test flips. Now is at least start, or now is before end. At 23:30, that is true. Now is after twenty two. At three in the morning, it is also true.
How long until seven? End minus now, modulo a day. Seven hours minus twenty three thirty is negative. The modulo fixes it. Seven and a half hours. The rule defers the promo to 07:00.
A one-time login code is critical. It bypasses quiet hours. A morning code is useless to someone logging in now. So the rule checks priority first, then the window.
Write the wrap case first. It is the one that breaks.
The full design is in the lecture. Channels, rules, retries and dedupe.