Helpers.php
795 Bytes
<?php
if (!function_exists('data_diff')) {
/**
* Get the active class if the condition is not falsy
*
* @param $condition
* @param string $activeClass
* @param string $inactiveClass
*
* @return string
*/
function data_diff($origin, $target) {
$origin = new DateTime($origin);
$target = new DateTime($target);
$interval = $origin->diff($target);
$y = $interval->format("%y");
$m = $interval->format("%m");
$d = $interval->format("%d");
$limit = '';
if (!empty($y)) {$limit .= "{$y}年";}
if (!empty($m)) {$limit .= "{$m}个月";}
if (!empty($d)) {$limit .= "{$d}天";}
return $limit;
}
}