It’s been a while since my last post. I’ve been hacking along though. Here’s an interesting puzzle I faced recently.
In the app, I have an model called Corporation. Each corporation has a reporting frequency, a start date and the timezone it’s in. The task is to calculate the next (and the last) reporting date for each corporation. It seems pretty straight forward, but the devil is in the details …
The trimmed down version of my implementation is below
The only tricky bit is the first if block inside the recursive reporting_date call. It makes sure we’re not losing days when we cycle through months that have less days than the start_date.day value.
Hope I’m making sense here … and I’m sure there are existing algorithms out there doing what I want more elegantly.