[wp-trac] [WordPress Trac] #48384: get_post_time returns wrong value after timezone switch

WordPress Trac noreply at wordpress.org
Mon Oct 21 13:30:07 UTC 2019


#48384: get_post_time returns wrong value after timezone switch
--------------------------+-----------------------------
 Reporter:  david.binda   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Date/Time     |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When testing the r46154 , I've run into a regression, when the returned
 time from `get_post_time` is incorrect after a timezone setting swith.

 I know that the timezone is not expected to be changed often, but it still
 may happen.

 In case a post is created with a timezone set, for instance, to UTC+0, and
 then later changed to a different one, for instance UTC+2, the
 `get_post_time` function with the `$gmt` param set to `true`, i.e.
 expecting UTC+0, would return an original post time with the new offset
 added/substracted (expected behaviour would be the same time, as the post
 was created under the UTC+0 timezone).

 The issue is visible on post listing in wp-admin/edit.php, where post
 created during the UTC+0 timezone being set, are marked as 2 hours ago,
 after changing the timezone to UTC+2.

 I've created a phpunit test demostrating the issue. The test is passing in
 5.2.4, and even on 5.3 RC1 after reverting the r46154, but not when r46154
 is being applied.

 Checking the updated code of `get_post_time`, `get_post_modified_time` and
 of a newly added `get_post_datetime`, as well as `get_post_timestamp`, it
 feels like those functions should default to work with the gmt version of
 the date (stored in post_date_gmt/post_modified_gmt) and should
 recalculate the GMT datetime to currently set timezone, rather than
 changing the `post_date` to UTC, as the code does not know, what timezone
 was used for storing the data.

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


More information about the wp-trac mailing list