Search code examples
phpzend-frameworkzend-date

Zend Date Weirdness - Missing Configuration?


I'm getting odd output from the getDate() function. It's supposed to return a date without the time parts, but I am getting time parts. Am I missing some configuration option that would correct this?

Sample Code:

date_default_timezone_set('America/New_York');
$date = new Zend_Date(array(
    'year' => 2010,
    'month' => 3,
    'day' => 29,
));
echo $date->getIso() . PHP_EOL;
echo $date->getDate()->getIso() . PHP_EOL;

Output:

2010-03-29T00:00:00-04:00
2010-03-29T23:00:00-04:00

Solution

  • This isn't really an answer to my question, but this is my workaround. I have extended the Zend_Date class as follows:

    class My_Date extends Zend_Date
    {
        public static function now($locale = null)
        {
            return new My_Date(time(), self::TIMESTAMP, $locale);
        }
    
        /**
         * set to the first second of current day
         */
        public function setDayStart()
        {
            return $this->setHour(0)->setMinute(0)->setSecond(0);
        }
    
        /**
         * get the first second of current day
         */
        public function getDayStart()
        {
            $clone = clone $this;
            return $clone->setDayStart();
        }
    }