Skip to content

Commit 01b0f7d

Browse files
authored
Merge pull request #385 from thecodingmachine/mktime
deprecated mktime and regenerated the files
2 parents d6ff856 + c0a7a02 commit 01b0f7d

File tree

7 files changed

+136
-87
lines changed

7 files changed

+136
-87
lines changed

deprecated/datetime.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,65 @@ function gmdate(string $format, int $timestamp = null): string
3434
}
3535
return $result;
3636
}
37+
38+
/**
39+
* Returns the Unix timestamp corresponding to the arguments
40+
* given. This timestamp is a long integer containing the number of
41+
* seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
42+
* specified.
43+
*
44+
* Arguments may be left out in order from right to left; any
45+
* arguments thus omitted will be set to the current value according
46+
* to the local date and time.
47+
*
48+
* @param int $hour The number of the hour relative to the start of the day determined by
49+
* month, day and year.
50+
* Negative values reference the hour before midnight of the day in question.
51+
* Values greater than 23 reference the appropriate hour in the following day(s).
52+
* @param int $minute The number of the minute relative to the start of the hour.
53+
* Negative values reference the minute in the previous hour.
54+
* Values greater than 59 reference the appropriate minute in the following hour(s).
55+
* @param int $second The number of seconds relative to the start of the minute.
56+
* Negative values reference the second in the previous minute.
57+
* Values greater than 59 reference the appropriate second in the following minute(s).
58+
* @param int $month The number of the month relative to the end of the previous year.
59+
* Values 1 to 12 reference the normal calendar months of the year in question.
60+
* 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.
61+
* Values greater than 12 reference the appropriate month in the following year(s).
62+
* @param int $day The number of the day relative to the end of the previous month.
63+
* Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
64+
* 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.
65+
* Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
66+
* @param int $year The number of the year, may be a two or four digit value,
67+
* with values between 0-69 mapping to 2000-2069 and 70-100 to
68+
* 1970-2000. On systems where time_t is a 32bit signed integer, as
69+
* most common today, the valid range for year
70+
* is somewhere between 1901 and 2038.
71+
* @return int mktime returns the Unix timestamp of the arguments
72+
* given.
73+
* If the arguments are invalid, the function returns FALSE.
74+
* @throws DatetimeException
75+
* @deprecated The Safe version of this function is no longer needed in PHP 8.0+
76+
*
77+
*/
78+
function mktime(int $hour, int $minute = null, int $second = null, int $month = null, int $day = null, int $year = null): int
79+
{
80+
error_clear_last();
81+
if ($year !== null) {
82+
$safeResult = \mktime($hour, $minute, $second, $month, $day, $year);
83+
} elseif ($day !== null) {
84+
$safeResult = \mktime($hour, $minute, $second, $month, $day);
85+
} elseif ($month !== null) {
86+
$safeResult = \mktime($hour, $minute, $second, $month);
87+
} elseif ($second !== null) {
88+
$safeResult = \mktime($hour, $minute, $second);
89+
} elseif ($minute !== null) {
90+
$safeResult = \mktime($hour, $minute);
91+
} else {
92+
$safeResult = \mktime($hour);
93+
}
94+
if ($safeResult === false) {
95+
throw DatetimeException::createFromPhpError();
96+
}
97+
return $safeResult;
98+
}

deprecated/functionsList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'imagepsslantfont',
4444
'krsort',
4545
'ksort',
46+
'mktime',
4647
'mssql_bind',
4748
'mssql_close',
4849
'mssql_connect',

generated/datetime.php

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,39 @@
77
/**
88
* Returns associative array with detailed info about given date/time.
99
*
10-
* @param string $format Format accepted by DateTime::createFromFormat.
10+
* @param string $format Format accepted by DateTimeImmutable::createFromFormat.
1111
* @param string $datetime String representing the date/time.
1212
* @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.
13+
*
14+
* The returned array has keys for year,
15+
* month, day, hour,
16+
* minute, second,
17+
* fraction, and is_localtime.
18+
*
19+
* If is_localtime is present then
20+
* zone_type indicates the type of timezone. For type
21+
* 1 (UTC offset) the zone,
22+
* is_dst fields are added; for type 2
23+
* (abbreviation) the fields tz_abbr,
24+
* is_dst are added; and for type 3
25+
* (timezone identifier) the tz_abbr,
26+
* tz_id are added.
27+
*
28+
* The array includes warning_count and
29+
* warnings fields. The first one indicate how many
30+
* warnings there were.
31+
* The keys of elements warnings array indicate the
32+
* position in the given datetime where the warning
33+
* occurred, with the string value describing the warning itself. An example
34+
* below shows such a warning.
35+
*
36+
* The array also contains error_count and
37+
* errors fields. The first one indicate how many errors
38+
* were found.
39+
* The keys of elements errors array indicate the
40+
* position in the given datetime where the error
41+
* occurred, with the string value describing the error itself. An example
42+
* below shows such an error.
1343
* @throws DatetimeException
1444
*
1545
*/
@@ -45,6 +75,43 @@ function date_parse_from_format(string $format, string $datetime): ?array
4575
* DateTimeImmutable::__construct.
4676
* @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
4777
* on success.
78+
*
79+
* The returned array has keys for year,
80+
* month, day, hour,
81+
* minute, second,
82+
* fraction, and is_localtime.
83+
*
84+
* If is_localtime is present then
85+
* zone_type indicates the type of timezone. For type
86+
* 1 (UTC offset) the zone,
87+
* is_dst fields are added; for type 2
88+
* (abbreviation) the fields tz_abbr,
89+
* is_dst are added; and for type 3
90+
* (timezone identifier) the tz_abbr,
91+
* tz_id are added.
92+
*
93+
* If relative time elements are present in the
94+
* datetime string such as +3 days,
95+
* the then returned array includes a nested array with the key
96+
* relative. This array then contains the keys
97+
* year, month, day,
98+
* hour, minute,
99+
* second, and if necessary weekday, and
100+
* weekdays, depending on the string that was passed in.
101+
*
102+
* The array includes warning_count and
103+
* warnings fields. The first one indicate how many
104+
* warnings there were.
105+
* The keys of elements warnings array indicate the
106+
* position in the given datetime where the warning
107+
* occurred, with the string value describing the warning itself.
108+
*
109+
* The array also contains error_count and
110+
* errors fields. The first one indicate how many errors
111+
* were found.
112+
* The keys of elements errors array indicate the
113+
* position in the given datetime where the error
114+
* occurred, with the string value describing the error itself.
48115
* @throws DatetimeException
49116
*
50117
*/
@@ -98,15 +165,17 @@ function date_parse(string $datetime): ?array
98165
* civil_twilight_begin
99166
*
100167
*
101-
* The start of the civil dawn (zenith angle = 96°). It ends at sunrise.
168+
* The start of the civil dawn (zenith angle = 96°). It ends at
169+
* sunrise.
102170
*
103171
*
104172
*
105173
*
106174
* civil_twilight_end
107175
*
108176
*
109-
* The end of the civil dusk (zenith angle = 96°). It starts at sunset.
177+
* The end of the civil dusk (zenith angle = 96°). It starts at
178+
* sunset.
110179
*
111180
*
112181
*
@@ -377,11 +446,6 @@ function date_sunset(int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING, fl
377446
* if no timestamp is given. In other words, timestamp
378447
* is optional and defaults to the value of time.
379448
*
380-
* Unix timestamps do not handle timezones. Use the
381-
* DateTimeImmutable class, and its
382-
* DateTimeInterface::format formatting method to
383-
* format date/time information with a timezone attached.
384-
*
385449
* @param string $format Format accepted by DateTimeInterface::format.
386450
* @param int $timestamp The optional timestamp parameter is an
387451
* int Unix timestamp that defaults to the current
@@ -630,83 +694,11 @@ function idate(string $format, int $timestamp = null): int
630694
}
631695

632696

633-
/**
634-
* Returns the Unix timestamp corresponding to the arguments
635-
* given. This timestamp is a long integer containing the number of
636-
* seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
637-
* specified.
638-
*
639-
* Arguments may be left out in order from right to left; any
640-
* arguments thus omitted will be set to the current value according
641-
* to the local date and time.
642-
*
643-
* @param int $hour The number of the hour relative to the start of the day determined by
644-
* month, day and year.
645-
* Negative values reference the hour before midnight of the day in question.
646-
* Values greater than 23 reference the appropriate hour in the following day(s).
647-
* @param int $minute The number of the minute relative to the start of the hour.
648-
* Negative values reference the minute in the previous hour.
649-
* Values greater than 59 reference the appropriate minute in the following hour(s).
650-
* @param int $second The number of seconds relative to the start of the minute.
651-
* Negative values reference the second in the previous minute.
652-
* Values greater than 59 reference the appropriate second in the following minute(s).
653-
* @param int $month The number of the month relative to the end of the previous year.
654-
* Values 1 to 12 reference the normal calendar months of the year in question.
655-
* 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.
656-
* Values greater than 12 reference the appropriate month in the following year(s).
657-
* @param int $day The number of the day relative to the end of the previous month.
658-
* Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
659-
* 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.
660-
* Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
661-
* @param int $year The number of the year, may be a two or four digit value,
662-
* with values between 0-69 mapping to 2000-2069 and 70-100 to
663-
* 1970-2000. On systems where time_t is a 32bit signed integer, as
664-
* most common today, the valid range for year
665-
* is somewhere between 1901 and 2038.
666-
* @return int mktime returns the Unix timestamp of the arguments
667-
* given.
668-
* If the arguments are invalid, the function returns FALSE.
669-
* @throws DatetimeException
670-
*
671-
*/
672-
function mktime(int $hour, int $minute = null, int $second = null, int $month = null, int $day = null, int $year = null): int
673-
{
674-
error_clear_last();
675-
if ($year !== null) {
676-
$safeResult = \mktime($hour, $minute, $second, $month, $day, $year);
677-
} elseif ($day !== null) {
678-
$safeResult = \mktime($hour, $minute, $second, $month, $day);
679-
} elseif ($month !== null) {
680-
$safeResult = \mktime($hour, $minute, $second, $month);
681-
} elseif ($second !== null) {
682-
$safeResult = \mktime($hour, $minute, $second);
683-
} elseif ($minute !== null) {
684-
$safeResult = \mktime($hour, $minute);
685-
} else {
686-
$safeResult = \mktime($hour);
687-
}
688-
if ($safeResult === false) {
689-
throw DatetimeException::createFromPhpError();
690-
}
691-
return $safeResult;
692-
}
693-
694-
695697
/**
696698
* Format the time and/or date according to locale settings. Month and weekday
697699
* names and other language-dependent strings respect the current locale set
698700
* with setlocale.
699701
*
700-
* Not all conversion specifiers may be supported by your C library, in which
701-
* case they will not be supported by PHP's strftime.
702-
* Additionally, not all platforms support negative timestamps, so your
703-
* date range may be limited to no earlier than the Unix epoch. This means that
704-
* %e, %T, %R and, %D (and possibly others) - as well as dates prior to
705-
* Jan 1, 1970 - will not work on Windows, some Linux
706-
* distributions, and a few other operating systems. For Windows systems, a
707-
* complete overview of supported conversion specifiers can be found at
708-
* MSDN.
709-
*
710702
* @param string $format
711703
* The following characters are recognized in the
712704
* format parameter string

generated/functionsList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@
520520
'md5_file',
521521
'mime_content_type',
522522
'mkdir',
523-
'mktime',
524523
'msg_get_queue',
525524
'msg_queue_exists',
526525
'msg_receive',

generator/tests/DateTimeImmutableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function testDatePeriodBug(): void
176176

177177
/** @var DateTimeImmutable $date */
178178
foreach ($datePeriod as $date) {
179-
$this->expectException(\TypeError::class);
179+
$this->expectException(\Error::class);
180180
$this->assertNull($date->getInnerDateTime());
181181
}
182182

generator/tests/DocPageTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ public function testDetectFalsyFunction()
1616
$mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml');
1717
$fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml');
1818
$arrayReplace = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/array/functions/array-replace.xml');
19-
$mktime = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/mktime.xml');
2019
$date = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/date.xml');
2120
$classImplement = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/spl/functions/class-implements.xml');
2221
$getHeaders = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/url/functions/get-headers.xml');
2322
$gzopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/zlib/functions/gzopen.xml');
2423
$fopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/image/functions/imagecreatefromstring.xml');
25-
//$ldapSearch = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/ldap/functions/ldap-search.xml');
2624

2725
$this->assertTrue($pregMatch->detectFalsyFunction());
2826
$this->assertFalse($implode->detectFalsyFunction());
@@ -32,13 +30,11 @@ public function testDetectFalsyFunction()
3230
$this->assertTrue($mcryptDecrypt->detectFalsyFunction());
3331
$this->assertTrue($fsockopen->detectFalsyFunction());
3432
$this->assertFalse($arrayReplace->detectFalsyFunction());
35-
$this->assertTrue($mktime->detectFalsyFunction());
3633
$this->assertTrue($date->detectFalsyFunction());
3734
$this->assertTrue($classImplement->detectFalsyFunction());
3835
$this->assertTrue($getHeaders->detectFalsyFunction());
3936
$this->assertTrue($gzopen->detectFalsyFunction());
4037
$this->assertTrue($fopen->detectFalsyFunction());
41-
//$this->assertTrue($ldapSearch->detectFalsyFunction());
4238
}
4339

4440
public function testDetectNullsyFunction()

rector-migrate.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@
527527
'md5_file' => 'Safe\md5_file',
528528
'mime_content_type' => 'Safe\mime_content_type',
529529
'mkdir' => 'Safe\mkdir',
530-
'mktime' => 'Safe\mktime',
531530
'msg_get_queue' => 'Safe\msg_get_queue',
532531
'msg_queue_exists' => 'Safe\msg_queue_exists',
533532
'msg_receive' => 'Safe\msg_receive',

0 commit comments

Comments
 (0)