note 112601 added to dateinterval.format

From: Date: Wed, 03 Jul 2013 10:13:58 +0000
Subject: note 112601 added to dateinterval.format
Groups: php.notes 
Request: Send a blank email to php-notes+get-195444@lists.php.net to get a copy of this message
German Version of formatDateDiff: function formatDateDiff($start, $end=null) { if(!($start instanceof DateTime)) { $start = new DateTime($start); } if($end === null) { $end = new DateTime(); } if(!($end instanceof DateTime)) { $end = new DateTime($start); } $interval = $end->diff($start); $doPlural = function($nb,$str){ if ($nb > 1) { switch ($str) { case 'Jahr': case 'Monat': case 'Tag': return $str.'e'; case 'Stunde': case 'Minute': case 'Sekunde': return $str.'n'; } } else return $str; }; // adds plurals $format = array(); if($interval->y !== 0) { $format[] = "%y ".$doPlural($interval->y, "Jahr"); } if($interval->m !== 0) { $format[] = "%m ".$doPlural($interval->m, "Monat"); } if($interval->d !== 0) { $format[] = "%d ".$doPlural($interval->d, "Tag"); } if($interval->h !== 0) { $format[] = "%h ".$doPlural($interval->h, "Stunde"); } if($interval->i !== 0) { $format[] = "%i ".$doPlural($interval->i, "Minute"); } if($interval->s !== 0) { $format[] = "%s ".$doPlural($interval->s, "Sekunde"); } if(count($format)==0 || (count($format)==1 && $interval->s !== 0)) { return "weniger als eine Minute"; } // We use the two biggest parts if(count($format) > 1) { $format = array_shift($format).", ".array_shift($format); } else { $format = array_pop($format); } // Prepend 'since ' or whatever you like return $interval->format($format); } ---- Server IP: 69.147.83.199 Probable Submitter: 85.158.139.107 (proxied: 62.218.134.30) ---- Manual Page -- http://php.net/manual/en/dateinterval.format.php Edit -- https://master.php.net/note/edit/112601 Del: integrated -- https://master.php.net/note/delete/112601/integrated Del: useless -- https://master.php.net/note/delete/112601/useless Del: bad code -- https://master.php.net/note/delete/112601/bad+code Del: spam -- https://master.php.net/note/delete/112601/spam Del: non-english -- https://master.php.net/note/delete/112601/non-english Del: in docs -- https://master.php.net/note/delete/112601/in+docs Del: other reasons-- https://master.php.net/note/delete/112601 Reject -- https://master.php.net/note/reject/112601 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195444) next »