note 108076 deleted from dateinterval.format by danbrown

From: Date: Tue, 27 Mar 2012 15:33:18 +0000
Subject: note 108076 deleted from dateinterval.format by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186847@lists.php.net to get a copy of this message
Note Submitter: lxg ---- @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; } ?>

« previous php.notes (#186847) next »