Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 11 years ago

#5970 closed defect (bug) (fixed)

"Human time" difference has time zone problems

Reported by: jhodgdon's profile jhodgdon Owned by: westi's profile westi
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)

humantime.diff (2.9 KB) - added by jhodgdon 16 years ago.
Fix human time difference issues on several screens

Download all attachments as: .zip

Change History (6)

#1 @jhodgdon
16 years ago

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:

$time = get_post_time();
// or
$time = get_post_modified_time();

$human_time = human_time_diff( $time );

The get_post_time and get_modified_time functions work like this:

  1. Get the timestamp from the database table (which is stored in your current local time zone).
  2. Convert it to a Unix timestamp, by using the mktime PHP function.

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...

@jhodgdon
16 years ago

Fix human time difference issues on several screens

#2 @jhodgdon
16 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.

#3 @westi
16 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

#4 @westi
16 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6995]) Fix the display of human time difference when server timezone if different from blog timezone. Fixes #5970 props jhodgdon.

#5 @nacin
11 years ago

"G" has a meaning in date(), which means this probably should have been looked at from another angle. Too late now, but someone may stumble across this in a few years and realize this should be re-done and fixed up.

Note: See TracTickets for help on using tickets.