Skip to content

Commit

Permalink
Merge pull request #246 from Kharhamel/dateFunction
Browse files Browse the repository at this point in the history
Date function
  • Loading branch information
Kharhamel authored Oct 22, 2020
2 parents 7026ace + f531da1 commit 72d9fee
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
63 changes: 63 additions & 0 deletions generated/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,69 @@ function date_sunset(int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING, fl
}


/**
* Returns a string formatted according to the given format string using the
* given integer timestamp or the current time
* if no timestamp is given. In other words, timestamp
* is optional and defaults to the value of time.
*
* @param string $format Format accepted by DateTimeInterface::format.
* @param int $timestamp The optional timestamp parameter is an
* integer Unix timestamp that defaults to the current
* local time if a timestamp is not given. In other
* words, it defaults to the value of time.
* @return string Returns a formatted date string. If a non-numeric value is used for
* timestamp, FALSE is returned and an
* E_WARNING level error is emitted.
* @throws DatetimeException
*
*/
function date(string $format, int $timestamp = null): string
{
error_clear_last();
if ($timestamp !== null) {
$result = \date($format, $timestamp);
} else {
$result = \date($format);
}
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}


/**
* Identical to the date function except that
* the time returned is Greenwich Mean Time (GMT).
*
* @param string $format The format of the outputted date string. See the formatting
* options for the date function.
* @param int $timestamp The optional timestamp parameter is an
* integer Unix timestamp that defaults to the current
* local time if a timestamp is not given. In other
* words, it defaults to the value of time.
* @return string Returns a formatted date string. If a non-numeric value is used for
* timestamp, FALSE is returned and an
* E_WARNING level error is emitted.
* @throws DatetimeException
*
*/
function gmdate(string $format, int $timestamp = null): string
{
error_clear_last();
if ($timestamp !== null) {
$result = \gmdate($format, $timestamp);
} else {
$result = \gmdate($format);
}
if ($result === false) {
throw DatetimeException::createFromPhpError();
}
return $result;
}


/**
* Returns the Unix timestamp corresponding to the arguments
* given. This timestamp is a long integer containing the number of
Expand Down
2 changes: 2 additions & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'curl_share_errno',
'curl_share_setopt',
'curl_unescape',
'date',
'date_parse',
'date_parse_from_format',
'date_sunrise',
Expand Down Expand Up @@ -191,6 +192,7 @@
'getprotobynumber',
'get_headers',
'glob',
'gmdate',
'gmp_binomial',
'gmp_export',
'gmp_import',
Expand Down
5 changes: 5 additions & 0 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public function detectFalsyFunction(): bool
if (preg_match('/&gd\.return\.identifier;/m', $file)) {
return true;
}
//used for date
if (preg_match('/If a non-numeric value is used for
\<parameter\>timestamp\<\/parameter\>, &false; is returned/m', $file)) {
return true;
}

//used to detect imagecreatefromstring
if (preg_match('/If the arguments are invalid, the function returns &false;/m', $file)) {
Expand Down
2 changes: 2 additions & 0 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testDetectFalsyFunction()
$fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml');
$arrayReplace = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/array/functions/array-replace.xml');
$mktime = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/mktime.xml');
$date = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/date.xml');

$this->assertTrue($pregMatch->detectFalsyFunction());
$this->assertFalse($implode->detectFalsyFunction());
Expand All @@ -29,6 +30,7 @@ public function testDetectFalsyFunction()
$this->assertTrue($fsockopen->detectFalsyFunction());
$this->assertFalse($arrayReplace->detectFalsyFunction());
$this->assertTrue($mktime->detectFalsyFunction());
$this->assertTrue($date->detectFalsyFunction());
}

public function testDetectNullsyFunction()
Expand Down
2 changes: 2 additions & 0 deletions rector-migrate-0.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
'curl_share_errno' => 'Safe\curl_share_errno',
'curl_share_setopt' => 'Safe\curl_share_setopt',
'curl_unescape' => 'Safe\curl_unescape',
'date' => 'Safe\date',
'date_parse' => 'Safe\date_parse',
'date_parse_from_format' => 'Safe\date_parse_from_format',
'date_sunrise' => 'Safe\date_sunrise',
Expand Down Expand Up @@ -201,6 +202,7 @@
'getprotobynumber' => 'Safe\getprotobynumber',
'get_headers' => 'Safe\get_headers',
'glob' => 'Safe\glob',
'gmdate' => 'Safe\gmdate',
'gmp_binomial' => 'Safe\gmp_binomial',
'gmp_export' => 'Safe\gmp_export',
'gmp_import' => 'Safe\gmp_import',
Expand Down

0 comments on commit 72d9fee

Please # to comment.