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
e77ffe2c
Commit
e77ffe2c
authored
Mar 12, 2014
by
David Renty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added asElapsedTime function
parent
ed5007e4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
Formatter.php
framework/base/Formatter.php
+50
-0
No files found.
framework/base/Formatter.php
View file @
e77ffe2c
...
@@ -455,4 +455,54 @@ class Formatter extends Component
...
@@ -455,4 +455,54 @@ class Formatter extends Component
return
$verbose
?
Yii
::
t
(
'yii'
,
'{n, plural, =1{# petabyte} other{# petabytes}}'
,
$params
)
:
Yii
::
t
(
'yii'
,
'{n} PB'
,
$params
);
return
$verbose
?
Yii
::
t
(
'yii'
,
'{n, plural, =1{# petabyte} other{# petabytes}}'
,
$params
)
:
Yii
::
t
(
'yii'
,
'{n} PB'
,
$params
);
}
}
}
}
/**
* Formats the value as a the time elapsed since then in human readable form.
* @param integer|string|DateTime $value the value to be formatted. The following
* types of value are supported:
*
* - an integer representing a UNIX timestamp
* - a string that can be parsed into a UNIX timestamp via `strtotime()`
* - a PHP DateTime object
*
* @return string the formatted result
*/
public
function
asElapsedTime
(
$value
)
{
if
(
$value
===
null
)
{
return
$this
->
nullDisplay
;
}
$value
=
$this
->
normalizeDatetimeValue
(
$value
);
$now
=
new
\DateTime
();
$date
=
new
DateTime
(
null
,
new
\DateTimeZone
(
$this
->
timeZone
));
$date
->
setTimestamp
(
$value
);
$interval
=
$now
->
diff
(
$date
);
if
(
$interval
->
y
>=
1
)
{
$delta
=
$interval
->
y
;
$format
=
'{delta, plural, =1{a year} other{# years}} ago'
;
}
elseif
(
$interval
->
m
>=
1
)
{
$delta
=
$interval
->
m
;
$format
=
'{delta, plural, =1{a month} other{# months}} ago'
;
}
elseif
(
$interval
->
d
>=
7
)
{
$delta
=
floor
(
$interval
->
d
/
7
);
$format
=
'{delta, plural, =1{a week} other{# weeks}} ago'
;
}
elseif
(
$interval
->
d
>=
1
)
{
$delta
=
$interval
->
d
;
$format
=
'{delta, plural, =1{yesterday} other{# days ago}}'
;
}
elseif
(
$interval
->
h
>=
1
)
{
$delta
=
$interval
->
h
;
$format
=
'{delta, plural, =1{an hour} other{# hours}} ago'
;
}
elseif
(
$interval
->
i
>=
1
)
{
$delta
=
$interval
->
i
;
$format
=
'{delta, plural, =1{a minute} other{# minutes}} ago'
;
}
else
{
$delta
=
$interval
->
s
;
$format
=
'{delta, plural, =1{a second} other{# seconds}} ago'
;
}
return
Yii
::
t
(
'yii'
,
$format
,
[
'delta'
=>
$delta
]);
}
}
}
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