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

Merge pull request #387 from storeman/fix-289

Fixes 289 - Zend_Date milliseconds bug
Frank Brückner 11 лет назад
Родитель
Сommit
efa61af7ea
1 измененных файлов с 11 добавлено и 4 удалено
  1. 11 4
      library/Zend/Date.php

+ 11 - 4
library/Zend/Date.php

@@ -4514,10 +4514,11 @@ class Zend_Date extends Zend_Date_DateObject
         }
 
         if ($precision === null) {
-            $precision = strlen($milli);
-            if ($milli < 0) {
-                --$precision;
-            }
+			// Use internal default precision
+			// Is not as logic as using the length of the input. But this would break tests and maybe other things
+			// as an input value of integer 10, which is used in tests, must be parsed as 10 milliseconds (real milliseconds, precision 3)
+			// but with auto-detect of precision, 100 milliseconds would be added.
+            $precision = $this->_precision;
         }
 
         if (!is_int($precision) || $precision < 1 || $precision > 9) {
@@ -4525,6 +4526,12 @@ class Zend_Date extends Zend_Date_DateObject
             throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision);
         }
 
+		if ($this->_precision > $precision) {
+			$milli = $milli * pow(10, $this->_precision - $precision);
+		} elseif ($this->_precision < $precision) {
+			$milli = round($milli / pow(10, $precision - $this->_precision));
+		}
+		
         $this->_fractional += $milli;
 
         // Add/sub milliseconds + add/sub seconds