每月计费周期的最佳模式
我为我的新计费系统编写了一些代码。目的是在每月的同一天向客户开具账单。 (不是该月的第一天或最后一天)
static bool NeedToBill(DateTime planLastBilled, DateTime cycleDate)
{
// is today the same date as the cycleDate AND is was the planLastBilled not the same day as today?
if (DateTime.UtcNow.Day.Equals(cycleDate.Day) && !DateTime.UtcNow.Day.Equals(planLastBilled))
return true;
else
return false;
}
2 个陷阱是:
- 如果他的 periodDate.Day 是 31 并且当前月份只有 29 天,
- cycleDate 是 2012 年 2 月 29 日 - 他只会在闰年计费
是否有一个共同点最佳实践在这里?
所以看起来有很多事情需要检查
- 这个帐户本月是否已经计费?
- 当前月份中是否存在周期日
- 周期日是否大于或等于当前日期(如果是,则这是理想的选择) 前一天交易失败)
谢谢!
I wrote some code for my new billing system. The purpose is to bill the customer on the same day each month. (not the 1st or last day of the month)
static bool NeedToBill(DateTime planLastBilled, DateTime cycleDate)
{
// is today the same date as the cycleDate AND is was the planLastBilled not the same day as today?
if (DateTime.UtcNow.Day.Equals(cycleDate.Day) && !DateTime.UtcNow.Day.Equals(planLastBilled))
return true;
else
return false;
}
The 2 pitfalls are:
- If his cycleDate.Day is the 31 and the current month only has 29 days
- cycleDate is Feb 29 2012 - he will only get billed on leap years
Is there a common best practice here?
so it seems like there's a bunch things to check
- has this account already been billed this month?
- does the cycle day exists in the current month
- is the cycle day greater than or equal to the current date (this is ideal if
the transaction failed the day before)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
仅允许选择 1 - 28 之间的结算日。根据我的经验,这是大多数信用卡/贷款公司在有选择时的处理方式。
Only allow the choice of a billing day between 1 - 28. In my experience this is how most credit card / loan companies deal with it when given a choice.
每个月的同一天是什么意思?
如果我是客户,我希望在每月 16 日收到账单。没问题。如果我想在每月 31 日计费,那么明显的问题是并非所有月份都有 31 天,正如您在问题中指出的那样。
为什么不检查当前月份的天数。如果少于 31 天,则将该月的最后一天作为帐单日期。
还有更多的问题吗?
What does the same day each month mean?
If I am a customer, I want to be billed on the 16th each month. No problem. If I want to be billed on the 31st on each month the obvious issue is not all months have 31 days as you've pointed out in your question.
Why not check the current month for the number of days. If it has less than 31 days, make the last day of the month the bill date.
Is there more to the problem?
我建议让他选择 1-28 之间,或者任何一天,但如果当前月份的天数少于所选日期,则在该月的最后一天收费。
I'd say make him choose between 1-28, or any day but charge on the last day on the month if the current month has less days than the chosen day of month.
好吧,我相信我完全想太多了。
这很简单,涵盖了所有内容:
不一定会在同一天计费,但已经足够接近了。
如果事务被拒绝一天,或者计划任务在 1 天之内未运行,则下次运行时它将拾取它,这也增加了灵活性。
Ok, I believe I have been totally over-thinking this.
This is simple and covers everything:
It will not necessarily bill on the exact same day, however it's close enough.
This also adds flexibility if the transaction was denied for a day, or if the scheduled task was not ran for 1 day the next time it runs it will pick it up.