Skip to content

Commit 331edda

Browse files
committed
Make date/time type arguments of IntlDateFormatter ctor optional
Default them to IntlDateFormatter:FULL, which has value 0, which was what you would get if you passed null to these arguments in weak typing mode. The documentation called this ICU's default date/time type.
1 parent bd2c743 commit 331edda

6 files changed

+61
-18
lines changed

ext/intl/dateformat/dateformat.stub.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@ class IntlDateFormatter
88
* @param IntlTimeZone|DateTimeZone|string|null $timezone
99
* @param IntlCalendar|int|null $calendar
1010
*/
11-
public function __construct(?string $locale, int $dateType, int $timeType, $timezone = null, $calendar = null, ?string $pattern = null) {}
11+
public function __construct(
12+
?string $locale,
13+
int $dateType = IntlDateFormatter::FULL,
14+
int $timeType = IntlDateFormatter::FULL,
15+
$timezone = null,
16+
$calendar = null,
17+
?string $pattern = null
18+
) {}
1219

1320
/**
1421
* @param IntlTimeZone|DateTimeZone|string|null $timezone
1522
* @return IntlDateFormatter|null
1623
* @alias datefmt_create
1724
*/
18-
public static function create(?string $locale, int $dateType, int $timeType, $timezone = null, IntlCalendar|int|null $calendar = null, ?string $pattern = null) {}
25+
public static function create(
26+
?string $locale,
27+
int $dateType = IntlDateFormatter::FULL,
28+
int $timeType = IntlDateFormatter::FULL,
29+
$timezone = null,
30+
IntlCalendar|int|null $calendar = null,
31+
?string $pattern = null
32+
) {}
1933

2034
/**
2135
* @return int|false

ext/intl/dateformat/dateformat_arginfo.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: a83ee23ab33293a878280f137260da9f8914218a */
2+
* Stub hash: 5fd68ae153d18374d33a5c3848a88abc1ab67d38 */
33

4-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlDateFormatter___construct, 0, 0, 3)
4+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlDateFormatter___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 1)
6-
ZEND_ARG_TYPE_INFO(0, dateType, IS_LONG, 0)
7-
ZEND_ARG_TYPE_INFO(0, timeType, IS_LONG, 0)
6+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, dateType, IS_LONG, 0, "IntlDateFormatter::FULL")
7+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeType, IS_LONG, 0, "IntlDateFormatter::FULL")
88
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timezone, "null")
99
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, calendar, "null")
1010
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null")
1111
ZEND_END_ARG_INFO()
1212

13-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlDateFormatter_create, 0, 0, 3)
13+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlDateFormatter_create, 0, 0, 1)
1414
ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 1)
15-
ZEND_ARG_TYPE_INFO(0, dateType, IS_LONG, 0)
16-
ZEND_ARG_TYPE_INFO(0, timeType, IS_LONG, 0)
15+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, dateType, IS_LONG, 0, "IntlDateFormatter::FULL")
16+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeType, IS_LONG, 0, "IntlDateFormatter::FULL")
1717
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timezone, "null")
1818
ZEND_ARG_OBJ_TYPE_MASK(0, calendar, IntlCalendar, MAY_BE_LONG|MAY_BE_NULL, "null")
1919
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null")

ext/intl/dateformat/dateformat_create.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
5151
char *locale_str;
5252
size_t locale_len = 0;
5353
Locale locale;
54-
zend_long date_type = 0;
55-
zend_long time_type = 0;
54+
zend_long date_type = UDAT_FULL;
55+
zend_long time_type = UDAT_FULL;
5656
zend_object *calendar_obj = NULL;
5757
zend_long calendar_long = 0;
5858
bool calendar_is_null = 1;
@@ -71,11 +71,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
7171
intl_error_reset(NULL);
7272
object = return_value;
7373

74-
ZEND_PARSE_PARAMETERS_START(3, 6)
74+
ZEND_PARSE_PARAMETERS_START(1, 6)
7575
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
76+
Z_PARAM_OPTIONAL
7677
Z_PARAM_LONG(date_type)
7778
Z_PARAM_LONG(time_type)
78-
Z_PARAM_OPTIONAL
7979
Z_PARAM_ZVAL(timezone_zv)
8080
Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(calendar_obj, Calendar_ce_ptr, calendar_long, calendar_is_null)
8181
Z_PARAM_STRING_OR_NULL(pattern_str, pattern_str_len)

ext/intl/php_intl.stub.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ function intl_error_name(int $errorCode): string {}
158158
/* dateformat */
159159

160160
/** @param IntlTimeZone|DateTimeZone|string|null $timezone */
161-
function datefmt_create(?string $locale, int $dateType, int $timeType, $timezone = null, IntlCalendar|int|null $calendar = null, ?string $pattern = null): ?IntlDateFormatter {}
161+
function datefmt_create(
162+
?string $locale,
163+
int $dateType = IntlDateFormatter::FULL,
164+
int $timeType = IntlDateFormatter::FULL,
165+
$timezone = null,
166+
IntlCalendar|int|null $calendar = null,
167+
?string $pattern = null
168+
): ?IntlDateFormatter {}
162169

163170
function datefmt_get_datetype(IntlDateFormatter $formatter): int|false {}
164171

ext/intl/php_intl_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 9d6b4d36a39e4bb346ea0d45d4be8c941070bd67 */
2+
* Stub hash: 0d3e65fea1fbb8f38c3268b4048cb91972a94a1b */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_intlcal_create_instance, 0, 0, IntlCalendar, 1)
55
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timezone, "null")
@@ -276,10 +276,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intl_error_name, 0, 1, IS_STRING
276276
ZEND_ARG_TYPE_INFO(0, errorCode, IS_LONG, 0)
277277
ZEND_END_ARG_INFO()
278278

279-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_datefmt_create, 0, 3, IntlDateFormatter, 1)
279+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_datefmt_create, 0, 1, IntlDateFormatter, 1)
280280
ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 1)
281-
ZEND_ARG_TYPE_INFO(0, dateType, IS_LONG, 0)
282-
ZEND_ARG_TYPE_INFO(0, timeType, IS_LONG, 0)
281+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, dateType, IS_LONG, 0, "IntlDateFormatter::FULL")
282+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeType, IS_LONG, 0, "IntlDateFormatter::FULL")
283283
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timezone, "null")
284284
ZEND_ARG_OBJ_TYPE_MASK(0, calendar, IntlCalendar, MAY_BE_LONG|MAY_BE_NULL, "null")
285285
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pattern, IS_STRING, 1, "null")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
IntlDateFormatter::create() with default date and time types
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$ts = strtotime('2012-01-01 00:00:00 UTC');
9+
$fmt = IntlDateFormatter::create('en_US');
10+
echo $fmt->format($ts), "\n";
11+
12+
$fmt = new IntlDateFormatter('en_US');
13+
echo $fmt->format($ts), "\n";
14+
15+
$fmt = datefmt_create('en_US');
16+
echo $fmt->format($ts), "\n";
17+
18+
?>
19+
--EXPECT--
20+
Sunday, January 1, 2012 at 12:00:00 AM Coordinated Universal Time
21+
Sunday, January 1, 2012 at 12:00:00 AM Coordinated Universal Time
22+
Sunday, January 1, 2012 at 12:00:00 AM Coordinated Universal Time

0 commit comments

Comments
 (0)