[wp-trac] [WordPress Trac] #57998: Issue in current_time function

WordPress Trac noreply at wordpress.org
Tue Mar 28 08:55:26 UTC 2023


#57998: Issue in current_time function
-------------------------------+-----------------------------
 Reporter:  reputeinfosystems  |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Date/Time          |    Version:  trunk
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 Hello,



 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.



 {{{#!php
 <?php
     return $gmt ? time() : time() + (int)( get_option( 'gmt_offset' ) *
 HOUR_IN_SECONDS );
 ?>
 }}}



 While in WordPress 6.2 RC, it gets changes and integer typecasting moved
 inside the brackets.



 {{{#!php
 <?php
    return $gmt ? time() : time() + ( (int) get_option( 'gmt_offset' ) *
 HOUR_IN_SECONDS );
 ?>
 }}}



 This creates time difference when the site timezone is like '+11:30',
 '+05:30', etc. When we call the function with timestamp parameter
 {{{#!php
 <?php current_time('timestamp'); ?>
 }}}



 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.



 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.



 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.



 Suggested change:



 {{{#!php
 <?php
     return $gmt ? time() : time() + ( (float) get_option( 'gmt_offset' ) *
 HOUR_IN_SECONDS ); ?>
 ?>
 }}}



 Thanks

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57998>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list