Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

deprecated mktime and regenerated the files #385

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions deprecated/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,65 @@ function gmdate(string $format, int $timestamp = null): string
}
return $result;
}

/**
* Returns the Unix timestamp corresponding to the arguments
* given. This timestamp is a long integer containing the number of
* seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
* specified.
*
* Arguments may be left out in order from right to left; any
* arguments thus omitted will be set to the current value according
* to the local date and time.
*
* @param int $hour The number of the hour relative to the start of the day determined by
* month, day and year.
* Negative values reference the hour before midnight of the day in question.
* Values greater than 23 reference the appropriate hour in the following day(s).
* @param int $minute The number of the minute relative to the start of the hour.
* Negative values reference the minute in the previous hour.
* Values greater than 59 reference the appropriate minute in the following hour(s).
* @param int $second The number of seconds relative to the start of the minute.
* Negative values reference the second in the previous minute.
* Values greater than 59 reference the appropriate second in the following minute(s).
* @param int $month The number of the month relative to the end of the previous year.
* Values 1 to 12 reference the normal calendar months of the year in question.
* Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc.
* Values greater than 12 reference the appropriate month in the following year(s).
* @param int $day The number of the day relative to the end of the previous month.
* Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
* Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc.
* Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
* @param int $year The number of the year, may be a two or four digit value,
* with values between 0-69 mapping to 2000-2069 and 70-100 to
* 1970-2000. On systems where time_t is a 32bit signed integer, as
* most common today, the valid range for year
* is somewhere between 1901 and 2038.
* @return int mktime returns the Unix timestamp of the arguments
* given.
* If the arguments are invalid, the function returns FALSE.
* @throws DatetimeException
* @deprecated The Safe version of this function is no longer needed in PHP 8.0+
*
*/
function mktime(int $hour, int $minute = null, int $second = null, int $month = null, int $day = null, int $year = null): int
{
error_clear_last();
if ($year !== null) {
$safeResult = \mktime($hour, $minute, $second, $month, $day, $year);
} elseif ($day !== null) {
$safeResult = \mktime($hour, $minute, $second, $month, $day);
} elseif ($month !== null) {
$safeResult = \mktime($hour, $minute, $second, $month);
} elseif ($second !== null) {
$safeResult = \mktime($hour, $minute, $second);
} elseif ($minute !== null) {
$safeResult = \mktime($hour, $minute);
} else {
$safeResult = \mktime($hour);
}
if ($safeResult === false) {
throw DatetimeException::createFromPhpError();
}
return $safeResult;
}
1 change: 1 addition & 0 deletions deprecated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'imagepsslantfont',
'krsort',
'ksort',
'mktime',
'mssql_bind',
'mssql_close',
'mssql_connect',
Expand Down
152 changes: 72 additions & 80 deletions generated/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,39 @@
/**
* Returns associative array with detailed info about given date/time.
*
* @param string $format Format accepted by DateTime::createFromFormat.
* @param string $format Format accepted by DateTimeImmutable::createFromFormat.
* @param string $datetime String representing the date/time.
* @return array{year: int|false, month: int|false, day: int|false, hour: int|false, minute: int|false, second: int|false, fraction: float|false, warning_count: int, warnings: string[], error_count: int, errors: string[], is_localtime: bool, zone_type: int|bool, zone: int|bool, is_dst: bool, tz_abbr: string, tz_id: string, relative: array{year: int, month: int, day: int, hour: int, minute: int, second: int, weekday: int, weekdays: int, first_day_of_month: bool, last_day_of_month: bool}}|null Returns associative array with detailed info about given date/time.
*
* The returned array has keys for year,
* month, day, hour,
* minute, second,
* fraction, and is_localtime.
*
* If is_localtime is present then
* zone_type indicates the type of timezone. For type
* 1 (UTC offset) the zone,
* is_dst fields are added; for type 2
* (abbreviation) the fields tz_abbr,
* is_dst are added; and for type 3
* (timezone identifier) the tz_abbr,
* tz_id are added.
*
* The array includes warning_count and
* warnings fields. The first one indicate how many
* warnings there were.
* The keys of elements warnings array indicate the
* position in the given datetime where the warning
* occurred, with the string value describing the warning itself. An example
* below shows such a warning.
*
* The array also contains error_count and
* errors fields. The first one indicate how many errors
* were found.
* The keys of elements errors array indicate the
* position in the given datetime where the error
* occurred, with the string value describing the error itself. An example
* below shows such an error.
* @throws DatetimeException
*
*/
Expand Down Expand Up @@ -45,6 +75,43 @@ function date_parse_from_format(string $format, string $datetime): ?array
* DateTimeImmutable::__construct.
* @return array{year: int|false, month: int|false, day: int|false, hour: int|false, minute: int|false, second: int|false, fraction: float|false, warning_count: int, warnings: string[], error_count: int, errors: string[], is_localtime: bool, zone_type: int|bool, zone: int|bool, is_dst: bool, tz_abbr: string, tz_id: string, relative: array{year: int, month: int, day: int, hour: int, minute: int, second: int, weekday: int, weekdays: int, first_day_of_month: bool, last_day_of_month: bool}}|null Returns array with information about the parsed date/time
* on success.
*
* The returned array has keys for year,
* month, day, hour,
* minute, second,
* fraction, and is_localtime.
*
* If is_localtime is present then
* zone_type indicates the type of timezone. For type
* 1 (UTC offset) the zone,
* is_dst fields are added; for type 2
* (abbreviation) the fields tz_abbr,
* is_dst are added; and for type 3
* (timezone identifier) the tz_abbr,
* tz_id are added.
*
* If relative time elements are present in the
* datetime string such as +3 days,
* the then returned array includes a nested array with the key
* relative. This array then contains the keys
* year, month, day,
* hour, minute,
* second, and if necessary weekday, and
* weekdays, depending on the string that was passed in.
*
* The array includes warning_count and
* warnings fields. The first one indicate how many
* warnings there were.
* The keys of elements warnings array indicate the
* position in the given datetime where the warning
* occurred, with the string value describing the warning itself.
*
* The array also contains error_count and
* errors fields. The first one indicate how many errors
* were found.
* The keys of elements errors array indicate the
* position in the given datetime where the error
* occurred, with the string value describing the error itself.
* @throws DatetimeException
*
*/
Expand Down Expand Up @@ -98,15 +165,17 @@ function date_parse(string $datetime): ?array
* civil_twilight_begin
*
*
* The start of the civil dawn (zenith angle = 96°). It ends at sunrise.
* The start of the civil dawn (zenith angle = 96°). It ends at
* sunrise.
*
*
*
*
* civil_twilight_end
*
*
* The end of the civil dusk (zenith angle = 96°). It starts at sunset.
* The end of the civil dusk (zenith angle = 96°). It starts at
* sunset.
*
*
*
Expand Down Expand Up @@ -377,11 +446,6 @@ function date_sunset(int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING, fl
* if no timestamp is given. In other words, timestamp
* is optional and defaults to the value of time.
*
* Unix timestamps do not handle timezones. Use the
* DateTimeImmutable class, and its
* DateTimeInterface::format formatting method to
* format date/time information with a timezone attached.
*
* @param string $format Format accepted by DateTimeInterface::format.
* @param int $timestamp The optional timestamp parameter is an
* int Unix timestamp that defaults to the current
Expand Down Expand Up @@ -630,83 +694,11 @@ function idate(string $format, int $timestamp = null): int
}


/**
* Returns the Unix timestamp corresponding to the arguments
* given. This timestamp is a long integer containing the number of
* seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
* specified.
*
* Arguments may be left out in order from right to left; any
* arguments thus omitted will be set to the current value according
* to the local date and time.
*
* @param int $hour The number of the hour relative to the start of the day determined by
* month, day and year.
* Negative values reference the hour before midnight of the day in question.
* Values greater than 23 reference the appropriate hour in the following day(s).
* @param int $minute The number of the minute relative to the start of the hour.
* Negative values reference the minute in the previous hour.
* Values greater than 59 reference the appropriate minute in the following hour(s).
* @param int $second The number of seconds relative to the start of the minute.
* Negative values reference the second in the previous minute.
* Values greater than 59 reference the appropriate second in the following minute(s).
* @param int $month The number of the month relative to the end of the previous year.
* Values 1 to 12 reference the normal calendar months of the year in question.
* Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc.
* Values greater than 12 reference the appropriate month in the following year(s).
* @param int $day The number of the day relative to the end of the previous month.
* Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
* Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc.
* Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
* @param int $year The number of the year, may be a two or four digit value,
* with values between 0-69 mapping to 2000-2069 and 70-100 to
* 1970-2000. On systems where time_t is a 32bit signed integer, as
* most common today, the valid range for year
* is somewhere between 1901 and 2038.
* @return int mktime returns the Unix timestamp of the arguments
* given.
* If the arguments are invalid, the function returns FALSE.
* @throws DatetimeException
*
*/
function mktime(int $hour, int $minute = null, int $second = null, int $month = null, int $day = null, int $year = null): int
{
error_clear_last();
if ($year !== null) {
$safeResult = \mktime($hour, $minute, $second, $month, $day, $year);
} elseif ($day !== null) {
$safeResult = \mktime($hour, $minute, $second, $month, $day);
} elseif ($month !== null) {
$safeResult = \mktime($hour, $minute, $second, $month);
} elseif ($second !== null) {
$safeResult = \mktime($hour, $minute, $second);
} elseif ($minute !== null) {
$safeResult = \mktime($hour, $minute);
} else {
$safeResult = \mktime($hour);
}
if ($safeResult === false) {
throw DatetimeException::createFromPhpError();
}
return $safeResult;
}


/**
* Format the time and/or date according to locale settings. Month and weekday
* names and other language-dependent strings respect the current locale set
* with setlocale.
*
* Not all conversion specifiers may be supported by your C library, in which
* case they will not be supported by PHP's strftime.
* Additionally, not all platforms support negative timestamps, so your
* date range may be limited to no earlier than the Unix epoch. This means that
* %e, %T, %R and, %D (and possibly others) - as well as dates prior to
* Jan 1, 1970 - will not work on Windows, some Linux
* distributions, and a few other operating systems. For Windows systems, a
* complete overview of supported conversion specifiers can be found at
* MSDN.
*
* @param string $format
* The following characters are recognized in the
* format parameter string
Expand Down
1 change: 0 additions & 1 deletion generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@
'md5_file',
'mime_content_type',
'mkdir',
'mktime',
'msg_get_queue',
'msg_queue_exists',
'msg_receive',
Expand Down
2 changes: 1 addition & 1 deletion generator/tests/DateTimeImmutableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testDatePeriodBug(): void

/** @var DateTimeImmutable $date */
foreach ($datePeriod as $date) {
$this->expectException(\TypeError::class);
$this->expectException(\Error::class);
$this->assertNull($date->getInnerDateTime());
}

Expand Down
4 changes: 0 additions & 4 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ public function testDetectFalsyFunction()
$mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml');
$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');
$classImplement = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/spl/functions/class-implements.xml');
$getHeaders = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/url/functions/get-headers.xml');
$gzopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/zlib/functions/gzopen.xml');
$fopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/image/functions/imagecreatefromstring.xml');
//$ldapSearch = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/ldap/functions/ldap-search.xml');

$this->assertTrue($pregMatch->detectFalsyFunction());
$this->assertFalse($implode->detectFalsyFunction());
Expand All @@ -32,13 +30,11 @@ public function testDetectFalsyFunction()
$this->assertTrue($mcryptDecrypt->detectFalsyFunction());
$this->assertTrue($fsockopen->detectFalsyFunction());
$this->assertFalse($arrayReplace->detectFalsyFunction());
$this->assertTrue($mktime->detectFalsyFunction());
$this->assertTrue($date->detectFalsyFunction());
$this->assertTrue($classImplement->detectFalsyFunction());
$this->assertTrue($getHeaders->detectFalsyFunction());
$this->assertTrue($gzopen->detectFalsyFunction());
$this->assertTrue($fopen->detectFalsyFunction());
//$this->assertTrue($ldapSearch->detectFalsyFunction());
}

public function testDetectNullsyFunction()
Expand Down
1 change: 0 additions & 1 deletion rector-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@
'md5_file' => 'Safe\md5_file',
'mime_content_type' => 'Safe\mime_content_type',
'mkdir' => 'Safe\mkdir',
'mktime' => 'Safe\mktime',
'msg_get_queue' => 'Safe\msg_get_queue',
'msg_queue_exists' => 'Safe\msg_queue_exists',
'msg_receive' => 'Safe\msg_receive',
Expand Down