Просмотр исходного кода

[ZF-7833] Zend_Date:

- added GNU support to get()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18093 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 лет назад
Родитель
Сommit
cf65484a1f
2 измененных файлов с 18 добавлено и 4 удалено
  1. 17 4
      library/Zend/Date.php
  2. 1 0
      tests/Zend/DateTest.php

+ 17 - 4
library/Zend/Date.php

@@ -194,7 +194,17 @@ class Zend_Date extends Zend_Date_DateObject
         if (($part !== null && $part !== self::TIMESTAMP) or (!is_numeric($date))) {
             // switch off dst handling for value setting
             $this->setUnixTimestamp($this->getGmtOffset());
+            $form = false;
+            if (self::$_options['format_type'] == 'php') {
+                $form = true;
+                self::$_options['format_type'] = 'iso';
+                $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
+            }
+
             $this->set($date, $part, $this->_locale);
+            if ($form) {
+                self::$_options['format_type'] = 'php';
+            }
 
             // DST fix
             if (is_array($date) === true) {
@@ -202,7 +212,7 @@ class Zend_Date extends Zend_Date_DateObject
                     $date['hour'] = 0;
                 }
 
-                $hour = $this->toString('H');
+                $hour = $this->toString('H', true);
                 $hour = $date['hour'] - $hour;
                 switch ($hour) {
                     case 1 :
@@ -315,7 +325,7 @@ class Zend_Date extends Zend_Date_DateObject
     {
         if ($stamp instanceof Zend_Date) {
             // extract timestamp from object
-            $stamp = $stamp->get(self::TIMESTAMP, true);
+            $stamp = $stamp->getTimestamp();
         }
 
         if (is_array($stamp)) {
@@ -450,7 +460,7 @@ class Zend_Date extends Zend_Date_DateObject
             $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
         }
 
-        return $this->get($format, $locale);
+        return $this->date($this->_toToken($format, $locale), $this->getUnixTimestamp(), false);
     }
 
     /**
@@ -517,13 +527,16 @@ class Zend_Date extends Zend_Date_DateObject
             $locale = $this->getLocale();
         }
 
-        if (($part !== null) && (strlen($part) !== 2) && (Zend_Locale::isLocale($part, null, false))) {
+        if (($part !== null) and !defined($part) and
+            ($part != 'ee') and ($part != 'ss') and Zend_Locale::isLocale($part, null, false)) {
             $locale = $part;
             $part = null;
         }
 
         if ($part === null) {
             $part = self::TIMESTAMP;
+        } else if (self::$_options['format_type'] == 'php') {
+            $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
         }
 
         return $this->date($this->_toToken($part, $locale), $this->getUnixTimestamp(), false);

+ 1 - 0
tests/Zend/DateTest.php

@@ -74,6 +74,7 @@ class Zend_DateTest extends PHPUnit_Framework_TestCase
         Zend_Date::setOptions(array('cache' => $this->_cache));
         Zend_Date::setOptions(array('fix_dst' => true));
         Zend_Date::setOptions(array('extend_month' => false));
+        Zend_Date::setOptions(array('format_type' => 'iso'));
     }
 
     public function tearDown()