Issues

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

Issue Type: New Feature Created: 2008-05-14T11:49:42.000+0000 Last Updated: 2012-11-20T21:37:46.000+0000 Status: Open Fix version(s): Reporter: Thomas Weidner (thomas) Assignee: None Tags: - Zend_Date

Related issues: Attachments:

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

Posted by Maxence Delannoy (mdelanno) on 2009-05-03T09:16:20.000+0000

My solution :

<pre class="highlight">
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.

Posted by Konstantin.Myakshin (koc) on 2010-05-19T17:39:17.000+0000

what about to implement this method in next minior release?

Posted by Jorge Padron (jpadron) on 2010-05-20T05:18:18.000+0000

+1

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts