diff --git a/module/holiday/model.php b/module/holiday/model.php index b56566483d..bf9047069d 100644 --- a/module/holiday/model.php +++ b/module/holiday/model.php @@ -275,13 +275,14 @@ class holidayModel extends model } /** + * 判断一天是否是工作日。 * Judge if is working days. * * @param string $date * @access public * @return bool */ - public function isWorkingDay($date) + public function isWorkingDay(string $date): bool { $record = $this->dao->select('*')->from(TABLE_HOLIDAY) ->where('type')->eq('working') diff --git a/module/holiday/test/holiday.class.php b/module/holiday/test/holiday.class.php index d0996daf16..81dbc85823 100644 --- a/module/holiday/test/holiday.class.php +++ b/module/holiday/test/holiday.class.php @@ -233,19 +233,21 @@ class holidayTest } /** - * Test isWorkingDay method. + * 测试某天是否是工作日。 + * Test judge if is a working day. * - * @param string $date + * @param string $date * @access public - * @return object + * @return string|array */ - public function isWorkingDayTest($date) + public function isWorkingDayTest(string $date): string|array { + $date = !empty($date) ? date('Y-m-d', strtotime($date)) : '0000-00-00'; $objects = $this->objectModel->isWorkingDay($date); if(dao::isError()) return dao::getError(); - return $objects; + return $objects === true ? 'It is a working day' : 'It is not a working day'; } /** diff --git a/module/holiday/test/model/isworkingday.php b/module/holiday/test/model/isworkingday.php index 6d17dd89e4..de3514ae63 100755 --- a/module/holiday/test/model/isworkingday.php +++ b/module/holiday/test/model/isworkingday.php @@ -1,7 +1,12 @@ #!/usr/bin/env php gen(10); +zdTable('user')->gen(1); + su('admin'); /** @@ -17,8 +22,8 @@ pid=1 */ $holiday = new holidayTest(); -$date = array('2022-03-01', '2022-04-09', '2002-2-2'); +$date = array('-1 month', '-1 month +3 day', ''); -r($holiday->isWorkingDayTest($date[0])) && p() && e('0'); // 测试不是工作日 -r($holiday->isWorkingDayTest($date[1])) && p() && e('1'); // 测试是工作日 -r($holiday->isWorkingDayTest($date[2])) && p() && e('0'); // 测试日期格式不对 \ No newline at end of file +r($holiday->isWorkingDayTest($date[0])) && p() && e('It is not a working day'); // 测试不是工作日 +r($holiday->isWorkingDayTest($date[1])) && p() && e('It is a working day'); // 测试是工作日 +r($holiday->isWorkingDayTest($date[2])) && p() && e('It is not a working day'); // 测试日期格式不对