[wp-trac] [WordPress Trac] #49038: wp_date

WordPress Trac noreply at wordpress.org
Thu Dec 19 13:39:05 UTC 2019


#49038: wp_date
--------------------------+------------------------------
 Reporter:  autotutorial  |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Date/Time     |     Version:
 Severity:  critical      |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by autotutorial):

 Replying to [comment:2 Rarst]:
 > Please provide an example of timestamp that produces unexpected output,
 what result you expect for it, and what is actual result.

 From the general settings set in Europe/Rome, it returns a date 2020-03-29
 00:00:00 because the offset sum is incorrect and in the case of daylight
 saving time it must be returned in UTC 2020-03-29 02:00:00.
 This means that in wp_date there is a bug and wordpress should only create
 dates (inputs) in UTC while the display (output) in any DateTimeZone
 except valid DST which can only be displayed in UTC.
 Only this is the correct way to use dates.
 I hope it helps, I commented on the troubleshooting code in options-
 general.php.
 On the way to creating the dates you need to think about, I am of the
 opinion that I only create UTC dates for all the date contexts and produce
 output with the exception I mentioned earlier.
 https://github.com/WordPress/WordPress/blob/5.3-branch/wp-admin/options-
 general.php#L283
 {{{#!php
 <?php
 $date_time_zone_selected = new DateTimeZone( $tzstring );
         //Bad 1 $tz_offset Bad 2 empty date create
                 $tz_offset               = timezone_offset_get(
 $date_time_zone_selected, date_create( 'now', new DateTimeZone( 'UTC'  ) )
 );
                 $right_now               = time();
                 foreach ( timezone_transitions_get(
 $date_time_zone_selected ) as $tr ) {
                         if ( $tr['ts'] > $right_now ) {
                 //UTC with offset Daylight saving time
                                 $found = true;
                                 break;
                         }
                 }

                 if ( $found ) {
                         echo ' ';
                         $message = $tr['isdst'] ?
                                 /* translators: %s: Date and time. */
                                 __( 'Daylight saving time begins on: %s.'
 ) :
                                 /* translators: %s: Date and time. */
                                 __( 'Standard time begins on: %s.' );
                         // Add the difference between the current offset
 and the new offset to ts to get the correct transition time from
 date_i18n().
             //Bad sum offset, $tr['ts'] is UTC, offest with Daylight
 saving time is $tr['offset']
             //Here bad 2020-03-29 00:00:00 timezone Europe/Rome, it
 convert wittout sum $tz_offset - $tr['offset'], only $tr['offset'] and
 convert UTC
             //UTC 2020-03-29 02:00:00
                         printf(
                                 $message,
                                 '<code>' . date_i18n(
                                         __( 'F j, Y' ) . ' ' . __( 'g:i a'
 ),
                                         $tr['ts']  + ( $tz_offset -
 $tr['offset'] )
                                 ) . '</code>'
                         );
                 } else {
                         _e( 'This timezone does not observe daylight
 saving time.' );
                 }
         }
         ?>
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49038#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list