Changes between Initial Version and Version 2 of Ticket #57998
- Timestamp:
- 03/28/2023 09:17:25 AM (6 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #57998
-
Property
Summary
changed from
Issue in current_time function
tocurrent_time function: GMT offset is not always an integer
-
Property
Summary
changed from
-
Ticket #57998 – Description
initial v2 1 1 Hello, 2 2 3 4 5 We found a bug in the WordPress 6.2 RC with the function 'current_time' located in 'wp-includes\functions.php'. Before 6.2 RC, the line under this function was like as below. 6 7 3 We found a bug in the WordPress 6.2 RC with the function `current_time` located in `wp-includes\functions.php`. Before 6.2 RC, the line under this function was like as below. 8 4 9 5 {{{#!php 10 6 <?php 11 7 return $gmt ? time() : time() + (int)( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 12 8 ?> 13 9 }}} 14 10 15 16 17 11 While in WordPress 6.2 RC, it gets changes and integer typecasting moved inside the brackets. 18 19 20 12 21 13 {{{#!php 22 14 <?php 23 15 return $gmt ? time() : time() + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 24 16 ?> 25 17 }}} 26 27 28 18 29 19 This creates time difference when the site timezone is like '+11:30', '+05:30', etc. When we call the function with timestamp parameter … … 32 22 }}} 33 23 34 24 in WordPress 6.1.1 or lower, it returns me the `gmt_offset` 11.5 ( for +11:30 ), 5.5 ( for +05:30 ) and calculate properly without making any difference. 35 25 36 in WordPress 6.1.1 or lower, it returns me the gmt_offset 11.5 ( for +11:30 ), 5.5 ( for +05:30 ) and calculate properly without making any difference. 26 While from WordPress 6.2, first it'll convert the `gmt_offset` to integer and that considers 30 minutes less than original. Before WordPress 6.2, the `gmt_offset` first converted into seconds and then it typecasted to integer but with 6.2 first it typecasting `gmt_offset` to integer and then converting to seconds so it makes the 30 minutes difference on above examples. 37 27 38 39 40 While from WordPress 6.2, first it'll convert the gmt_offset to integer and that considers 30 minutes less then original. Before WordPress 6.2, the gmt_offset first converted into seconds and then it typecasted to integer but with 6.2 first it typecasting gmt_offset to integer and then converting to seconds so it makes the 30 minutes difference on above examples. 41 42 43 44 We would suggest that if it's needed to type cast only gmt_offset (inside the bracket as per WordPress 6.2) then either use 'float' or 'double' so that the above timezone makes no difference and calculate proper timestamp. 45 46 28 We would suggest that if it's needed to type cast only `gmt_offset` (inside the bracket as per WordPress 6.2) then either use `float` or `double` so that the above timezone makes no difference and calculate proper timestamp. 47 29 48 30 Suggested change: 49 31 50 51 52 32 {{{#!php 53 33 <?php 54 return $gmt ? time() : time() + ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); ?> 34 return $gmt ? time() : time() + ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 55 35 ?> 56 36 }}} 57 37 58 59 60 38 Thanks