note 108076 added to dateinterval.format

From: Date: Tue, 27 Mar 2012 10:08:26 +0000
Subject: note 108076 added to dateinterval.format
Groups: php.notes 
Request: Send a blank email to php-notes+get-186833@lists.php.net to get a copy of this message
@kuzb 04-Feb-2011 05:15 The to_seconds() method has several bugs. For one, as is stated correctly, you cannot use months and years to calculate a number of seconds. Luckily, the DateInterval instance provides the days property, holding the absolute number of days. Secondly, that to_seconds() method doesn't add minutes. Here's a corrected implementation (as a simple function): <?php function diffToSeconds(\DateInterval $diff) { $diffSeconds = (int)$diff->days * 86400 + $diff->h * 3600 + $diff->i * 60 + $diff->s; if ($diff->invert) $diffSeconds *= -1; return $diffSeconds; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 89.0.9.46 ---- Manual Page -- http://www.php.net/manual/en/dateinterval.format.php Edit -- https://master.php.net/note/edit/108076 Del: integrated -- https://master.php.net/note/delete/108076/integrated Del: useless -- https://master.php.net/note/delete/108076/useless Del: bad code -- https://master.php.net/note/delete/108076/bad+code Del: spam -- https://master.php.net/note/delete/108076/spam Del: non-english -- https://master.php.net/note/delete/108076/non-english Del: in docs -- https://master.php.net/note/delete/108076/in+docs Del: other reasons-- https://master.php.net/note/delete/108076 Reject -- https://master.php.net/note/reject/108076 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186833) next »