#5970 closed defect (bug) (fixed)
"Human time" difference has time zone problems
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.5 | Priority: | normal |
Severity: | normal | Version: | 2.5 |
Component: | Administration | Keywords: | has-patch |
Focuses: | Cc: |
Description
As of [6994] in 2.5 bleeding, the "human time difference" shown on Manage Posts, Manage Pages, and Media Library screens can be incorrect, depending on your time zone settings.
Here's how to reproduce this problem:
a) On the General Settings page, set your time zone to something that is different from the time zone on the server where your WordPress installation is running. For instance, set it to UTC + 11, and save the settings.
b) Click "Write" and write a new post. Save it (no need to publish).
c) Visit the Manage Posts screen, and click on Drafts to see your new post. When I did this, it said it was last modified 19 hours ago, although it was less than a minute ago.
This can also be seen on the Manage Pages screen and the Media Library screen, if you create a page or upload some media files.
I'll put my explanation of the reason for the bug in a separate comment, and then attempt to fix it.
Attachments (1)
Change History (6)
#2
@
17 years ago
- Keywords has-patch added
This patch fixes the problem. It has the added benefit that if you go to your Settings page and change the time zone setting, then go back to any of these three management screens, the times shown are still accurate.
Here's what I think is going on.
All three of these screens use the "human_time_diff" function to show update times on the screen. In particular, they are doing something like this:
The get_post_time and get_modified_time functions work like this:
The problem with this is that mktime assumes that the input is in the local time zone, with "local" meaning the time zone on the server where PHP is running -- not the time zone in your General Settings. So it is creating a timestamp that is potentially several hours off of the correct unix timestamp for the moment when that post was created or modified.
Then the human_time_difference compares this to time(), which is always the current moment's correct time stamp (the server does the right thing with the time zones). So the difference, in my example, is 19 hours off.
The correct thing to do would be to use gmmktime applied to the stored GMT timestamp in the database, to create the real time stamp for the post time or post modified time.
I'll submit a patch...