Commit:    06658b4306535fc66190d71c3dcd3de60a0db588
Author:    Adam Harvey <[email protected]>         Mon, 27 Oct 2014 11:32:50 -0700
Parents:   7b010a93212b03861e8b41b56ae04c7568eb3d81
Branches:  master

Link:       
http://git.php.net/?p=web/php.git;a=commitdiff;h=06658b4306535fc66190d71c3dcd3de60a0db588

Log:
Tidy up the EOL page and move interval formatting to an include file.

Changed paths:
  M  eol.php
  M  include/branches.inc


Diff:
diff --git a/eol.php b/eol.php
index 8eca02b..2a3a110 100644
--- a/eol.php
+++ b/eol.php
@@ -38,41 +38,9 @@ site_header('Unsupported Branches');
                </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>
@@ -90,8 +58,8 @@ site_header('Unsupported Branches');
                                                        <?php echo 
isset($BRANCH_NOTES[$branch]) ? $BRANCH_NOTES[$branch] : ''; ?>
                                        </td>
                                </tr>
-                           <?php } ?>
-               <?php endforeach; ?>
+                       <?php endforeach ?>
+               <?php endforeach ?>
        </tbody>
 </table>
 
diff --git a/include/branches.inc b/include/branches.inc
index 385b2e4..03e47ed 100644
--- a/include/branches.inc
+++ b/include/branches.inc
@@ -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) {


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to