[wp-trac] [WordPress Trac] #61732: get_calendar() will use invalid dates in SQL queries

WordPress Trac noreply at wordpress.org
Mon Dec 2 13:33:06 UTC 2024


#61732: get_calendar() will use invalid dates in SQL queries
--------------------------------------+-----------------------
 Reporter:  leedxw                    |       Owner:  pbearne
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  6.8
Component:  Date/Time                 |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------

Comment (by ngoncalves):

 The current patch doesn't fix the issues with get_calendar when using
 timezones ahead of UTC that I wrote about above.

 As I'm not familiar with the WordPress codebase, I'm unsure of how to fix
 it in a way that would be merged so I'll try to showcase the issues using
 tests: Here are 2 tests which fails when you set the timezone to anything
 ahead of UTC (like UTC+1), but passes if you remove the
 date_default_timezone_set statements.

 {{{#!php
 <?php
         /*
          * Test that the get_calendar function return HTML that represents
 the last day of October, day 31
          * in positive non UTC timezone (i.e: UTC+1)
         */
         public function
 testGet_calendar_returns_post_day_31_in_october_in_non_UTC_timezone() {
                 $day_31_in_calendar_html = '<td><a
 href="http://example.org/?m=20241031" aria-label="Posts published on
 October 31, 2024">31</a>';
                 $post_id  = self::factory()->post->create( array(
 'post_date' => '2024-10-31 10:00:00' ) );
                 global $year, $monthnum;
                 $year = 2024;
                 $monthnum = 10;

                 date_default_timezone_set('Europe/Paris');
                 $output = get_calendar( true, false);
                 $this->assertStringContainsString(
 $day_31_in_calendar_html, $output );
         }
        /*
          * Test that get_calendar function doesn't trigger wpdb errors in
 positive non UTC timezone (i.e: UTC+1)
          *
          */
         public function
 testGet_calendar_no_database_errors_in_non_UTC_timezone() {
                 $post_id  = self::factory()->post->create( array(
 'post_date' => '2024-11-15 10:00:00' ) );
                 global $year, $monthnum, $wpdb;
                 $year = 2024;
                 $monthnum = 11;

                 date_default_timezone_set('Europe/Paris');

                 $output = get_calendar( true, false);
                 $this->assertSame('', $wpdb->last_error);
                 date_default_timezone_set('UTC');
         }
 }}}

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


More information about the wp-trac mailing list