Commit 3616d1f0 by Qiang Xue

Fixes #2816: Changed default date and time format of `yii\base\Formatter` to `Y-m-d` and `H:i:s`

parent 7f73ec1f
...@@ -237,6 +237,7 @@ Yii Framework 2 Change Log ...@@ -237,6 +237,7 @@ Yii Framework 2 Change Log
- Removed `yii\web\Controller::getCanonicalUrl`, use `yii\helpers\Url::canonical` instead. - Removed `yii\web\Controller::getCanonicalUrl`, use `yii\helpers\Url::canonical` instead.
- Chg #2691: Null parameters will not be included in the generated URLs by `UrlManager` (gonimar, qiangxue) - Chg #2691: Null parameters will not be included in the generated URLs by `UrlManager` (gonimar, qiangxue)
- Chg #2734: `FileCache::keyPrefix` defaults to empty string now (qiangxue) - Chg #2734: `FileCache::keyPrefix` defaults to empty string now (qiangxue)
- Chg #2816: Changed default date and time format of `yii\base\Formatter` to `Y-m-d` and `H:i:s` (qiangxue)
- Chg #2911: Removed `tbl_` default for table prefix (samdark) - Chg #2911: Removed `tbl_` default for table prefix (samdark)
- Chg #2912: Relative view files will be looked for under the directory containing the view currently being rendered (qiangxue) - Chg #2912: Relative view files will be looked for under the directory containing the view currently being rendered (qiangxue)
- Chg #2955: Changed the signature of ActiveQuery constructors and `ActiveRecord::createQuery()` to simplify customizing ActiveQuery classes (qiangxue) - Chg #2955: Changed the signature of ActiveQuery constructors and `ActiveRecord::createQuery()` to simplify customizing ActiveQuery classes (qiangxue)
......
...@@ -38,15 +38,15 @@ class Formatter extends Component ...@@ -38,15 +38,15 @@ class Formatter extends Component
/** /**
* @var string the default format string to be used to format a date using PHP date() function. * @var string the default format string to be used to format a date using PHP date() function.
*/ */
public $dateFormat = 'Y/m/d'; public $dateFormat = 'Y-m-d';
/** /**
* @var string the default format string to be used to format a time using PHP date() function. * @var string the default format string to be used to format a time using PHP date() function.
*/ */
public $timeFormat = 'h:i:s A'; public $timeFormat = 'H:i:s';
/** /**
* @var string the default format string to be used to format a date and time using PHP date() function. * @var string the default format string to be used to format a date and time using PHP date() function.
*/ */
public $datetimeFormat = 'Y/m/d h:i:s A'; public $datetimeFormat = 'Y-m-d H:i:s';
/** /**
* @var string the text to be displayed when formatting a null. Defaults to '<span class="not-set">(not set)</span>'. * @var string the text to be displayed when formatting a null. Defaults to '<span class="not-set">(not set)</span>'.
*/ */
......
...@@ -233,7 +233,7 @@ abstract class Target extends Component ...@@ -233,7 +233,7 @@ abstract class Target extends Component
$prefix = $this->prefix ? call_user_func($this->prefix, $message) : $this->getMessagePrefix($message); $prefix = $this->prefix ? call_user_func($this->prefix, $message) : $this->getMessagePrefix($message);
return date('Y/m/d H:i:s', $timestamp) . " {$prefix}[$level][$category] $text"; return date('Y-m-d H:i:s', $timestamp) . " {$prefix}[$level][$category] $text";
} }
/** /**
......
...@@ -121,24 +121,24 @@ class FormatterTest extends TestCase ...@@ -121,24 +121,24 @@ class FormatterTest extends TestCase
public function testAsDate() public function testAsDate()
{ {
$value = time(); $value = time();
$this->assertSame(date('Y/m/d', $value), $this->formatter->asDate($value)); $this->assertSame(date('Y-m-d', $value), $this->formatter->asDate($value));
$this->assertSame(date('Y-m-d', $value), $this->formatter->asDate($value, 'Y-m-d')); $this->assertSame(date('Y/m/d', $value), $this->formatter->asDate($value, 'Y/m/d'));
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asDate(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDate(null));
} }
public function testAsTime() public function testAsTime()
{ {
$value = time(); $value = time();
$this->assertSame(date('h:i:s A', $value), $this->formatter->asTime($value)); $this->assertSame(date('H:i:s', $value), $this->formatter->asTime($value));
$this->assertSame(date('h:i:s', $value), $this->formatter->asTime($value, 'h:i:s')); $this->assertSame(date('h:i:s A', $value), $this->formatter->asTime($value, 'h:i:s A'));
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asTime(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asTime(null));
} }
public function testAsDatetime() public function testAsDatetime()
{ {
$value = time(); $value = time();
$this->assertSame(date('Y/m/d h:i:s A', $value), $this->formatter->asDatetime($value)); $this->assertSame(date('Y-m-d H:i:s', $value), $this->formatter->asDatetime($value));
$this->assertSame(date('Y-m-d h:i:s', $value), $this->formatter->asDatetime($value, 'Y-m-d h:i:s')); $this->assertSame(date('Y/m/d h:i:s A', $value), $this->formatter->asDatetime($value, 'Y/m/d h:i:s A'));
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asDatetime(null)); $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDatetime(null));
} }
...@@ -193,9 +193,9 @@ class FormatterTest extends TestCase ...@@ -193,9 +193,9 @@ class FormatterTest extends TestCase
public function testFormat() public function testFormat()
{ {
$value = time(); $value = time();
$this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, 'date')); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'date'));
$this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, 'DATE')); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'DATE'));
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, ['date', 'Y-m-d'])); $this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, ['date', 'Y/m/d']));
$this->setExpectedException('\yii\base\InvalidParamException'); $this->setExpectedException('\yii\base\InvalidParamException');
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data')); $this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data'));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment