in reply to A date calculation
As per funkymonk's orig post, it's trying to calc the first of the (next) mth, by adding enough days to get to the end of the curr mth (calc in seconds). It's actually an off-by-one error (in this case off by 1 day).
As mentioned, you should use a Date:: module to avoid fiddly details like different mth lengths and leap yrs.