每月计费周期的最佳模式

发布于 2024-10-25 11:55:38 字数 738 浏览 1 评论 0原文

我为我的新计费系统编写了一些代码。目的是在每月的同一天向客户开具账单。 (不是该月的第一天或最后一天)

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 个陷阱是:

  1. 如果他的 periodDate.Day 是 31 并且当前月份只有 29 天,
  2. cycleDate 是 2012 年 2 月 29 日 - 他只会在闰年计费

是否有一个共同点最佳实践在这里?

所以看起来有很多事情需要检查

  1. 这个帐户本月是否已经计费?
  2. 当前月份中是否存在周期日
  3. 周期日是否大于或等于当前日期(如果是,则这是理想的选择) 前一天交易失败)

谢谢!

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:

  1. If his cycleDate.Day is the 31 and the current month only has 29 days
  2. 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

  1. has this account already been billed this month?
  2. does the cycle day exists in the current month
  3. is the cycle day greater than or equal to the current date (this is ideal if
    the transaction failed the day before)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

压抑⊿情绪 2024-11-01 11:55:38

仅允许选择 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.

盗梦空间 2024-11-01 11:55:38

每个月的同一天是什么意思?

如果我是客户,我希望在每月 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?

握住你手 2024-11-01 11:55:38

我建议让他选择 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.

软甜啾 2024-11-01 11:55:38

好吧,我相信我完全想太多了
这很简单,涵盖了所有内容:

bool NeedToBill = ((DateTime.UTCNow – LastBillDate) >= 30 Days)

不一定会在同一天计费,但已经足够接近了。
如果事务被拒绝一天,或者计划任务在 1 天之内未运行,则下次运行时它将拾取它,这也增加了灵活性。

Ok, I believe I have been totally over-thinking this.
This is simple and covers everything:

bool NeedToBill = ((DateTime.UTCNow – LastBillDate) >= 30 Days)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文