ソースを参照

fix more tests

euromark 11 年 前
コミット
52936f990b

+ 1 - 1
src/Utility/Text.php

@@ -222,7 +222,7 @@ class Text extends String {
 	 */
 	public function words($options = array()) {
 		if (true || !$this->xrWord) {
-			$text = str_replace(array(PHP_EOL, NL, TB), ' ', $this->text);
+			$text = str_replace(array(PHP_EOL, "\t"), ' ', $this->text);
 
 			$pieces = explode(' ', $text);
 			$pieces = array_unique($pieces);

+ 37 - 4
src/Utility/Time.php

@@ -613,14 +613,14 @@ class Time extends CakeTime {
 	 *
 	 * @return array (for forms etc)
 	 */
-	public static function months($monthKeys = array(), $options = array()) {
+	public static function monthNames($monthKeys = array(), $options = array()) {
 		if (!$monthKeys) {
 			$monthKeys = range(1, 12);
 		}
 		$res = array();
 		$abbr = isset($options['abbr']) ? $options['abbr'] : false;
 		foreach ($monthKeys as $key) {
-			$res[static::pad($key)] = static::month($key, $abbr, $options);
+			$res[static::pad($key)] = static::monthName($key, $abbr, $options);
 		}
 		return $res;
 	}
@@ -630,7 +630,7 @@ class Time extends CakeTime {
 	 *
 	 * @return array (for forms etc)
 	 */
-	public static function days($dayKeys = array(), $options = array()) {
+	public static function dayNames($dayKeys = array(), $options = array()) {
 		if (!$dayKeys) {
 			$dayKeys = range(0, 6);
 		}
@@ -638,7 +638,7 @@ class Time extends CakeTime {
 		$abbr = isset($options['abbr']) ? $options['abbr'] : false;
 		$offset = isset($options['offset']) ? $options['offset'] : 0;
 		foreach ($dayKeys as $key) {
-			$res[$key] = static::day($key, $abbr, $offset);
+			$res[$key] = static::dayName($key, $abbr, $offset);
 		}
 		return $res;
 	}
@@ -1051,6 +1051,39 @@ class Time extends CakeTime {
 	}
 
 	/**
+	 * Returns a partial SQL string to search for all records between two dates.
+	 *
+	 * @param int|string|DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
+	 * @param int|string|DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
+	 * @param string $fieldName Name of database field to compare with
+	 * @param string|DateTimeZone $timezone Timezone string or DateTimeZone object
+	 * @return string Partial SQL string.
+	 */
+	public static function daysAsSql($begin, $end, $fieldName, $timezone = null) {
+		$begin = new \DateTime($begin, $timezone);
+		$begin = $begin->format('U');
+		$end = new \DateTime($end, $timezone);
+		$end = $end->format('U');
+		$begin = date('Y-m-d', $begin) . ' 00:00:00';
+		$end = date('Y-m-d', $end) . ' 23:59:59';
+
+		return "($fieldName >= '$begin') AND ($fieldName <= '$end')";
+	}
+
+/**
+ * Returns a partial SQL string to search for all records between two times
+ * occurring on the same day.
+ *
+ * @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
+ * @param string $fieldName Name of database field to compare with
+ * @param string|DateTimeZone $timezone Timezone string or DateTimeZone object
+ * @return string Partial SQL string.
+ */
+	public static function dayAsSql($dateString, $fieldName, $timezone = null) {
+		return static::daysAsSql($dateString, $dateString, $fieldName, $timezone);
+	}
+
+	/**
 	 * Hours, minutes
 	 * e.g. 9.3 => 9.5
 	 *

+ 2 - 2
tests/TestCase/Utility/TextTest.php

@@ -47,12 +47,12 @@ TXT;
 		//pr($is);
 		$this->assertEquals($is, '0-104-32-72-0');
 
-		$is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . CR . 'x' . TB . 'x');
+		$is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . TB . 'x');
 		//pr($is);
 	}
 
 	public function testConvertToOrdTable() {
-		$is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . CR . 'x' . TB . 'x');
+		$is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . TB . 'x');
 		//pr($is);
 	}
 

+ 4 - 4
tests/TestCase/Utility/TimeTest.php

@@ -520,9 +520,9 @@ class TimeTest extends TestCase {
 	 *
 	 * @return void
 	 */
-	public function testDays() {
+	public function testDayNames() {
 		//$this->out($this->_header(__FUNCTION__), true);
-		$ret = $this->Time->days();
+		$ret = $this->Time->dayNames();
 		$this->assertTrue(count($ret) === 7);
 	}
 
@@ -531,9 +531,9 @@ class TimeTest extends TestCase {
 	 *
 	 * @return void
 	 */
-	public function testMonths() {
+	public function testMonthNames() {
 		//$this->out($this->_header(__FUNCTION__), true);
-		$ret = $this->Time->months();
+		$ret = $this->Time->monthNames();
 		$this->assertTrue(count($ret) === 12);
 	}