diff --git a/module/holiday/model.php b/module/holiday/model.php index cefcb29c62..8801dff47b 100644 --- a/module/holiday/model.php +++ b/module/holiday/model.php @@ -236,21 +236,22 @@ class holidayModel extends model } /** - * Get diff days. + * 获取开始和结束日期间的日期。 + * Get the dates between the begin and end. * * @param string $begin * @param string $end * @access public - * @return bool + * @return array */ - public function getDaysBetween($begin, $end) + public function getDaysBetween(string $begin, string $end): array { $beginTime = strtotime($begin); $endTime = strtotime($end); $days = ($endTime - $beginTime) / 86400; $dateList = array(); - for($i = 0; $i <= $days; $i ++) $dateList[] = date('Y-m-d', strtotime("+$i days", $beginTime)); + for($i = 0; $i <= $days; $i ++) $dateList[] = date('Y-m-d', strtotime("+{$i} days", $beginTime)); return $dateList; } diff --git a/module/holiday/test/holiday.class.php b/module/holiday/test/holiday.class.php index e74f865ef9..df0e081305 100644 --- a/module/holiday/test/holiday.class.php +++ b/module/holiday/test/holiday.class.php @@ -197,14 +197,15 @@ class holidayTest } /** - * Test getDaysBetweenTest method. + * 测试获取开始和结束日期之间的日期。 + * Test get the dates between the begin and end. * * @param string $begin * @param string $end * @access public - * @return int + * @return int|array */ - public function getDaysBetweenTest($begin, $end) + public function getDaysBetweenTest(string $begin, string $end): int|array { $objects = $this->objectModel->getDaysBetween($begin, $end); diff --git a/module/holiday/test/model/getdaysbetween.php b/module/holiday/test/model/getdaysbetween.php index 0590a038b9..79dc2f5720 100755 --- a/module/holiday/test/model/getdaysbetween.php +++ b/module/holiday/test/model/getdaysbetween.php @@ -1,5 +1,6 @@ #!/usr/bin/env php getDaysBetweenTest('2022-04-01', '2022-04-21')) && p() && e('21'); r($holiday->getDaysBetweenTest('2022-05-23', '2022-05-30')) && p() && e('8'); //返回2022-05-23到2022-05-30之间的天数 r($holiday->getDaysBetweenTest('2021-01-01', '2022-01-01')) && p() && e('366'); //测试传入一间隔一整年的两天 r($holiday->getDaysBetweenTest('2022-05-07', '2022-05-08')) && p() && e('2'); //返回2022-05-07到2022-05-08之间的天数 -r($holiday->getDaysBetweenTest('2022-05-07', '2022-05-07')) && p() && e('1'); //测试传入同一天的情况 \ No newline at end of file +r($holiday->getDaysBetweenTest('2022-05-07', '2022-05-07')) && p() && e('1'); //测试传入同一天的情况