企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
>[info] 判断日期是否符合范围 ~~~ /** * 主要用于筛选时间范围限制 * @param int $start 开始时间戳 * @param int $end 结束时间戳 * @param int $day 天数 * @param bool $isThrow 是否直接抛出异常 * @param string $text 自定义提示消息 * @return bool * @throws \yii\web\BadRequestHttpException */ public static function checkDayRange($start, $end, $day, $isThrow = true, $text = '') { $diff = $end - $start; if ($diff <= $day * 86400) { return true; } if ($isThrow) { $message = $text ?: sprintf("时间筛选范围不能超过%d天", $day); throw new BadRequestHttpException($message); } return false; } ~~~ * **示例:** ~~~ $startTime = strtotime(trim($paramItem['start_time'])); $endTime = strtotime(trim($paramItem['end_time']) . ' 23:59:59'); Helper::checkDayRange($startTime, $endTime, 90, true); ~~~