In my system, we make payments on day 10, 20 and 30 of all months. So, if I sell something on 05/Sep, I should get payed on 10/Sep. If I sell something in 31/Aug, I shoul开发者_如何转开发d get payed on 10/Sep, and so forth.
Do you have any suggestion on the algorithm?
Your specifications are incomplete, so the edge cases are unclear. Anyway, you can play with this:
date = Date.new(2010, 1, 4) # example input
day = ((date.day / 10) + 1) * 10
if day > Time.days_in_month(date.month, date.year)
Date.new(date.year, date.month, 10) + 1.month
else
Date.new(date.year, date.month, day)
end
精彩评论