|
|
@ -12,6 +12,7 @@ namespace Mage; |
|
|
|
|
|
|
|
|
|
|
|
use Mage\Runtime\Runtime; |
|
|
|
use Mage\Runtime\Runtime; |
|
|
|
use DateTime; |
|
|
|
use DateTime; |
|
|
|
|
|
|
|
use DateInterval; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Utility class for resolving trivial operations |
|
|
|
* Utility class for resolving trivial operations |
|
|
@ -81,44 +82,47 @@ class Utils |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function getTimeDiff(DateTime $releaseDate) |
|
|
|
public function getTimeDiff(DateTime $releaseDate) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$textDiff = ''; |
|
|
|
|
|
|
|
$now = new DateTime(); |
|
|
|
$now = new DateTime(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var DateInterval $diff */ |
|
|
|
$diff = $now->diff($releaseDate); |
|
|
|
$diff = $now->diff($releaseDate); |
|
|
|
|
|
|
|
|
|
|
|
if ($diff->format('%a') <= 7) { |
|
|
|
if ($diff->days > 7) { |
|
|
|
if ($diff->format('%d') == 7) { |
|
|
|
return ''; |
|
|
|
$textDiff = 'a week ago'; |
|
|
|
} |
|
|
|
} elseif ($diff->format('%d') > 0 && $diff->format('%d') < 7) { |
|
|
|
|
|
|
|
$days = $diff->format('%d'); |
|
|
|
if ($diff->days == 7) { |
|
|
|
if ($days <= 1) { |
|
|
|
return 'a week ago'; |
|
|
|
$textDiff = 'one day ago'; |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
$textDiff = $days . ' days ago'; |
|
|
|
if ($diff->days > 1) { |
|
|
|
} |
|
|
|
return sprintf('%d days ago', $diff->days); |
|
|
|
} elseif ($diff->format('%d') == 0 && $diff->format('%h') > 0) { |
|
|
|
} |
|
|
|
$hours = $diff->format('%h'); |
|
|
|
|
|
|
|
if ($hours <= 1) { |
|
|
|
if ($diff->days == 1) { |
|
|
|
$textDiff = 'one hour ago'; |
|
|
|
return 'one day ago'; |
|
|
|
} else { |
|
|
|
} |
|
|
|
$textDiff = $hours . ' hours ago'; |
|
|
|
|
|
|
|
} |
|
|
|
if ($diff->h > 1) { |
|
|
|
} elseif ($diff->format('%d') == 0 && $diff->format('%h') == 0 && $diff->format('%i') > 0) { |
|
|
|
return sprintf('%d hours ago', $diff->h); |
|
|
|
$minutes = $diff->format('%i'); |
|
|
|
} |
|
|
|
if ($minutes == 1) { |
|
|
|
|
|
|
|
$textDiff = 'one minute ago'; |
|
|
|
if ($diff->h == 1) { |
|
|
|
} else { |
|
|
|
return 'one hour ago'; |
|
|
|
$textDiff = $minutes . ' minutes ago'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} elseif ($diff->format('%d') == 0 && $diff->format('%h') == 0 && $diff->format('%i') == 0) { |
|
|
|
if ($diff->i > 1) { |
|
|
|
$seconds = $diff->format('%s'); |
|
|
|
return sprintf('%d minutes ago', $diff->i); |
|
|
|
if ($seconds < 10) { |
|
|
|
} |
|
|
|
$textDiff = 'just now'; |
|
|
|
|
|
|
|
} else { |
|
|
|
if ($diff->i == 1) { |
|
|
|
$textDiff = $seconds . ' seconds ago'; |
|
|
|
return 'one minute ago'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($diff->s >= 10) { |
|
|
|
|
|
|
|
return sprintf('%d seconds ago', $diff->s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $textDiff; |
|
|
|
return 'just now'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|