@@ -2297,7 +2297,7 @@ static zend_object_value date_object_clone_timezone(zval *this_ptr TSRMLS_DC)
2297
2297
case TIMELIB_ZONETYPE_ABBR :
2298
2298
new_obj -> tzi .z .utc_offset = old_obj -> tzi .z .utc_offset ;
2299
2299
new_obj -> tzi .z .dst = old_obj -> tzi .z .dst ;
2300
- new_obj -> tzi .z .abbr = old_obj -> tzi .z .abbr ;
2300
+ new_obj -> tzi .z .abbr = strdup ( old_obj -> tzi .z .abbr ) ;
2301
2301
break ;
2302
2302
}
2303
2303
@@ -3238,6 +3238,26 @@ PHP_METHOD(DateTimeImmutable, sub)
3238
3238
}
3239
3239
/* }}} */
3240
3240
3241
+ static void set_timezone_from_timelib_time (php_timezone_obj * tzobj , timelib_time * t )
3242
+ {
3243
+ tzobj -> initialized = 1 ;
3244
+ tzobj -> type = t -> zone_type ;
3245
+ switch (t -> zone_type ) {
3246
+ case TIMELIB_ZONETYPE_ID :
3247
+ tzobj -> tzi .tz = t -> tz_info ;
3248
+ break ;
3249
+ case TIMELIB_ZONETYPE_OFFSET :
3250
+ tzobj -> tzi .utc_offset = t -> z ;
3251
+ break ;
3252
+ case TIMELIB_ZONETYPE_ABBR :
3253
+ tzobj -> tzi .z .utc_offset = t -> z ;
3254
+ tzobj -> tzi .z .dst = t -> dst ;
3255
+ tzobj -> tzi .z .abbr = strdup (t -> tz_abbr );
3256
+ break ;
3257
+ }
3258
+ }
3259
+
3260
+
3241
3261
/* {{{ proto DateTimeZone date_timezone_get(DateTimeInterface object)
3242
3262
Return new DateTimeZone object relative to give DateTime
3243
3263
*/
@@ -3255,21 +3275,7 @@ PHP_FUNCTION(date_timezone_get)
3255
3275
if (dateobj -> time -> is_localtime /* && dateobj->time->tz_info*/ ) {
3256
3276
php_date_instantiate (date_ce_timezone , return_value TSRMLS_CC );
3257
3277
tzobj = (php_timezone_obj * ) zend_object_store_get_object (return_value TSRMLS_CC );
3258
- tzobj -> initialized = 1 ;
3259
- tzobj -> type = dateobj -> time -> zone_type ;
3260
- switch (dateobj -> time -> zone_type ) {
3261
- case TIMELIB_ZONETYPE_ID :
3262
- tzobj -> tzi .tz = dateobj -> time -> tz_info ;
3263
- break ;
3264
- case TIMELIB_ZONETYPE_OFFSET :
3265
- tzobj -> tzi .utc_offset = dateobj -> time -> z ;
3266
- break ;
3267
- case TIMELIB_ZONETYPE_ABBR :
3268
- tzobj -> tzi .z .utc_offset = dateobj -> time -> z ;
3269
- tzobj -> tzi .z .dst = dateobj -> time -> dst ;
3270
- tzobj -> tzi .z .abbr = strdup (dateobj -> time -> tz_abbr );
3271
- break ;
3272
- }
3278
+ set_timezone_from_timelib_time (tzobj , dateobj -> time );
3273
3279
} else {
3274
3280
RETURN_FALSE ;
3275
3281
}
@@ -3620,23 +3626,21 @@ PHP_FUNCTION(date_diff)
3620
3626
}
3621
3627
/* }}} */
3622
3628
3623
- static int timezone_initialize (timelib_tzinfo * * tzi , /*const*/ char * tz TSRMLS_DC )
3629
+ static int timezone_initialize (php_timezone_obj * tzobj , /*const*/ char * tz TSRMLS_DC )
3624
3630
{
3625
- char * tzid ;
3626
-
3627
- * tzi = NULL ;
3628
-
3629
- if ((tzid = timelib_timezone_id_from_abbr (tz , -1 , 0 ))) {
3630
- * tzi = php_date_parse_tzfile (tzid , DATE_TIMEZONEDB TSRMLS_CC );
3631
+ timelib_time * dummy_t = ecalloc (1 , sizeof (timelib_time ));
3632
+ int dst , not_found ;
3633
+ char * orig_tz = tz ;
3634
+
3635
+ dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
3636
+ if (not_found ) {
3637
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unknown or bad timezone (%s)" , orig_tz );
3638
+ efree (dummy_t );
3639
+ return FAILURE ;
3631
3640
} else {
3632
- * tzi = php_date_parse_tzfile (tz , DATE_TIMEZONEDB TSRMLS_CC );
3633
- }
3634
-
3635
- if (* tzi ) {
3641
+ set_timezone_from_timelib_time (tzobj , dummy_t TSRMLS_CC );
3642
+ efree (dummy_t );
3636
3643
return SUCCESS ;
3637
- } else {
3638
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unknown or bad timezone (%s)" , tz );
3639
- return FAILURE ;
3640
3644
}
3641
3645
}
3642
3646
@@ -3647,19 +3651,15 @@ PHP_FUNCTION(timezone_open)
3647
3651
{
3648
3652
char * tz ;
3649
3653
int tz_len ;
3650
- timelib_tzinfo * tzi = NULL ;
3651
3654
php_timezone_obj * tzobj ;
3652
3655
3653
3656
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & tz , & tz_len ) == FAILURE ) {
3654
3657
RETURN_FALSE ;
3655
3658
}
3656
- if (SUCCESS != timezone_initialize (& tzi , tz TSRMLS_CC )) {
3659
+ tzobj = zend_object_store_get_object (php_date_instantiate (date_ce_timezone , return_value TSRMLS_CC ) TSRMLS_CC );
3660
+ if (SUCCESS != timezone_initialize (tzobj , tz TSRMLS_CC )) {
3657
3661
RETURN_FALSE ;
3658
3662
}
3659
- tzobj = zend_object_store_get_object (php_date_instantiate (date_ce_timezone , return_value TSRMLS_CC ) TSRMLS_CC );
3660
- tzobj -> type = TIMELIB_ZONETYPE_ID ;
3661
- tzobj -> tzi .tz = tzi ;
3662
- tzobj -> initialized = 1 ;
3663
3663
}
3664
3664
/* }}} */
3665
3665
@@ -3670,18 +3670,13 @@ PHP_METHOD(DateTimeZone, __construct)
3670
3670
{
3671
3671
char * tz ;
3672
3672
int tz_len ;
3673
- timelib_tzinfo * tzi = NULL ;
3674
3673
php_timezone_obj * tzobj ;
3675
3674
zend_error_handling error_handling ;
3676
3675
3677
3676
zend_replace_error_handling (EH_THROW , NULL , & error_handling TSRMLS_CC );
3678
3677
if (SUCCESS == zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & tz , & tz_len )) {
3679
- if (SUCCESS == timezone_initialize (& tzi , tz TSRMLS_CC )) {
3680
- tzobj = zend_object_store_get_object (getThis () TSRMLS_CC );
3681
- tzobj -> type = TIMELIB_ZONETYPE_ID ;
3682
- tzobj -> tzi .tz = tzi ;
3683
- tzobj -> initialized = 1 ;
3684
- } else {
3678
+ tzobj = zend_object_store_get_object (getThis () TSRMLS_CC );
3679
+ if (FAILURE == timezone_initialize (tzobj , tz TSRMLS_CC )) {
3685
3680
ZVAL_NULL (getThis ());
3686
3681
}
3687
3682
}
@@ -3693,39 +3688,12 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
3693
3688
{
3694
3689
zval * * z_timezone = NULL ;
3695
3690
zval * * z_timezone_type = NULL ;
3696
- timelib_tzinfo * tzi ;
3697
3691
3698
3692
if (zend_hash_find (myht , "timezone_type" , 14 , (void * * ) & z_timezone_type ) == SUCCESS ) {
3699
3693
if (zend_hash_find (myht , "timezone" , 9 , (void * * ) & z_timezone ) == SUCCESS ) {
3700
3694
convert_to_long (* z_timezone_type );
3701
- switch (Z_LVAL_PP (z_timezone_type )) {
3702
- case TIMELIB_ZONETYPE_OFFSET : {
3703
- char * offset , * offset_start ;
3704
-
3705
- offset = emalloc (sizeof (char ) * (Z_STRLEN_PP (z_timezone ) + 1 ));
3706
- memmove (offset , Z_STRVAL_PP (z_timezone ), Z_STRLEN_PP (z_timezone )+ 1 );
3707
- offset_start = offset ;
3708
-
3709
- ++ offset ;
3710
- if (* offset_start == '+' ){
3711
- (* tzobj )-> tzi .utc_offset = -1 * timelib_parse_tz_cor (& offset );
3712
- } else {
3713
- (* tzobj )-> tzi .utc_offset = timelib_parse_tz_cor (& offset );
3714
- }
3715
- efree (offset_start );
3716
- (* tzobj )-> type = TIMELIB_ZONETYPE_OFFSET ;
3717
- (* tzobj )-> initialized = 1 ;
3718
- return SUCCESS ;
3719
- break ;
3720
- }
3721
- case TIMELIB_ZONETYPE_ABBR :
3722
- case TIMELIB_ZONETYPE_ID :
3723
- if (SUCCESS == timezone_initialize (& tzi , Z_STRVAL_PP (z_timezone ) TSRMLS_CC )) {
3724
- (* tzobj )-> type = TIMELIB_ZONETYPE_ID ;
3725
- (* tzobj )-> tzi .tz = tzi ;
3726
- (* tzobj )-> initialized = 1 ;
3727
- return SUCCESS ;
3728
- }
3695
+ if (SUCCESS == timezone_initialize (* tzobj , Z_STRVAL_PP (z_timezone ) TSRMLS_CC )) {
3696
+ return SUCCESS ;
3729
3697
}
3730
3698
}
3731
3699
}
0 commit comments