Skip to content

Commit

Permalink
增加两个时间的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
lujiang committed Apr 4, 2019
1 parent ea75ae4 commit 0b00038
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/basic/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DateHelper
{
/**
* 获取两个时间点之间所有的日期
*
*
* @param string $startDate
* @param string $endDate
*
Expand All @@ -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;
}

/**
* 返回本周开始和结束的时间戳
*
Expand Down

0 comments on commit 0b00038

Please sign in to comment.