开发者

How to choose the best payment day from 3 pre-determined choices?

开发者 https://www.devze.com 2023-04-03 02:23 出处:网络
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 o

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
0

精彩评论

暂无评论...
验证码 换一张
取 消