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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
Formatter.php
framework/base/Formatter.php
+15
-4
No files found.
framework/base/Formatter.php
View file @
b5cd0a6f
...
@@ -462,7 +462,7 @@ class Formatter extends Component
...
@@ -462,7 +462,7 @@ class Formatter extends Component
* types of value are supported:
* types of value are supported:
*
*
* - an integer representing a UNIX timestamp
* - 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 DateTime object
* - a PHP DateInterval object
* - a PHP DateInterval object
*
*
...
@@ -477,16 +477,27 @@ class Formatter extends Component
...
@@ -477,16 +477,27 @@ class Formatter extends Component
if
(
$value
instanceof
\DateInterval
)
{
if
(
$value
instanceof
\DateInterval
)
{
$interval
=
$value
;
$interval
=
$value
;
}
else
{
}
else
{
$value
=
$this
->
normalizeDatetimeValue
(
$value
);
$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
);
$timezone
=
new
\DateTimeZone
(
$this
->
timeZone
);
$dateNow
=
new
DateTime
(
'now'
,
$timezone
);
$dateNow
=
new
DateTime
(
'now'
,
$timezone
);
$dateThen
=
new
DateTime
(
null
,
$timezone
);
$dateThen
=
new
DateTime
(
null
,
$timezone
);
$dateThen
->
setTimestamp
(
$value
);
$dateThen
->
setTimestamp
(
$timestamp
);
$interval
=
$dateNow
->
diff
(
$dateThen
);
$interval
=
$dateNow
->
diff
(
$dateThen
);
}
}
}
if
(
$interval
->
y
>=
1
)
{
if
(
$interval
->
y
>=
1
)
{
$delta
=
$interval
->
y
;
$delta
=
$interval
->
y
;
...
...
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