Rails' end_of_month

Posted by andy

Whilst building the payment module for one of my Rails apps I used the very convenient Rails’ Time extension method end_of_month returns the last day of the month. However it sets the time to 00:00:00, which is quite unexpected IMHO! Technically the end of the month is still 86400 seconds away. This behaviour is documented, but if you haven’t actually read the whole API it might cause some nasty surprises. I fixed it by simply adding 86399 seconds to end_of_time. That still leaves 999 usecs, but I can live with that :)