Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-17624

Datetime edge case tests fail when local timezone is ahead of UTC

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 4.0.0-a2
    • 4.0.0-a2
    • Test Suite
    • PHP 8.3.30, SQLite, macOS 15.7.4, local timezone UTC+1 (CET)

      there are 3 edge case tests in phpbb_datetime_from_format_test::test_relative_format_date (data sets #8, #9, #10) that fail consistently when PHPUnit is run on a machine whose local timezone is ahead of UTC (e.g., CET,  CEST, AEST).

      The edge cases added at the end of relative_format_date_data() use strtotime('yesterday'), strtotime('today'), and strtotime('tomorrow') to compute the test dates. These functions return timestamps based on the local timezone.

      The result is then formatted with gmdate('Y-m-d', ...), which formats in UTC.  When the local timezone is ahead of UTC, the UTC date is one day behind the local date, shifting all three test expectations by one day.

      For example, on a machine in UTC+2 at 01:00 local time:

      • strtotime('today') returns midnight local = 22:00 UTC the previous day
      • gmdate('Y-m-d', strtotime('today')) therefore returns yesterday's date in UTC 

      The test expects "Today 00:00" but format_date() correctly identifies the timestamp as yesterday. 

      -----------------

      file path : tests/datetime/from_format_test.php, lines 122-134.                                                                                                      
      test output — makes it immediately reproducible. Something like:
                                                                                                                                                                                                                             
        Failing output:                                                                                                                                                                                                    

      1) phpbb_datetime_from_format_test::test_relative_format_date with data set #8 ('2026-03-21 00:00', false, 'Yesterday 00:00')
      Failed asserting that two strings are equal.
      — Expected
      +++ Actual
      @@ @@
      -'Yesterday 00:00'
      +'2026-03-21 00:00'

      /Users/Andreas/Sites/phpbb/tests/datetime/from_format_test.php:162

      2) phpbb_datetime_from_format_test::test_relative_format_date with data set #9 ('2026-03-22 00:00', false, 'Today 00:00')
      Failed asserting that two strings are equal.
      — Expected
      +++ Actual
      @@ @@
      -'Today 00:00'
      +'Yesterday 00:00'

      /Users/Andreas/Sites/phpbb/tests/datetime/from_format_test.php:162

      3) phpbb_datetime_from_format_test::test_relative_format_date with data set #10 ('2026-03-23 00:00', false, 'Tomorrow 00:00')
      Failed asserting that two strings are equal.
      — Expected
      +++ Actual
      @@ @@
      -'Tomorrow 00:00'
      +'Today 00:00'

      /Users/Andreas/Sites/phpbb/tests/datetime/from_format_test.php:162

                                                                                                                                                                                                                          
              

       

       

            Marc Marc
            Sajaki Sajaki
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: