A member joins a gym on January 31. They pay monthly. When is their next renewal?
February 28, obviously. And the one after that? If your answer is March 28, you've just written the bug we spent a surprising amount of time on.
MemberKeep is our offline Flutter app for businesses with recurring members: gyms, clubs, coworking spaces, coaches, freelancers. It tracks members, plans, renewal dates and expected monthly revenue, all on the device. Here's how three of its core parts work, and why we built them that way.
Renewals are counted from the join date
The naive way to renew is "take the last renewal date and add one cycle":
// simplified: the drifting version DateTime nextRenewal ( DateTime previous ) = > DateTime ( previous . year , previous . month + 1 , previous . day );
Enter fullscreen mode
Exit fullscreen mode
Dart's DateTime rolls overflow forward, so January 31 plus a month lands in early March. Clamp it to the end of February and you get the 28th.…