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
cb3eb9c6
Commit
cb3eb9c6
authored
Mar 14, 2014
by
David Renty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for inverted intervals (future time) and unit tests
parent
b5cd0a6f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
29 deletions
+48
-29
Formatter.php
framework/base/Formatter.php
+48
-29
FormatterTest.php
tests/unit/framework/base/FormatterTest.php
+0
-0
No files found.
framework/base/Formatter.php
View file @
cb3eb9c6
...
@@ -468,7 +468,7 @@ class Formatter extends Component
...
@@ -468,7 +468,7 @@ class Formatter extends Component
*
*
* @return string the formatted result
* @return string the formatted result
*/
*/
public
function
as
ElapsedTime
(
$value
)
public
function
as
RelativeTime
(
$value
,
$referenceTime
=
null
)
{
{
if
(
$value
===
null
)
{
if
(
$value
===
null
)
{
return
$this
->
nullDisplay
;
return
$this
->
nullDisplay
;
...
@@ -490,41 +490,60 @@ class Formatter extends Component
...
@@ -490,41 +490,60 @@ class Formatter extends Component
}
}
}
else
{
}
else
{
$timezone
=
new
\DateTimeZone
(
$this
->
timeZone
);
$timezone
=
new
\DateTimeZone
(
$this
->
timeZone
);
if
(
$referenceTime
===
null
)
{
$dateNow
=
new
DateTime
(
'now'
,
$timezone
);
}
else
{
$referenceTime
=
$this
->
normalizeDatetimeValue
(
$referenceTime
);
$dateNow
=
new
DateTime
(
null
,
$timezone
);
$dateNow
->
setTimestamp
(
$referenceTime
);
}
$dateNow
=
new
DateTime
(
'now'
,
$timezone
);
$dateThen
=
new
DateTime
(
null
,
$timezone
);
$dateThen
=
new
DateTime
(
null
,
$timezone
);
$dateThen
->
setTimestamp
(
$timestamp
);
$dateThen
->
setTimestamp
(
$timestamp
);
$interval
=
$dateNow
->
diff
(
$dateThen
);
$interval
=
$dateThen
->
diff
(
$dateNow
);
var_dump
(
$dateThen
);
var_dump
(
$dateNow
);
}
}
}
}
if
(
$interval
->
y
>=
1
)
{
if
(
$interval
->
invert
)
{
$delta
=
$interval
->
y
;
if
(
$interval
->
y
>=
1
)
{
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a year} other{# years}} ago'
,
[
'delta'
=>
$delta
]);
return
Yii
::
t
(
'yii'
,
'in {delta, plural, =1{a year} other{# years}}'
,
[
'delta'
=>
$interval
->
y
]);
}
}
if
(
$interval
->
m
>=
1
)
{
if
(
$interval
->
m
>=
1
)
{
$delta
=
$interval
->
m
;
return
Yii
::
t
(
'yii'
,
'in {delta, plural, =1{a month} other{# months}}'
,
[
'delta'
=>
$interval
->
m
]);
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a month} other{# months}} ago'
,
[
'delta'
=>
$delta
]);
}
}
if
(
$interval
->
d
>=
1
)
{
if
(
$interval
->
d
>=
7
)
{
return
Yii
::
t
(
'yii'
,
'in {delta, plural, =1{a day} other{# days}}'
,
[
'delta'
=>
$interval
->
d
]);
$delta
=
floor
(
$interval
->
d
/
7
);
}
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a week} other{# weeks}} ago'
,
[
'delta'
=>
$delta
]);
if
(
$interval
->
h
>=
1
)
{
}
return
Yii
::
t
(
'yii'
,
'in {delta, plural, =1{an hour} other{# hours}}'
,
[
'delta'
=>
$interval
->
h
]);
if
(
$interval
->
d
>=
1
)
{
}
$delta
=
$interval
->
d
;
if
(
$interval
->
i
>=
1
)
{
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{yesterday} other{# days ago}}'
,
[
'delta'
=>
$delta
]);
return
Yii
::
t
(
'yii'
,
'in {delta, plural, =1{a minute} other{# minutes}}'
,
[
'delta'
=>
$interval
->
i
]);
}
}
if
(
$interval
->
h
>=
1
)
{
$delta
=
$interval
->
h
;
return
Yii
::
t
(
'yii'
,
'in {delta, plural, =1{a second} other{# seconds}}'
,
[
'delta'
=>
$interval
->
s
]);
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{an hour} other{# hours}} ago'
,
[
'delta'
=>
$delta
]);
}
else
{
}
if
(
$interval
->
y
>=
1
)
{
if
(
$interval
->
i
>=
1
)
{
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a year} other{# years}} ago'
,
[
'delta'
=>
$interval
->
y
]);
$delta
=
$interval
->
i
;
}
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a minute} other{# minutes}} ago'
,
[
'delta'
=>
$delta
]);
if
(
$interval
->
m
>=
1
)
{
}
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a month} other{# months}} ago'
,
[
'delta'
=>
$interval
->
m
]);
}
if
(
$interval
->
d
>=
1
)
{
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a day} other{# days}} ago'
,
[
'delta'
=>
$interval
->
d
]);
}
if
(
$interval
->
h
>=
1
)
{
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{an hour} other{# hours}} ago'
,
[
'delta'
=>
$interval
->
h
]);
}
if
(
$interval
->
i
>=
1
)
{
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a minute} other{# minutes}} ago'
,
[
'delta'
=>
$interval
->
i
]);
}
$delta
=
$interval
->
s
;
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a second} other{# seconds}} ago'
,
[
'delta'
=>
$interval
->
s
])
;
return
Yii
::
t
(
'yii'
,
'{delta, plural, =1{a second} other{# seconds}} ago'
,
[
'delta'
=>
$delta
]);
}
}
}
}
}
tests/unit/framework/base/FormatterTest.php
View file @
cb3eb9c6
This diff is collapsed.
Click to expand it.
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