Browse Source

Fix up datetime output.

mscherer 1 year ago
parent
commit
f0ea8b20bc
2 changed files with 20 additions and 3 deletions
  1. 3 3
      src/I18n/DateTime.php
  2. 17 0
      tests/TestCase/Utility/DateTimeTest.php

+ 3 - 3
src/I18n/DateTime.php

@@ -541,7 +541,7 @@ class DateTime extends CakeDateTime {
 
 		if (!is_object($dateString)) {
 			if (is_string($dateString) && strlen($dateString) === 10) {
-				$date = new CakeDateTime($dateString);
+				$date = new CakeDate($dateString);
 			} else {
 				$date = new static($dateString);
 			}
@@ -551,9 +551,9 @@ class DateTime extends CakeDateTime {
 
 		if ($format === null) {
 			if ($date instanceof CakeDateTime) {
-				$format = FORMAT_NICE_YMD;
-			} else {
 				$format = FORMAT_NICE_YMDHM;
+			} else {
+				$format = FORMAT_NICE_YMD;
 			}
 		}
 

+ 17 - 0
tests/TestCase/Utility/DateTimeTest.php

@@ -164,6 +164,23 @@ class DateTimeTest extends TestCase {
 	}
 
 	/**
+	 * Test that input as date only (YYYY-MM-DD) does not suddenly return a
+	 * different date on output due to timezone differences.
+	 * Here the timezone should not apply since we only input date and only output
+	 * date (time itself is irrelevant).
+	 *
+	 * @return void
+	 */
+	public function testDateTimeWithTimezone() {
+		$res = setlocale(LC_TIME, 'de_DE.UTF-8', 'deu_deu');
+		//$this->assertTrue(!empty($res));
+		Configure::write('Config.timezone', 'America/Anchorage');
+
+		$ret = $this->Time->niceDate('2009-12-01 12:13:14');
+		$this->assertEquals('01.12.2009, 12:13', $ret);
+	}
+
+	/**
 	 * @return void
 	 */
 	public function testFormatLocalized() {