Skip to content

Commit 5668114

Browse files
committed
Fix timezone errors
1 parent b20a65d commit 5668114

6 files changed

+28
-19
lines changed

ext/intl/tests/bug62017.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ try {
2121
?>
2222
--EXPECTF--
2323

24-
Exception: datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d
24+
Exception: datefmt_create(): Time zone identifier given is not a valid UTF-8 string in %s on line %d
2525

2626
Exception: IntlDateFormatter::__construct(): error converting pattern to UTF-16 in %s on line %d

ext/intl/tests/calendar_createInstance_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ try {
1717
}
1818
?>
1919
--EXPECT--
20-
intlcal_create_instance: passed IntlTimeZone is not properly constructed
20+
intlcal_create_instance(): passed IntlTimeZone is not properly constructed

ext/intl/tests/dateformat___construct_bad_tz_cal.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ try {
2929
}
3030
?>
3131
--EXPECT--
32-
Exception: datefmt_create: No such time zone: 'bad timezone'
32+
Exception: IntlDateFormatter::__construct(): No such time zone: "bad timezone"
3333
Exception: IntlDateFormatter::__construct(): Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object
34-
Exception: IntlDateFormatter::__construct(): Argument #5 ($calendar) must be of type IntlCalendar|int|null, stdClass given
34+
Exception: IntlDateFormatter::__construct(): Argument #5 ($calendar) must be of type IntlCalendar|int|null, stdClass given

ext/intl/tests/dateformat_setTimeZone_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ try {
2424
?>
2525
--EXPECTF--
2626
Warning: Array to string conversion in %s on line %d
27-
datefmt_set_timezone: No such time zone: 'Array'
28-
datefmt_set_timezone: No such time zone: 'non existing timezone'
27+
IntlDateFormatter::setTimeZone(): No such time zone: "Array"
28+
IntlDateFormatter::setTimeZone(): No such time zone: "non existing timezone"

ext/intl/tests/transliterator_transliterate_variant1.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ Warning: transliterator_transliterate(): String conversion of id to UTF-16 faile
2828

2929
Warning: transliterator_transliterate(): Could not create transliterator with ID %s
3030

31-
String conversion of id to UTF-16 failed: U_INVALID_CHAR_FOUND
31+
transliterator_transliterate(): String conversion of id to UTF-16 failed: U_INVALID_CHAR_FOUND
3232

3333
Warning: transliterator_transliterate(): unable to open ICU transliterator with id "inexistent id" in %s on line %d
3434

35-
Warning: transliterator_transliterate(): Could not create transliterator with ID "inexistent id" (transliterator_create(): unable to open ICU transliterator with id "inexistent id": U_INVALID_ID) in %s on line %d
35+
Warning: transliterator_transliterate(): Could not create transliterator with ID "inexistent id" (transliterator_transliterate(): unable to open ICU transliterator with id "inexistent id": U_INVALID_ID) in %s on line %d
3636

37-
transliterator_create(): unable to open ICU transliterator with id "inexistent id": U_INVALID_ID
37+
transliterator_transliterate(): unable to open ICU transliterator with id "inexistent id": U_INVALID_ID
3838
Done.

ext/intl/timezone/timezone_class.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
117117
}
118118
/* }}} */
119119

120+
static void timezone_throw_exception_with_call_location(const char *msg, const char *add_info)
121+
{
122+
zend_string *fn = get_active_function_or_method_name();
123+
zend_throw_error(IntlException_ce_ptr, "%s(): %s%s%s%s",
124+
ZSTR_VAL(fn), msg,
125+
add_info ? "\"" : "",
126+
add_info ? add_info : "",
127+
add_info ? "\"" : ""
128+
);
129+
zend_string_release_ex(fn, false);
130+
}
131+
120132
/* {{{ timezone_process_timezone_argument
121133
* TimeZone argument processor. outside_error may be NULL (for static functions/constructors) */
122134
U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
@@ -138,14 +150,14 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
138150
TimeZone_object *to = Z_INTL_TIMEZONE_P(zv_timezone);
139151

140152
if (to->utimezone == NULL) {
141-
zend_throw_error(IntlException_ce_ptr, "passed IntlTimeZone is not "
142-
"properly constructed");
153+
timezone_throw_exception_with_call_location("passed IntlTimeZone is not "
154+
"properly constructed", NULL);
143155
zval_ptr_dtor_str(&local_zv_tz);
144156
return NULL;
145157
}
146158
timeZone = to->utimezone->clone();
147159
if (UNEXPECTED(timeZone == NULL)) {
148-
zend_throw_error(IntlException_ce_ptr, "could not clone TimeZone");
160+
timezone_throw_exception_with_call_location("could not clone TimeZone", NULL);
149161
zval_ptr_dtor_str(&local_zv_tz);
150162
return NULL;
151163
}
@@ -165,22 +177,19 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
165177
}
166178
if (intl_stringFromChar(id, Z_STRVAL_P(zv_timezone), Z_STRLEN_P(zv_timezone),
167179
&status) == FAILURE) {
168-
// TODO: Grab current executing function/method
169-
zend_throw_error(IntlException_ce_ptr, "Time zone identifier given is not a "
170-
"valid UTF-8 string");
180+
timezone_throw_exception_with_call_location("Time zone identifier given is not a "
181+
"valid UTF-8 string", NULL);
171182
zval_ptr_dtor_str(&local_zv_tz);
172183
return NULL;
173184
}
174185
timeZone = TimeZone::createTimeZone(id);
175186
if (UNEXPECTED(timeZone == NULL)) {
176-
// TODO: Grab current executing function/method
177-
zend_throw_error(IntlException_ce_ptr, "Could not create time zone");
187+
timezone_throw_exception_with_call_location("Could not create time zone", NULL);
178188
zval_ptr_dtor_str(&local_zv_tz);
179189
return NULL;
180190
}
181191
if (*timeZone == TimeZone::getUnknown()) {
182-
// TODO: Grab current executing function/method
183-
zend_throw_error(IntlException_ce_ptr, "No such time zone: '%s'", Z_STRVAL_P(zv_timezone));
192+
timezone_throw_exception_with_call_location("No such time zone: ", Z_STRVAL_P(zv_timezone));
184193
zval_ptr_dtor_str(&local_zv_tz);
185194
delete timeZone;
186195
return NULL;

0 commit comments

Comments
 (0)