Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
6a8f4b0e
Commit
6a8f4b0e
authored
Nov 26, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed date formatter to display date-only values correctly
fixes #5448
parent
c2d814cc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
10 deletions
+56
-10
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
DateTimeExtended.php
framework/i18n/DateTimeExtended.php
+42
-9
Formatter.php
framework/i18n/Formatter.php
+1
-1
FormatterTest.php
tests/unit/framework/i18n/FormatterTest.php
+12
-0
No files found.
framework/CHANGELOG.md
View file @
6a8f4b0e
...
...
@@ -8,6 +8,7 @@ Yii Framework 2 Change Log
-
Bug #4823:
`yii message`
accuracy and error handling were improved (samdark)
-
Bug #4889: Application was getting into redirect loop when user wasn't allowed accessing login page. Now shows 403 (samdark)
-
Bug #5402: Debugger was not loading when there were closures in asset classes (samdark)
-
Bug #5448: Date formatter was doing timezone conversion on date only values resulting in different date displayed than provided (cebe)
-
Bug #5452: Errors occurring after the response is sent are not displayed (qiangxue)
-
Bug #5521: Fixed
`yii\console\controllers\AssetController`
breaks CSS URLs, which start from '/' (klimov-paul)
-
Bug #5570:
`yii\bootstrap\Tabs`
would throw an exception if
`content`
is not set for one of its
`items`
(RomeroMsk)
...
...
framework/i18n/DateTimeExtended.php
View file @
6a8f4b0e
...
...
@@ -34,9 +34,14 @@ class DateTimeExtended extends \DateTime
*/
public
function
__construct
(
$time
=
'now'
,
\DateTimeZone
$timezone
=
null
)
{
// TODO get date info
$this
->
_isDateOnly
=
false
;
parent
::
__construct
(
$time
,
$timezone
);
$info
=
date_parse
(
$time
);
if
(
$info
[
'hour'
]
===
false
&&
$info
[
'minute'
]
===
false
&&
$info
[
'second'
]
===
false
)
{
$this
->
_isDateOnly
=
true
;
}
else
{
$this
->
_isDateOnly
=
false
;
}
}
/**
...
...
@@ -47,12 +52,23 @@ class DateTimeExtended extends \DateTime
* @return DateTimeExtended
* @link http://php.net/manual/en/datetime.createfromformat.php
*/
public
static
function
createFromFormat
(
$format
,
$time
,
\DateTimeZone
$timezone
=
null
)
public
static
function
createFromFormat
(
$format
,
$time
,
$timezone
=
null
)
{
$dateTime
=
parent
::
createFromFormat
(
$format
,
$time
,
$timezone
);
// TODO turn object into instance of $this
// TODO get date info
// $dateTime->_isDateOnly = false;
if
((
$originalDateTime
=
parent
::
createFromFormat
(
$format
,
$time
,
$timezone
))
===
false
)
{
return
false
;
}
$info
=
date_parse_from_format
(
$format
,
$time
);
/** @var $dateTime \DateTime */
$dateTime
=
new
static
;
if
(
$info
[
'hour'
]
===
false
&&
$info
[
'minute'
]
===
false
&&
$info
[
'second'
]
===
false
)
{
$dateTime
->
_isDateOnly
=
true
;
}
else
{
$dateTime
->
_isDateOnly
=
false
;
}
$dateTime
->
setTimezone
(
$originalDateTime
->
getTimezone
());
$dateTime
->
setTimestamp
(
$originalDateTime
->
getTimestamp
());
return
$dateTime
;
}
...
...
@@ -60,4 +76,22 @@ class DateTimeExtended extends \DateTime
{
return
$this
->
_isDateOnly
;
}
}
\ No newline at end of file
public
function
getTimezone
()
{
if
(
$this
->
_isDateOnly
)
{
return
false
;
}
else
{
return
parent
::
getTimezone
();
}
}
public
function
getOffset
()
{
if
(
$this
->
_isDateOnly
)
{
return
false
;
}
else
{
return
parent
::
getOffset
();
}
}
}
framework/i18n/Formatter.php
View file @
6a8f4b0e
...
...
@@ -534,7 +534,7 @@ class Formatter extends Component
// avoid time zone conversion for date-only values
if
(
$type
===
'date'
&&
$timestamp
->
isDateOnly
())
{
$timeZone
=
$this
->
defaultTimeZone
;
// TODO maybe just NULL?
$timeZone
=
$this
->
defaultTimeZone
;
}
else
{
$timeZone
=
$this
->
timeZone
;
}
...
...
tests/unit/framework/i18n/FormatterTest.php
View file @
6a8f4b0e
...
...
@@ -629,6 +629,18 @@ class FormatterTest extends TestCase
}
public
function
testDateOnlyValues
()
{
date_default_timezone_set
(
'Pacific/Kiritimati'
);
// timzones with exactly 24h difference, ensure this test does not fail on a certain time
$this
->
formatter
->
defaultTimeZone
=
'Pacific/Kiritimati'
;
// always UTC+14
$this
->
formatter
->
timeZone
=
'Pacific/Honolulu'
;
// always UTC-10
// when timezone conversion is made on this date, it will result in 2014-07-31 to be returned.
// ensure this does not happen on date only values
$this
->
assertSame
(
'2014-08-01'
,
$this
->
formatter
->
asDate
(
'2014-08-01'
,
'yyyy-MM-dd'
));
}
// number format
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment