Skip to content

Commit f5d9e00

Browse files
committed
alternative from feedback for comparison.
1 parent 4fbe0d5 commit f5d9e00

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

ext/intl/dateformat/dateformat.stub.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,16 @@ public static function formatObject($datetime, $format = null, ?string $locale =
154154

155155
/**
156156
* @param int $offset
157-
* @param bool $updateCalendar
158157
* @tentative-return-type
159158
* @alias datefmt_parse
160159
*/
161-
public function parse(string $string, &$offset = null, bool $updateCalendar = false): int|float|false {}
160+
public function parse(string $string, &$offset = null): int|float|false {}
161+
162+
/**
163+
* @param int $offset
164+
* @tentative-return-type
165+
*/
166+
public function parseToCalendar(string $string, &$offset = null): int|float|false {}
162167

163168
/**
164169
* @param int $offset

ext/intl/dateformat/dateformat_arginfo.h

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/dateformat/dateformat_parse.c

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,13 @@ PHP_FUNCTION(datefmt_parse)
131131
char* text_to_parse = NULL;
132132
size_t text_len =0;
133133
zval* z_parse_pos = NULL;
134-
int32_t parse_pos = -1;
135-
bool update_calendar = false;
134+
int32_t parse_pos = -1;
136135

137136
DATE_FORMAT_METHOD_INIT_VARS;
138137

139138
/* Parse parameters. */
140-
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os|z!b",
141-
&object, IntlDateFormatter_ce_ptr, &text_to_parse, &text_len, &z_parse_pos, &update_calendar ) == FAILURE ){
139+
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os|z!",
140+
&object, IntlDateFormatter_ce_ptr, &text_to_parse, &text_len, &z_parse_pos ) == FAILURE ){
142141
RETURN_THROWS();
143142
}
144143

@@ -159,14 +158,53 @@ PHP_FUNCTION(datefmt_parse)
159158
RETURN_FALSE;
160159
}
161160
}
162-
internal_parse_to_timestamp( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, update_calendar, return_value);
161+
internal_parse_to_timestamp( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, false, return_value);
163162
if(z_parse_pos) {
164163
zval_ptr_dtor(z_parse_pos);
165164
ZVAL_LONG(z_parse_pos, parse_pos);
166165
}
167166
}
168167
/* }}} */
169168

169+
PHP_METHOD(IntlDateFormatter, parseToCalendar)
170+
{
171+
char* text_to_parse = NULL;
172+
size_t text_len =0;
173+
zval* z_parse_pos = NULL;
174+
int32_t parse_pos = -1;
175+
176+
DATE_FORMAT_METHOD_INIT_VARS;
177+
178+
/* Parse parameters. */
179+
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os|z!",
180+
&object, IntlDateFormatter_ce_ptr, &text_to_parse, &text_len, &z_parse_pos ) == FAILURE ){
181+
RETURN_THROWS();
182+
}
183+
184+
/* Fetch the object. */
185+
DATE_FORMAT_METHOD_FETCH_OBJECT;
186+
187+
if (z_parse_pos) {
188+
zend_long long_parse_pos;
189+
ZVAL_DEREF(z_parse_pos);
190+
long_parse_pos = zval_get_long(z_parse_pos);
191+
if (ZEND_LONG_INT_OVFL(long_parse_pos)) {
192+
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
193+
intl_error_set_custom_msg(NULL, "String index is out of valid range.", 0);
194+
RETURN_FALSE;
195+
}
196+
parse_pos = (int32_t)long_parse_pos;
197+
if((size_t)parse_pos > text_len) {
198+
RETURN_FALSE;
199+
}
200+
}
201+
internal_parse_to_timestamp( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, true, return_value);
202+
if(z_parse_pos) {
203+
zval_ptr_dtor(z_parse_pos);
204+
ZVAL_LONG(z_parse_pos, parse_pos);
205+
}
206+
}
207+
170208
/* {{{ Parse the string $value to a localtime array */
171209
PHP_FUNCTION(datefmt_localtime)
172210
{

ext/intl/php_intl.stub.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,8 @@ function datefmt_format(IntlDateFormatter $formatter, $datetime): string|false {
374374
*/
375375
function datefmt_format_object($datetime, $format = null, ?string $locale = null): string|false {}
376376

377-
/**
378-
* @param int $offset
379-
* @param bool $updateCalendar
380-
*/
381-
function datefmt_parse(IntlDateFormatter $formatter, string $string, &$offset = null, bool $updateCalendar = false): int|float|false {}
377+
/** @param int $offset */
378+
function datefmt_parse(IntlDateFormatter $formatter, string $string, &$offset = null): int|float|false {}
382379

383380
/**
384381
* @param int $offset

ext/intl/php_intl_arginfo.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/tests/gh13766.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $oIntlDateFormatter->setPattern('VV');
1010

1111
var_dump($oIntlDateFormatter->parse('America/Los_Angeles', $offset1));
1212
var_dump($oIntlDateFormatter->getTimeZone()->getID());
13-
var_dump($oIntlDateFormatter->parse('America/Los_Angeles', $offset2, true));
13+
var_dump($oIntlDateFormatter->parseToCalendar('America/Los_Angeles', $offset2));
1414
var_dump($oIntlDateFormatter->getTimeZone()->getID());
1515
--EXPECTF--
1616
int(%d)

0 commit comments

Comments
 (0)