首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >5-4-4财政年度附表的数学计算

5-4-4财政年度附表的数学计算
EN

Stack Overflow用户
提问于 2018-09-25 02:02:25
回答 1查看 167关注 0票数 0

我正在试图计算财政年度,并返回日期,当它是一个星期的结束,在5-4-4的时间表。

例如,从1月1日开始的财政年度,我将返回日期5周,4周,和另外4周。然后重复5周,4周,4周直到财政年度结束,然后大概重新启动它。

你会如何从数学上或程序上着手做这件事?

我想出了一种减法,但想知道是否有人有更好的解决方案:

代码语言:javascript
复制
52 - 47 = 5    | February 5th, 2018
52 - 43 = 9    | March 5th, 2018
52 - 39 = 13   | April 2nd, 2018
52 - 34 = 18   | May 7th, 2018
52 - 30 = 22   | June 4th, 2018
52 - 26 = 26   | July 3rd, 2018
52 - 21 = 31   | August 7th, 2018
52 - 17 = 35   | September 4th, 2018
52 - 13 = 39   | October 2nd, 2018
52 - 8  = 44   | November 6th, 2018
52 - 4  = 48   | December 4th, 2018
52 - 0  = 52   | January 1st, 2019
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-27 21:02:27

最后我自己解决了这个问题。在网上找不到任何东西。

解决方案:我的算法最终使用减法,但修改了我的问题。

代码语言:javascript
复制
int[] pattern = {5, 4, 4}; // The week pattern
DateTime begin = new DateTime(2018, 1, 1);
DateTime currentDate = DateTime.Today; // 9-27-2018

// Get the total amount of weeks between the 2 days.  Add 1 for including the end day
var currentWeek = (currentDate.Date.Subtract(beginTime).TotalDays + 1) / 7;
var counter = 0;
while (currentWeek > 0)
{
    if (counter > 2)
    {
        counter = 0;
    }
    currentWeek = currentWeek - pattern[counter];
}    
return currentWeek == 0;

然后返回关于当前日期是否是5-4-4计划中某个时间段的结束的bool。在这种情况下,它将返回虚假的原因9-27-2018年不是一天在财政日历的期末以5-4-4模式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52489588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档