Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
44289ff1
Unverified
Commit
44289ff1
authored
7 years ago
by
Morris Jobke
Browse files
Options
Downloads
Patches
Plain Diff
Use proper method to format absolute timestamp
Signed-off-by:
Morris Jobke
<
hey@morrisjobke.de
>
parent
af89db34
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/legacy/util.php
+0
-23
0 additions, 23 deletions
lib/private/legacy/util.php
settings/templates/settings/admin/server.php
+3
-1
3 additions, 1 deletion
settings/templates/settings/admin/server.php
tests/lib/UtilTest.php
+0
-64
0 additions, 64 deletions
tests/lib/UtilTest.php
with
3 additions
and
88 deletions
lib/private/legacy/util.php
+
0
−
23
View file @
44289ff1
...
...
@@ -678,29 +678,6 @@ class OC_Util {
);
}
/**
* formats a timestamp in the "right" way
*
* @param int $timestamp
* @param bool $dateOnly option to omit time from the result
* @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
* @return string timestamp
*
* @deprecated Use \OC::$server->query('DateTimeFormatter') instead
*/
public
static
function
formatDate
(
$timestamp
,
$dateOnly
=
false
,
$timeZone
=
null
)
{
if
(
$timeZone
!==
null
&&
!
$timeZone
instanceof
\DateTimeZone
)
{
$timeZone
=
new
\DateTimeZone
(
$timeZone
);
}
/** @var \OC\DateTimeFormatter $formatter */
$formatter
=
\OC
::
$server
->
query
(
'DateTimeFormatter'
);
if
(
$dateOnly
)
{
return
$formatter
->
formatDate
(
$timestamp
,
'long'
,
$timeZone
);
}
return
$formatter
->
formatDateTime
(
$timestamp
,
'long'
,
'long'
,
$timeZone
);
}
/**
* check if the current server configuration is suitable for ownCloud
*
...
...
This diff is collapsed.
Click to expand it.
settings/templates/settings/admin/server.php
+
3
−
1
View file @
44289ff1
...
...
@@ -159,7 +159,9 @@
<p
class=
"cronlog inlineblock"
>
<?php
if
(
$_
[
'lastcron'
]
!==
false
)
:
$relative_time
=
relative_modified_date
(
$_
[
'lastcron'
]);
$absolute_time
=
OC_Util
::
formatDate
(
$_
[
'lastcron'
]);
$formatter
=
\OC
::
$server
->
getDateTimeFormatter
();
$absolute_time
=
$formatter
->
formatDateTime
(
$_
[
'lastcron'
],
'long'
,
'long'
);
if
(
time
()
-
$_
[
'lastcron'
]
<=
3600
)
:
?>
<span
class=
"status success"
></span>
<span
class=
"crondate"
title=
"
<?php
p
(
$absolute_time
);
?>
"
>
...
...
This diff is collapsed.
Click to expand it.
tests/lib/UtilTest.php
+
0
−
64
View file @
44289ff1
...
...
@@ -38,70 +38,6 @@ class UtilTest extends \Test\TestCase {
$this
->
assertTrue
(
is_string
(
$edition
));
}
/**
* @group DB
*/
function
testFormatDate
()
{
date_default_timezone_set
(
"UTC"
);
$result
=
OC_Util
::
formatDate
(
1350129205
);
$expected
=
'October 13, 2012 at 11:53:25 AM GMT+0'
;
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
OC_Util
::
formatDate
(
1102831200
,
true
);
$expected
=
'December 12, 2004'
;
$this
->
assertEquals
(
$expected
,
$result
);
}
/**
* @group DB
*/
function
testFormatDateWithTZ
()
{
date_default_timezone_set
(
"UTC"
);
$result
=
OC_Util
::
formatDate
(
1350129205
,
false
,
'Europe/Berlin'
);
$expected
=
'October 13, 2012 at 1:53:25 PM GMT+2'
;
$this
->
assertEquals
(
$expected
,
$result
);
}
/**
* @expectedException \Exception
*/
function
testFormatDateWithInvalidTZ
()
{
OC_Util
::
formatDate
(
1350129205
,
false
,
'Mordor/Barad-dûr'
);
}
public
function
formatDateWithTZFromSessionData
()
{
return
array
(
array
(
3
,
'October 13, 2012 at 2:53:25 PM GMT+3'
,
'Etc/GMT-3'
),
array
(
15
,
'October 13, 2012 at 11:53:25 AM GMT+0'
,
'UTC'
),
array
(
-
13
,
'October 13, 2012 at 11:53:25 AM GMT+0'
,
'UTC'
),
array
(
9.5
,
'October 13, 2012 at 9:23:25 PM GMT+9:30'
,
'Australia/Darwin'
),
array
(
-
4.5
,
'October 13, 2012 at 7:23:25 AM GMT-4:30'
,
'America/Caracas'
),
array
(
15.5
,
'October 13, 2012 at 11:53:25 AM GMT+0'
,
'UTC'
),
);
}
/**
* @dataProvider formatDateWithTZFromSessionData
* @group DB
*/
function
testFormatDateWithTZFromSession
(
$offset
,
$expected
,
$expectedTimeZone
)
{
date_default_timezone_set
(
"UTC"
);
\OC
::
$server
->
getSession
()
->
set
(
'timezone'
,
$offset
);
$selectedTimeZone
=
\OC
::
$server
->
getDateTimeZone
()
->
getTimeZone
(
1350129205
);
$this
->
assertEquals
(
$expectedTimeZone
,
$selectedTimeZone
->
getName
());
$newDateTimeFormatter
=
new
\OC\DateTimeFormatter
(
$selectedTimeZone
,
\OC
::
$server
->
getL10N
(
'lib'
,
'en'
));
$this
->
overwriteService
(
'DateTimeFormatter'
,
$newDateTimeFormatter
);
$result
=
OC_Util
::
formatDate
(
1350129205
,
false
);
$this
->
assertEquals
(
$expected
,
$result
);
$this
->
restoreService
(
'DateTimeFormatter'
);
}
function
testSanitizeHTML
()
{
$badArray
=
[
'While it is unusual to pass an array'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment