ZF-3260: Add a function/functionset to calculate differences

Description

Add a function or multiple functions to calculate the difference between two date objects or date strings. The returned datepart should be selectable.

f.e.:

$date->getDifference($date2, Zend_Date::MINUTES); $date->getDifference($date2, Zend_Date::SECONDS); and so on...

Comments

My solution :


public function getDifference(Zend_Date $date, $part = Zend_Date::SECOND)
{
    $dividers = array(
        Zend_Date::SECOND => 1,
        Zend_Date::MINUTE => 60,
        Zend_Date::HOUR => 3600,
        Zend_Date::DAY => 86400
    );
    if (!isset($dividers[$part])) {
        throw new Zend_Date_Exception('Bad part value');
    }

    $diff = $this->getTimestamp() - $date->getTimestamp();
    if (self::$_options['fix_dst']) {
        $diff += ($this->get(Zend_Date::DAYLIGHT) - $date->get(Zend_Date::DAYLIGHT)) * 3600;
    }

    return $diff / $dividers[$part];
}

Note: $_options is a static property of Zend_Date, there is no method to access it from a derived class.

what about to implement this method in next minior release?

+1