From 0b0003857261fc206be4ac4463eebff923334ce5 Mon Sep 17 00:00:00 2001 From: lujiang Date: Thu, 4 Apr 2019 10:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=A4=E4=B8=AA=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/basic/DateHelper.php | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/basic/DateHelper.php b/src/basic/DateHelper.php index 4cc4648..2ffb5a4 100644 --- a/src/basic/DateHelper.php +++ b/src/basic/DateHelper.php @@ -13,7 +13,7 @@ class DateHelper { /** * 获取两个时间点之间所有的日期 - * + * * @param string $startDate * @param string $endDate * @@ -36,6 +36,53 @@ public static function getDateFromRange(string $startDate, string $endDate) :arr return $date; } + /** + * 判断两个时间段之间是否有交叉(边界相等也算交叉) + * @param string $periodOneStart + * @param string $periodOneEnd + * @param string $periodTwoStart + * @param string $periodTwoEnd + * + * @return bool + */ + public function isCross($periodOneStart = '', $periodOneEnd = '', $periodTwoStart = '', $periodTwoEnd = '') :bool + { + $status = $periodTwoStart - $periodOneStart; + + if ($status > 0) { + $status2 = $periodTwoStart - $periodOneEnd; + if ($status2 > 0) { + return false; + } else { + return true; + } + } else { + $status2 = $periodTwoEnd - $periodOneStart; + if ($status2 >= 0) { + return true; + } else { + return false; + } + } + } + + /** + * 将H:i 格式的时间转换成秒 + * @param string $hourMinute + * + * @return int + */ + public static function getMinute(string $hourMinute) :int + { + list($hour,$minute) = explode(':',$hourMinute); + + if (empty($hour) || empty($minute)) { + return 0; + } + + return $hour*60+$minute; + } + /** * 返回本周开始和结束的时间戳 *