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
b5cd0a6f
Commit
b5cd0a6f
authored
Mar 12, 2014
by
David Renty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asElapsedTime can now take a DateInterval string as a parameter
parent
b7cf6183
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
Formatter.php
framework/base/Formatter.php
+21
-10
No files found.
framework/base/Formatter.php
View file @
b5cd0a6f
...
...
@@ -462,7 +462,7 @@ class Formatter extends Component
* types of value are supported:
*
* - an integer representing a UNIX timestamp
* - a string that can be parsed into a UNIX timestamp via `strtotime()`
* - a string that can be parsed into a UNIX timestamp via `strtotime()`
or that can be passed to a DateInterval constructor.
* - a PHP DateTime object
* - a PHP DateInterval object
*
...
...
@@ -477,15 +477,26 @@ class Formatter extends Component
if
(
$value
instanceof
\DateInterval
)
{
$interval
=
$value
;
}
else
{
$value
=
$this
->
normalizeDatetimeValue
(
$value
);
$timezone
=
new
\DateTimeZone
(
$this
->
timeZone
);
$dateNow
=
new
DateTime
(
'now'
,
$timezone
);
$dateThen
=
new
DateTime
(
null
,
$timezone
);
$dateThen
->
setTimestamp
(
$value
);
$interval
=
$dateNow
->
diff
(
$dateThen
);
$timestamp
=
$this
->
normalizeDatetimeValue
(
$value
);
if
(
$timestamp
===
false
)
{
// $value is not a valid date/time value, so we try
// to create a DateInterval with it
try
{
$interval
=
new
\DateInterval
(
$value
);
}
catch
(
Exception
$e
)
{
// invalid date/time and invalid interval
return
$this
->
nullDisplay
;
}
}
else
{
$timezone
=
new
\DateTimeZone
(
$this
->
timeZone
);
$dateNow
=
new
DateTime
(
'now'
,
$timezone
);
$dateThen
=
new
DateTime
(
null
,
$timezone
);
$dateThen
->
setTimestamp
(
$timestamp
);
$interval
=
$dateNow
->
diff
(
$dateThen
);
}
}
if
(
$interval
->
y
>=
1
)
{
...
...
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