Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pasteque
pasteque-server
Commits
81372b25
Commit
81372b25
authored
May 05, 2020
by
Karamel
Browse files
Allow to pass timestamp as a string to DateUtils::readDate.
parent
76f4e9b8
Changes
2
Show whitespace changes
Inline
Side-by-side
src/lib/System/DateUtils.php
View file @
81372b25
...
@@ -95,8 +95,12 @@ class DateUtils
...
@@ -95,8 +95,12 @@ class DateUtils
*/
*/
public
static
function
readDate
(
$input
)
{
public
static
function
readDate
(
$input
)
{
if
(
$input
===
null
)
{
return
null
;
}
if
(
$input
===
null
)
{
return
null
;
}
if
(
is_numeric
(
$input
))
{
if
(
is_int
(
$input
))
{
if
(
is_int
(
$input
))
{
return
static
::
readTimestamp
(
$input
);
return
static
::
readTimestamp
(
$input
);
}
else
{
return
static
::
readTimestamp
(
intval
(
$input
));
}
}
}
if
(
$input
instanceof
\
DateTime
)
{
if
(
$input
instanceof
\
DateTime
)
{
return
$input
;
return
$input
;
...
...
tests/System/DateUtilsTest.php
View file @
81372b25
...
@@ -74,6 +74,13 @@ class DateUtilsTest extends TestCase {
...
@@ -74,6 +74,13 @@ class DateUtilsTest extends TestCase {
$this
->
assertEquals
(
$timestamp
,
$date
->
getTimestamp
());
$this
->
assertEquals
(
$timestamp
,
$date
->
getTimestamp
());
}
}
public
function
testReadDateTimestampString
()
{
$timestamp
=
'1171502725'
;
$date
=
DateUtils
::
readDate
(
$timestamp
);
$this
->
assertNotEquals
(
false
,
$date
);
$this
->
assertEquals
(
$timestamp
,
$date
->
getTimestamp
());
}
public
function
testReadDateDateTime
()
{
public
function
testReadDateDateTime
()
{
$timestamp
=
1171502725
;
$timestamp
=
1171502725
;
$date
=
new
\
DateTime
();
$date
=
new
\
DateTime
();
...
...
Write
Preview
Supports
Markdown
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