@@ -707,7 +707,7 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t
707
707
708
708
/* timezone */
709
709
case 'I' : length = slprintf (buffer , sizeof (buffer ), "%d" , localtime ? offset -> is_dst : 0 ); break ;
710
- case 'p' :
710
+ case 'p' :
711
711
if (!localtime || strcmp (offset -> abbr , "UTC" ) == 0 || strcmp (offset -> abbr , "Z" ) == 0 ) {
712
712
length = slprintf (buffer , sizeof (buffer ), "%s" , "Z" );
713
713
break ;
@@ -2179,7 +2179,7 @@ static void php_date_get_current_time_with_fraction(time_t *sec, suseconds_t *us
2179
2179
#endif
2180
2180
}
2181
2181
2182
- PHPAPI int php_date_initialize (php_date_obj * dateobj , const char * time_str , size_t time_str_len , const char * format , zval * timezone_object , int ctor ) /* {{{ */
2182
+ PHPAPI int php_date_initialize (php_date_obj * dateobj , const char * time_str , size_t time_str_len , const char * format , zval * timezone_object , int flags ) /* {{{ */
2183
2183
{
2184
2184
timelib_time * now ;
2185
2185
timelib_tzinfo * tzi = NULL ;
@@ -2189,6 +2189,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
2189
2189
timelib_sll new_offset = 0 ;
2190
2190
time_t sec ;
2191
2191
suseconds_t usec ;
2192
+ int options = 0 ;
2192
2193
2193
2194
if (dateobj -> time ) {
2194
2195
timelib_time_dtor (dateobj -> time );
@@ -2210,7 +2211,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
2210
2211
update_errors_warnings (err );
2211
2212
2212
2213
2213
- if (ctor && err && err -> error_count ) {
2214
+ if (( flags & PHP_DATE_INIT_CTOR ) && err && err -> error_count ) {
2214
2215
/* spit out the first library error message, at least */
2215
2216
php_error_docref (NULL , E_WARNING , "Failed to parse time string (%s) at position %d (%c): %s" , time_str ,
2216
2217
err -> error_messages [0 ].position , err -> error_messages [0 ].character , err -> error_messages [0 ].message );
@@ -2263,7 +2264,13 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
2263
2264
php_date_get_current_time_with_fraction (& sec , & usec );
2264
2265
timelib_unixtime2local (now , (timelib_sll ) sec );
2265
2266
php_date_set_time_fraction (now , usec );
2266
- timelib_fill_holes (dateobj -> time , now , TIMELIB_NO_CLONE );
2267
+
2268
+ options = TIMELIB_NO_CLONE ;
2269
+ if (flags & PHP_DATE_INIT_FORMAT ) {
2270
+ options |= TIMELIB_OVERRIDE_TIME ;
2271
+ }
2272
+ timelib_fill_holes (dateobj -> time , now , options );
2273
+
2267
2274
timelib_update_ts (dateobj -> time , tzi );
2268
2275
timelib_update_from_sse (dateobj -> time );
2269
2276
@@ -2331,7 +2338,7 @@ PHP_FUNCTION(date_create_from_format)
2331
2338
ZEND_PARSE_PARAMETERS_END ();
2332
2339
2333
2340
php_date_instantiate (execute_data -> This .value .ce ? execute_data -> This .value .ce : date_ce_date , return_value );
2334
- if (!php_date_initialize (Z_PHPDATE_P (return_value ), time_str , time_str_len , format_str , timezone_object , 0 )) {
2341
+ if (!php_date_initialize (Z_PHPDATE_P (return_value ), time_str , time_str_len , format_str , timezone_object , PHP_DATE_INIT_FORMAT )) {
2335
2342
zval_ptr_dtor (return_value );
2336
2343
RETURN_FALSE ;
2337
2344
}
@@ -2353,7 +2360,7 @@ PHP_FUNCTION(date_create_immutable_from_format)
2353
2360
ZEND_PARSE_PARAMETERS_END ();
2354
2361
2355
2362
php_date_instantiate (execute_data -> This .value .ce ? execute_data -> This .value .ce : date_ce_immutable , return_value );
2356
- if (!php_date_initialize (Z_PHPDATE_P (return_value ), time_str , time_str_len , format_str , timezone_object , 0 )) {
2363
+ if (!php_date_initialize (Z_PHPDATE_P (return_value ), time_str , time_str_len , format_str , timezone_object , PHP_DATE_INIT_FORMAT )) {
2357
2364
zval_ptr_dtor (return_value );
2358
2365
RETURN_FALSE ;
2359
2366
}
@@ -2375,7 +2382,7 @@ PHP_METHOD(DateTime, __construct)
2375
2382
ZEND_PARSE_PARAMETERS_END ();
2376
2383
2377
2384
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
2378
- php_date_initialize (Z_PHPDATE_P (ZEND_THIS ), time_str , time_str_len , NULL , timezone_object , 1 );
2385
+ php_date_initialize (Z_PHPDATE_P (ZEND_THIS ), time_str , time_str_len , NULL , timezone_object , PHP_DATE_INIT_CTOR );
2379
2386
zend_restore_error_handling (& error_handling );
2380
2387
}
2381
2388
/* }}} */
@@ -2395,7 +2402,7 @@ PHP_METHOD(DateTimeImmutable, __construct)
2395
2402
ZEND_PARSE_PARAMETERS_END ();
2396
2403
2397
2404
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
2398
- php_date_initialize (Z_PHPDATE_P (ZEND_THIS ), time_str , time_str_len , NULL , timezone_object , 1 );
2405
+ php_date_initialize (Z_PHPDATE_P (ZEND_THIS ), time_str , time_str_len , NULL , timezone_object , PHP_DATE_INIT_CTOR );
2399
2406
zend_restore_error_handling (& error_handling );
2400
2407
}
2401
2408
/* }}} */
0 commit comments