当您向函数传递一个空参数或参数中包含的日期字符串的周、期和年时,我希望使用该函数来确定当前的会计周期间和年。
到目前为止,我有一个类似这样的函数。
function FiscalDates($date){
$basedate=date_create("2018-04-29");
$querydate=date_create($date);
$diff=date_diff($basedate,$querydate);
$days = $diff->format('%a');
if(fmod($days,7)==0){
$weekno = ($days/7)+1;
} else {
$weekno = ceil($days/7);
}
if(fmod($weekno,4)==0){
$period = ($weekno/4);
} else {
$period = ceil($weekno/4);
}
if(fmod($period,13)==0){
$year = ($period/13)-1;
} else {
$year = (ceil($period/13))-1;
}
$period = $period-(13*$year);
$year = $year+2018;
return array($weekno,$period,$year);
}这在很大程度上是有效的,但唯一的问题是,它没有考虑到每5-6年发生一次的“闰周”。(一年中有53周) see 2nd paragraph of this page about that。每次发生这种情况,计算都会推迟一周。
我如何才能实现类似的事情,而又能计算出一年中的53周并保持准确?
发布于 2020-01-14 18:21:07
可能太晚了,或者不是直接回复,但几年前在英国的一家企业遇到了类似的问题,所以决定建立一个对你有帮助的库。
https://github.com/RoussKS/financial-year
它可以在一个财政年度内获得周期/周。它处理两种类型的财政年度。标准的12个月(周期),命名为calendar作为图书馆约定,business为13个周期的财政年度( 52/53周)。Business是你想要使用的。
它不会检查一年何时应该是53周的一年,因为这取决于业务,所以你需要提供一个参数(默认为false又名52)。
用于获取句号&周的示例
require_once __DIR__ . '/vendor/autoload.php';
// DateTimeAdapter
// If instantiating with string, it must be of ISO-8601 format 'YYYY-MM-DD'.
// This is your business's financial year start date.
$startDate = new \DateTime('2018-04-01');
$fy = new \RoussKS\FinancialYear\DateTimeAdapter('business', $startDate, false); // false for 52 weeks, true for 53 weeks
$dateToExamine = '2018-04-29';
// Get period of the date in question
echo $fy->getPeriodIdByDate($dateToExamine); // 1
// Get week of the date in question
echo $fy->getBusinessWeekIdIdByDate($dateToExamine); // 5虽然不确定你所说的年份是什么意思,但这是不是就像是按照2018/2019来命名年份一样?
https://stackoverflow.com/questions/59093077
复制相似问题