Browse Source

fix tests

euromark 11 years ago
parent
commit
8ab290e2cd
2 changed files with 19 additions and 16 deletions
  1. 16 9
      Lib/Utility/TimeLib.php
  2. 3 7
      Test/Case/Lib/Utility/TimeLibTest.php

+ 16 - 9
Lib/Utility/TimeLib.php

@@ -803,6 +803,8 @@ class TimeLib extends CakeTime {
 			}
 		}
 
+		$ret = '';
+		$j = 0;
 		$length = mb_strlen($format);
 		for ($i = 0; $i < $length; $i++) {
 			switch (mb_substr($format, $i, 1)) {
@@ -835,9 +837,7 @@ class TimeLib extends CakeTime {
 				break;
 			}
 
-			$ret = '';
-			$j = 0;
-			if ($str > 0 || $j > 0 || $options['zero'] || $i == mb_strlen($format) - 1) {
+			if ($str > 0 || $j > 0 || $options['zero'] || $i === mb_strlen($format) - 1) {
 				if ($j > 0) {
 					$ret .= $options['separator'];
 				}
@@ -1073,6 +1073,7 @@ class TimeLib extends CakeTime {
 	 * Hours, minutes
 	 * e.g. 9.3 => 9.5
 	 *
+	 * @param int $value
 	 * @return float
 	 */
 	public static function standardToDecimalTime($value) {
@@ -1091,6 +1092,9 @@ class TimeLib extends CakeTime {
 	 * e.g. 9.5 => 9.3
 	 * with pad=2: 9.30
 	 *
+	 * @param int $value
+	 * @param string $pad
+	 * @param string $decPoint
 	 * @return string
 	 */
 	public static function decimalToStandardTime($value, $pad = null, $decPoint = '.') {
@@ -1112,7 +1116,8 @@ class TimeLib extends CakeTime {
 	 * now supports negative values like -2,5 -2,5 -2:30 -:30 or -4
 	 *
 	 * @param string
-	 * @return int: seconds
+	 * @param array $allowed
+	 * @return int Seconds
 	 */
 	public static function parseTime($duration, $allowed = array(':', '.', ',')) {
 		if (empty($duration)) {
@@ -1152,7 +1157,8 @@ class TimeLib extends CakeTime {
 	 * Parse 2022-11-12 or 12.11.2022 or even 12.11.22
 	 *
 	 * @param string $date
-	 * @return int: seconds
+	 * @param array $allowed
+	 * @return int Seconds
 	 */
 	public static function parseDate($date, $allowed = array('.', '-')) {
 		$datePieces = explode(' ', $date, 2);
@@ -1182,8 +1188,9 @@ class TimeLib extends CakeTime {
 	/**
 	 * Return strings like 2:30 (later //TODO: or 2:33:99) from seconds etc
 	 *
-	 * @param int: seconds
-	 * @return string
+	 * @param int $duraton Duraction in seconds
+	 * @param string $mode
+	 * @return string Time
 	 */
 	public static function buildTime($duration, $mode = 'H:MM') {
 		if ($duration < 0) {
@@ -1206,8 +1213,8 @@ class TimeLib extends CakeTime {
 	/**
 	 * Return strings like 2:33:99 from seconds etc
 	 *
-	 * @param int: seconds
-	 * @return string
+	 * @param int $duration Duration in seconds
+	 * @return string Time
 	 */
 	public static function buildDefaultTime($duration) {
 		$minutes = $duration % HOUR;

+ 3 - 7
Test/Case/Lib/Utility/TimeLibTest.php

@@ -335,7 +335,7 @@ class TimeLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testAge() {
-		$this->assertEquals('0', TimeLib::age());
+		$this->assertEquals('0', TimeLib::age(null));
 
 		list($year, $month, $day) = explode('-', date('Y-m-d'));
 		$this->assertEquals('0', TimeLib::age($year . '-' . $month . '-' . $day, null));
@@ -356,12 +356,8 @@ class TimeLibTest extends MyCakeTestCase {
 		// Leap year
 
 		$this->assertEquals('2', TimeLib::age('2005-03-01', '2008-02-28'));
-		if (WINDOWS) {
-			// On some local devs this seems to return the wrong age 3...
-			$this->assertEquals('3', TimeLib::age('2005-03-01', '2008-02-29'));
-		} else {
-			$this->assertEquals('2', TimeLib::age('2005-03-01', '2008-02-29'));
-		}
+		$this->assertEquals('2', TimeLib::age('2005-03-01', '2008-02-29'));
+
 		$this->assertEquals('3', TimeLib::age('2005-03-01', '2008-03-01'));
 		$this->assertEquals('3', TimeLib::age('2005-02-29', '2008-03-01'));