mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
2.9 KiB
129 lines
2.9 KiB
8 years ago
|
<?php
|
||
|
/*
|
||
|
* This file is part of the Magallanes package.
|
||
|
*
|
||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
|
*/
|
||
|
|
||
|
namespace Mage;
|
||
|
|
||
8 years ago
|
use Mage\Runtime\Runtime;
|
||
8 years ago
|
use DateTime;
|
||
8 years ago
|
use DateInterval;
|
||
8 years ago
|
|
||
|
/**
|
||
|
* Utility class for resolving trivial operations
|
||
|
*
|
||
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||
|
*/
|
||
|
class Utils
|
||
|
{
|
||
|
/**
|
||
|
* Given a stage code it will resolve a human friendly name
|
||
|
*
|
||
|
* @param string $stage
|
||
|
* @return string
|
||
|
*/
|
||
8 years ago
|
public function getStageName($stage)
|
||
8 years ago
|
{
|
||
|
switch ($stage) {
|
||
8 years ago
|
case Runtime::PRE_DEPLOY:
|
||
8 years ago
|
return 'Pre Deploy';
|
||
8 years ago
|
break;
|
||
|
|
||
8 years ago
|
case Runtime::ON_DEPLOY:
|
||
8 years ago
|
return 'On Deploy';
|
||
8 years ago
|
break;
|
||
|
|
||
8 years ago
|
case Runtime::POST_DEPLOY:
|
||
8 years ago
|
return 'Post Deploy';
|
||
8 years ago
|
break;
|
||
|
|
||
8 years ago
|
case Runtime::ON_RELEASE:
|
||
8 years ago
|
return 'On Release';
|
||
|
break;
|
||
|
|
||
8 years ago
|
case Runtime::POST_RELEASE:
|
||
8 years ago
|
return 'Post Release';
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return $stage;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Given a Release ID, convert it to a DateTime instance
|
||
|
*
|
||
|
* @param string $releaseId The Release ID
|
||
|
* @return DateTime
|
||
|
*/
|
||
8 years ago
|
public function getReleaseDate($releaseId)
|
||
8 years ago
|
{
|
||
|
$formatted = sprintf('%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d',
|
||
8 years ago
|
$releaseId[0], $releaseId[1], $releaseId[2], $releaseId[3],
|
||
8 years ago
|
$releaseId[4], $releaseId[5],
|
||
|
$releaseId[6], $releaseId[7],
|
||
|
$releaseId[8], $releaseId[9],
|
||
|
$releaseId[10], $releaseId[11],
|
||
8 years ago
|
$releaseId[12], $releaseId[13]
|
||
|
);
|
||
8 years ago
|
|
||
|
return new DateTime($formatted);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Given a Date, calculate friendly how much time has passed
|
||
|
*
|
||
|
* @param DateTime $releaseDate
|
||
|
* @return string
|
||
|
*/
|
||
8 years ago
|
public function getTimeDiff(DateTime $releaseDate)
|
||
8 years ago
|
{
|
||
|
$now = new DateTime();
|
||
8 years ago
|
|
||
|
/** @var DateInterval $diff */
|
||
8 years ago
|
$diff = $now->diff($releaseDate);
|
||
8 years ago
|
|
||
8 years ago
|
if ($diff->days > 7) {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
if ($diff->days == 7) {
|
||
|
return 'a week ago';
|
||
|
}
|
||
|
|
||
|
if ($diff->days > 1) {
|
||
|
return sprintf('%d days ago', $diff->days);
|
||
|
}
|
||
|
|
||
|
if ($diff->days == 1) {
|
||
|
return 'one day ago';
|
||
|
}
|
||
|
|
||
|
if ($diff->h > 1) {
|
||
|
return sprintf('%d hours ago', $diff->h);
|
||
|
}
|
||
|
|
||
|
if ($diff->h == 1) {
|
||
|
return 'one hour ago';
|
||
|
}
|
||
|
|
||
|
if ($diff->i > 1) {
|
||
|
return sprintf('%d minutes ago', $diff->i);
|
||
|
}
|
||
|
|
||
|
if ($diff->i == 1) {
|
||
|
return 'one minute ago';
|
||
|
}
|
||
|
|
||
|
if ($diff->s >= 10) {
|
||
|
return sprintf('%d seconds ago', $diff->s);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
return 'just now';
|
||
8 years ago
|
}
|
||
|
}
|