Skip to content

Commit

Permalink
Fix: Do not pass null to function that expects DateTime or string (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored Dec 6, 2023
1 parent 019de1f commit 2b70836
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eol.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<?php foreach (get_eol_branches() as $major => $branches): ?>
<?php foreach ($branches as $branch => $detail): ?>
<?php $eolDate = get_branch_security_eol_date($branch) ?>
<?php $eolPeriod = format_interval($eolDate, null) ?>
<?php $eolPeriod = format_interval($eolDate, new DateTime('now')) ?>
<tr>
<td><?php echo htmlspecialchars($branch); ?></td>
<td>
Expand Down
5 changes: 2 additions & 3 deletions include/branches.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ $BRANCHES = [
* page. (Currently 28 days.) */
$KEEP_EOL = new DateInterval('P28D');

function format_interval($from, $to) {
function format_interval($from, DateTime $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);
$diff = $to->diff($from_obj);

$times = [];
if ($diff->y) {
Expand Down
7 changes: 4 additions & 3 deletions supported-versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
$initial = get_branch_release_date($branch);
$until = get_branch_bug_eol_date($branch);
$eol = get_branch_security_eol_date($branch);
$now = new DateTime('now');
?>
<tr class="<?php echo $state ?>">
<td>
Expand All @@ -63,11 +64,11 @@
<?php endif ?>
</td>
<td><?php echo htmlspecialchars($initial->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($initial, null)) ?></em></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($initial, $now)) ?></em></td>
<td><?php echo htmlspecialchars($until->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($until, null)) ?></em></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($until, $now)) ?></em></td>
<td><?php echo htmlspecialchars($eol->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($eol, null)) ?></em></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($eol, $now)) ?></em></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
Expand Down

0 comments on commit 2b70836

Please sign in to comment.