Skip to content

Commit

Permalink
Tidy up the EOL page and move interval formatting to an include file.
Browse files Browse the repository at this point in the history
  • Loading branch information
LawnGnome committed Oct 27, 2014
1 parent 7b010a9 commit 06658b4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
42 changes: 5 additions & 37 deletions eol.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,9 @@
</tr>
</thead>
<tbody>
<?php foreach (get_eol_branches() as $major => $branches):

foreach ($branches as $branch => $detail) {
try {
$now = new DateTime;
$then = new DateTime('@'.$detail['date']);
$diff = $now->diff($then);
$times = array();
if ($diff->y) {
$times[] = array($diff->y,'year');
if ($diff->m) {
$times[] = array($diff->m,'month');
}
} elseif ($diff->m) {
$times[] = array($diff->m,'month');
} elseif ($diff->d) {
$times[] = array($diff->d,'day');
} else {
$eolPeriod = 'moments ago...';
}
if ($times) {
$eolPeriod = implode(', ',
array_map(
function($t) {
return "$t[0] $t[1]" .
($t[0] != 1 ? 's' : '');
},
$times
)
) . " ago";
}
} catch(Exception $e) {
$eolPeriod = 'unknown...';
}
?>
<?php foreach (get_eol_branches() as $major => $branches): ?>
<?php foreach ($branches as $branch => $detail): ?>
<?php $eolPeriod = format_interval('@'.$detail['date'], null) ?>
<tr>
<td><?php echo htmlspecialchars($branch); ?></td>
<td>
Expand All @@ -90,8 +58,8 @@ function($t) {
<?php echo isset($BRANCH_NOTES[$branch]) ? $BRANCH_NOTES[$branch] : ''; ?>
</td>
</tr>
<?php } ?>
<?php endforeach; ?>
<?php endforeach ?>
<?php endforeach ?>
</tbody>
</table>

Expand Down
43 changes: 43 additions & 0 deletions include/branches.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/releases.inc';
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/version.inc';

function format_interval($from, $to) {
try {
$from_obj = $from instanceof DateTime ? $from : new DateTime($from);
$to_obj = $to instanceof DateTime ? $to : new DateTime($to);
$diff = $to_obj->diff($from_obj);

$times = array();
if ($diff->y) {
$times[] = array($diff->y,'year');
if ($diff->m) {
$times[] = array($diff->m,'month');
}
} elseif ($diff->m) {
$times[] = array($diff->m,'month');
} elseif ($diff->d) {
$times[] = array($diff->d,'day');
} else {
$eolPeriod = 'today';
}
if ($times) {
$eolPeriod = implode(', ',
array_map(
function($t) {
return "$t[0] $t[1]" .
($t[0] != 1 ? 's' : '');
},
$times
)
);

if ($diff->invert) {
$eolPeriod = "$eolPeriod ago";
} else {
$eolPeriod = "in $eolPeriod";
}
}
} catch(Exception $e) {
$eolPeriod = 'unknown';
}

return $eolPeriod;
}

function version_number_to_branch($version) {
$parts = explode('.', $version);
if (count($parts) > 1) {
Expand Down

0 comments on commit 06658b4

Please sign in to comment.