Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #57998


Ignore:
Timestamp:
03/28/2023 09:17:25 AM (13 months ago)
Author:
sabernhardt
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #57998

    • Property Summary changed from Issue in current_time function to current_time function: GMT offset is not always an integer
  • Ticket #57998 – Description

    initial v2  
    11Hello,
    22
    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  
     3We 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.
    84
    95{{{#!php
    106<?php
    11     return $gmt ? time() : time() + (int)( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
     7    return $gmt ? time() : time() + (int)( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    128?>
    139}}}
    1410
    15  
    16 
    1711While in WordPress 6.2 RC, it gets changes and integer typecasting moved inside the brackets.
    18 
    19  
    2012
    2113{{{#!php
    2214<?php
    23    return $gmt ? time() : time() + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
     15    return $gmt ? time() : time() + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    2416?>
    2517}}}
    26 
    27  
    2818
    2919This creates time difference when the site timezone is like '+11:30', '+05:30', etc. When we call the function with timestamp parameter
     
    3222}}}
    3323
    34  
     24in 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. 
    3525
    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. 
     26While 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.
    3727
    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  
     28We 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.
    4729
    4830Suggested change:
    4931
    50  
    51 
    5232{{{#!php
    5333<?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 );
    5535?>
    5636}}}
    5737
    58  
    59 
    6038Thanks