Browse Source

Show how much time ago was the release.

1.0
Andrés Montañez 12 years ago
parent
commit
ad6f3cb6ee
  1. 52
      Mage/Task/BuiltIn/Releases/List.php

52
Mage/Task/BuiltIn/Releases/List.php

@ -51,11 +51,13 @@ class Mage_Task_BuiltIn_Releases_List
if ($currentRelease == $release) { if ($currentRelease == $release) {
$isCurrent = ' <- current'; $isCurrent = ' <- current';
} }
$dateDiff = $this->_dateDiff($releaseDate);
Mage_Console::output( Mage_Console::output(
'Release: <purple>' . $release . '</purple> ' 'Release: <purple>' . $release . '</purple> '
. '- Date: <dark_gray>' . $releaseDate . '</dark_gray> ' . '- Date: <dark_gray>' . $releaseDate . '</dark_gray> '
. '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>' . $isCurrent, 2); . '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>' . $dateDiff . $isCurrent, 2);
} }
} }
@ -67,5 +69,53 @@ class Mage_Task_BuiltIn_Releases_List
return false; return false;
} }
} }
private function _dateDiff($releaseDate)
{
$textDiff = '';
$releaseDate = new DateTime($releaseDate);
$now = new DateTime();
$diff = $now->diff($releaseDate);
if ($diff->format('%a') <= 7) {
if ($diff->format('%d') == 7) {
$textDiff = ' [a week ago] ';
} else if ($diff->format('%d') > 0 && $diff->format('%d') < 7) {
$days = $diff->format('%d');
if ($days <= 1) {
$textDiff = ' [one day ago] ';
} else {
$textDiff = ' [' . $days . ' days ago] ';
}
} else if ($diff->format('%d') == 0 && $diff->format('%h') > 0) {
$hours = $diff->format('%h');
if ($hours <= 1) {
$textDiff = ' [one hour ago] ';
} else {
$textDiff = ' [' . $hours . ' hours ago] ';
}
} else if ($diff->format('%d') == 0 && $diff->format('%h') == 0) {
$minutes = $diff->format('%i');
if ($minutes <= 1) {
$textDiff = ' [one minute ago] ';
} else {
$textDiff = ' [' . $minutes . ' minutes ago] ';
}
} else if ($diff->format('%d') == 0 && $diff->format('%h') == 0 && $diff->format('%i') == 0) {
$seconds = $diff->format('%s');
if ($seconds < 10) {
$textDiff = ' [just now!] ';
} else {
$textDiff = ' [' . $seconds . ' seconds ago] ';
}
}
}
return $textDiff;
}
} }
Loading…
Cancel
Save