Browse Source

also allow oclock for localDate

euromark 11 years ago
parent
commit
e1ca575025
3 changed files with 62 additions and 16 deletions
  1. 33 10
      Lib/Utility/TimeLib.php
  2. 26 3
      Test/Case/Lib/Utility/TimeLibTest.php
  3. 3 3
      View/Helper/FormExtHelper.php

+ 33 - 10
Lib/Utility/TimeLib.php

@@ -458,11 +458,15 @@ class TimeLib extends CakeTime {
 	/**
 	 * Outputs Date(time) Sting nicely formatted (+ localized!)
 	 *
+	 * Options:
+	 * - timezone: User's timezone
+	 * - default: Default string (defaults to "-----")
+	 * - oclock: Set to true to append oclock string
+	 *
 	 * @param string $dateString,
-	 * @param string $format (YYYY-MM-DD, DD.MM.YYYY)
-	 * @param array $options
-		* - timezone: User's timezone
-		* - default (defaults to "-----")
+	 * @param string $format Format (YYYY-MM-DD, DD.MM.YYYY)
+	 * @param array $options @return string
+	 * @return string
 	 */
 	public static function localDate($dateString = null, $format = null, $options = array()) {
 		$defaults = array('default' => '-----', 'timezone' => null);
@@ -479,6 +483,7 @@ class TimeLib extends CakeTime {
 		if ($date === null || $date === false || $date <= 0) {
 			return $options['default'];
 		}
+
 		if ($format === null) {
 			if (is_int($dateString) || strpos($dateString, ' ') !== false) {
 				$format = FORMAT_LOCAL_YMDHM;
@@ -486,17 +491,35 @@ class TimeLib extends CakeTime {
 				$format = FORMAT_LOCAL_YMD;
 			}
 		}
-		return parent::_strftime($format, $date);
+
+		$date = parent::_strftime($format, $date);
+
+		if (!empty($options['oclock'])) {
+			switch ($format) {
+				case FORMAT_LOCAL_YMDHM:
+				case FORMAT_LOCAL_YMDHMS:
+				case FORMAT_LOCAL_YMDHM:
+				case FORMAT_LOCAL_HM:
+				case FORMAT_LOCAL_HMS:
+					$date .= ' ' . __('o\'clock');
+					break;
+			}
+		}
+		return $date;
 	}
 
 	/**
 	 * Outputs Date(time) Sting nicely formatted
 	 *
+	 * Options:
+	 * - timezone: User's timezone
+	 * - default: Default string (defaults to "-----")
+	 * - oclock: Set to true to append oclock string
+	 *
 	 * @param string $dateString,
-	 * @param string $format (YYYY-MM-DD, DD.MM.YYYY)
-	 * @param array $options
-		* - timezone: User's timezone
-		* - default (defaults to "-----")
+	 * @param string $format Format (YYYY-MM-DD, DD.MM.YYYY)
+	 * @param array $options Options
+	 * @return string
 	 */
 	public static function niceDate($dateString = null, $format = null, $options = array()) {
 		$defaults = array('default' => '-----', 'timezone' => null);
@@ -524,7 +547,7 @@ class TimeLib extends CakeTime {
 
 		$ret = date($format, $date);
 
-		if (!empty($options['oclock']) && $options['oclock']) {
+		if (!empty($options['oclock'])) {
 			switch ($format) {
 				case FORMAT_NICE_YMDHM:
 				case FORMAT_NICE_YMDHMS:

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

@@ -97,10 +97,21 @@ class TimeLibTest extends MyCakeTestCase {
 			array('2009-12-01 00:00:00', FORMAT_NICE_M_FULL, 'December'),
 		);
 		foreach ($values as $v) {
-			$ret = TimeLib::niceDate($v[0], $v[1]);
-			//$this->debug($ret);
-			$this->assertEquals($v[2], $ret);
+			$result = TimeLib::niceDate($v[0], $v[1]);
+			$this->assertEquals($v[2], $result);
 		}
+
+		$date = '2009-12-01 00:00:00';
+		$format = FORMAT_NICE_YMD;
+		$result = TimeLib::niceDate($date, $format, array('oclock' => true));
+		$expected = '01.12.2009';
+		$this->assertEquals($expected, $result);
+
+		$date = '2009-12-01 00:00:00';
+		$format = FORMAT_NICE_YMDHM;
+		$result = TimeLib::niceDate($date, $format, array('oclock' => true));
+		$expected = '01.12.2009, 00:00 ' . __('o\'clock');
+		$this->assertEquals($expected, $result);
 	}
 
 	/**
@@ -144,6 +155,18 @@ class TimeLibTest extends MyCakeTestCase {
 			//$this->debug($ret);
 			$this->assertEquals($v[2], $ret);
 		}
+
+		$date = '2009-12-01 00:00:00';
+		$format = FORMAT_LOCAL_YMD;
+		$result = TimeLib::localDate($date, $format, array('oclock' => true));
+		$expected = '01.12.2009';
+		$this->assertEquals($expected, $result);
+
+		$date = '2009-12-01 00:00:00';
+		$format = FORMAT_LOCAL_YMDHM;
+		$result = TimeLib::localDate($date, $format, array('oclock' => true));
+		$expected = '01.12.2009, 00:00 ' . __('o\'clock');
+		$this->assertEquals($expected, $result);
 	}
 
 	/**

+ 3 - 3
View/Helper/FormExtHelper.php

@@ -70,7 +70,7 @@ class FormExtHelper extends FormHelper {
 	public function deleteLink($title, $url = null, $options = array(), $confirmMessage = false) {
 		$options['method'] = 'delete';
 		if (!isset($options['class'])) {
-			$options['class'] = 'deleteLink';
+			$options['class'] = 'delete-link deleteLink';
 		}
 		return $this->postLink($title, $url, $options, $confirmMessage);
 	}
@@ -84,7 +84,7 @@ class FormExtHelper extends FormHelper {
 	 */
 	public function postLink($title, $url = null, $options = array(), $confirmMessage = false) {
 		if (!isset($options['class'])) {
-			$options['class'] = 'postLink';
+			$options['class'] = 'post-link postLink';
 		}
 		return parent::postLink($title, $url, $options, $confirmMessage);
 	}
@@ -1147,7 +1147,7 @@ jQuery(\'' . $selector . '\').maxlength(' . $this->Js->object($settings, array('
 	 */
 	protected function _checkbox($id, $group = null, $options = array()) {
 		$defaults = array(
-			'class' => 'checkboxToggle'
+			'class' => 'checkbox-toggle checkboxToggle'
 		);
 		$options = array_merge($defaults, $options);
 		return $script . parent::checkbox($fieldName, $options);