The main algorithm was good, but there were issues with code that was preparing data for processing and some timezone handling issues, both of which gave results that didn't make any sense.
End result: much more readable code and correct results.
quoting nevent1q…x3p0Oh, wow, some days are just awful.
I just realized that a very complicated system I developed isn't working properly and will have to take it completely apart and rebuild it from scratch.