Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Jan 27, 2014
1 parent 2c24a50 commit cee72c5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 50 deletions.
Expand Up @@ -36,7 +36,7 @@ class HumanReadableTimeperiod extends AbstractHelper
protected $result;

/**
* A function for making timeperiods readable
* A function for making timeperiods human readable
* @method
* @return string
* @param
Expand All @@ -45,56 +45,67 @@ class HumanReadableTimeperiod extends AbstractHelper
public function __invoke($time, $format="short")
{

$this->result = "-";

$dateTime = date_create($time);
$timestamp = date_format($dateTime, 'U');

//$timestamp = date('u', strtotime($time));
$seconds = time() - $timestamp;

if($format == "short" && $time > 0) {

$units = array(
'y' => $seconds / 31556926 % 12,
'w' => $seconds / 604800 % 52,
'd' => $seconds / 86400 % 7,
'h' => $seconds / 3600 % 24,
'm' => $seconds / 60 % 60,
's' => $seconds % 60
);

foreach($units as $key => $value) {
if($value > 0) {
$res[] = $value . $key;
}
}

$this->result = join(' ', $res) . " ago";

}
elseif($format == "long" && $time > 0) {
if(empty($time)) {
$this->result = "-";
}
else {

$this->result = "-";
$dateTime = date_create($time);
$timestamp = date_format($dateTime, 'U');
$seconds = time() - $timestamp;

if($format == "short") {

$units = array(
'y' => $seconds / 31556926 % 12,
'w' => $seconds / 604800 % 52,
'd' => $seconds / 86400 % 7,
'h' => $seconds / 3600 % 24,
'm' => $seconds / 60 % 60,
's' => $seconds % 60
);

foreach($units as $key => $value) {
if($value > 0) {
$res[] = $value . $key;
}
}

$this->result = join(' ', $res) . " ago";

}
elseif($format == "long") {

$units = array(
'Year(s)' => $seconds / 31556926 % 12,
'Week(s)' => $seconds / 604800 % 52,
'Day(s)' => $seconds / 86400 % 7,
'Hour(s)' => $seconds / 3600 % 24,
'Minute(s)' => $seconds / 60 % 60,
'Second(s)' => $seconds % 60
);

foreach($units as $key => $value) {
if($value > 0) {
$res[] = $value . $key;
}
}

$this->result = join(' ', $res) . " ago";

}
elseif($format == "fuzzy") {

// TODO

$this->result = "~TODO ago";

}

$units = array(
'Year(s)' => $seconds / 31556926 % 12,
'Week(s)' => $seconds / 604800 % 52,
'Day(s)' => $seconds / 86400 % 7,
'Hour(s)' => $seconds / 3600 % 24,
'Minute(s)' => $seconds / 60 % 60,
'Second(s)' => $seconds % 60
);

foreach($units as $key => $value) {
if($value > 0) {
$res[] = $value . $key;
}
}

$this->result = join(' ', $res) . " ago";
return $this->result;

}

return $this->result;
}

}

Expand Down
2 changes: 1 addition & 1 deletion module/Client/view/client/client/details.phtml
Expand Up @@ -27,7 +27,7 @@ $this->headTitle($title);
<tr><td>Autoprune</td><td><?php echo $this->escapeHtml($client->autoprune); ?></td></tr>
<tr><td>Fileretention</td><td><?php echo $this->printRetention($client->fileretention) . " days"; ?></td></tr>
<tr><td>Jobretention</td><td><?php echo $this->printRetention($client->jobretention) . " days"; ?></td></tr>
<tr><td>Last successful backup</td><td><a href="<?php echo $this->url('job', array('action'=>'details', 'id' => $job->jobid)); ?>"><?php echo $this->printHumanReadableTimeperiod($job->endtime, "short")?> ago (Level: <?php echo $this->printJobLevel($job->level); ?>)</a></td></tr>
<tr><td>Last successful backup</td><td><a href="<?php echo $this->url('job', array('action'=>'details', 'id' => $job->jobid)); ?>"><?php echo $this->printHumanReadableTimeperiod($job->endtime, "short")?> (Level: <?php echo $this->printJobLevel($job->level); ?>)</a></td></tr>

</table>

Expand Down

0 comments on commit cee72c5

Please sign in to comment.