I'm not sure I understand you. Can you explain in code or pseudocode? My intent was that everything in the loop after the ++$day is events occurring during the course of a day. Before ++$day is events occurring at the end of a day.
(This doesn't correctly model exactly when the level actually changes, but I think it does use fields based on the correct level everywhere.)