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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
91e4ad59
Commit
91e4ad59
authored
Mar 17, 2014
by
David Renty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PSR-2 compliance
parent
0fa5230c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
Formatter.php
framework/base/Formatter.php
+4
-2
FormatterTest.php
tests/unit/framework/base/FormatterTest.php
+2
-2
No files found.
framework/base/Formatter.php
View file @
91e4ad59
...
@@ -180,7 +180,9 @@ class Formatter extends Component
...
@@ -180,7 +180,9 @@ class Formatter extends Component
if
(
$value
===
null
)
{
if
(
$value
===
null
)
{
return
$this
->
nullDisplay
;
return
$this
->
nullDisplay
;
}
}
return
str_replace
(
'<p></p>'
,
''
,
return
str_replace
(
'<p></p>'
,
''
,
'<p>'
.
preg_replace
(
'/[\r\n]{2,}/'
,
"</p>
\n
<p>"
,
Html
::
encode
(
$value
))
.
'</p>'
'<p>'
.
preg_replace
(
'/[\r\n]{2,}/'
,
"</p>
\n
<p>"
,
Html
::
encode
(
$value
))
.
'</p>'
);
);
}
}
...
@@ -468,7 +470,7 @@ class Formatter extends Component
...
@@ -468,7 +470,7 @@ class Formatter extends Component
*
*
* @return string the formatted result
* @return string the formatted result
*/
*/
public
function
asRelativeTime
(
$value
,
$referenceTime
=
null
)
public
function
asRelativeTime
(
$value
,
$referenceTime
=
null
)
{
{
if
(
$value
===
null
)
{
if
(
$value
===
null
)
{
return
$this
->
nullDisplay
;
return
$this
->
nullDisplay
;
...
...
tests/unit/framework/base/FormatterTest.php
View file @
91e4ad59
...
@@ -269,7 +269,7 @@ class FormatterTest extends TestCase
...
@@ -269,7 +269,7 @@ class FormatterTest extends TestCase
$dateThen
=
new
DateTime
(
'2014-02-28'
);
$dateThen
=
new
DateTime
(
'2014-02-28'
);
$this
->
assertSame
(
'a month ago'
,
$this
->
formatter
->
asRelativeTime
(
$dateThen
,
$dateNow
));
$this
->
assertSame
(
'a month ago'
,
$this
->
formatter
->
asRelativeTime
(
$dateThen
,
$dateNow
));
// Relative to current time tests (can't test with seconds though
)
// Relative to current time tests (can't test with seconds though due to the tests computation time
)
$this
->
assertSame
(
'4 minutes ago'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'now'
,
[
$interval_244_seconds
])));
$this
->
assertSame
(
'4 minutes ago'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'now'
,
[
$interval_244_seconds
])));
$this
->
assertSame
(
'a minute ago'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'now'
,
[
$interval_1_minute
])));
$this
->
assertSame
(
'a minute ago'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'now'
,
[
$interval_1_minute
])));
$this
->
assertSame
(
'33 minutes ago'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'now'
,
[
$interval_33_minutes
])));
$this
->
assertSame
(
'33 minutes ago'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'now'
,
[
$interval_33_minutes
])));
...
@@ -335,7 +335,7 @@ class FormatterTest extends TestCase
...
@@ -335,7 +335,7 @@ class FormatterTest extends TestCase
$this
->
assertSame
(
'in a month'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'2014-03-03'
,
[
$interval_1_month
]),
$dateNow
));
$this
->
assertSame
(
'in a month'
,
$this
->
formatter
->
asRelativeTime
(
$this
->
buildDateSubIntervals
(
'2014-03-03'
,
[
$interval_1_month
]),
$dateNow
));
$this
->
assertSame
(
'in 28 days'
,
$this
->
formatter
->
asRelativeTime
(
$dateThen
,
$dateNow
));
$this
->
assertSame
(
'in 28 days'
,
$this
->
formatter
->
asRelativeTime
(
$dateThen
,
$dateNow
));
// Relative to current time tests (can't test with seconds though
)
// Relative to current time tests (can't test with seconds though due to the tests computation time
)
// We add 5 seconds to compensate for tests computation time
// We add 5 seconds to compensate for tests computation time
$interval_5_seconds
=
new
DateInterval
(
'PT5S'
);
$interval_5_seconds
=
new
DateInterval
(
'PT5S'
);
$interval_5_seconds
->
invert
=
true
;
$interval_5_seconds
->
invert
=
true
;
...
...
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