[wp-trac] Re: [WordPress Trac] #5970: "Human time" difference has time zone problems

WordPress Trac wp-trac at lists.automattic.com
Sat Feb 23 17:39:28 GMT 2008


#5970: "Human time" difference has time zone problems
----------------------------+-----------------------------------------------
 Reporter:  jhodgdon        |        Owner:  anonymous
     Type:  defect          |       Status:  new      
 Priority:  normal          |    Milestone:  2.5      
Component:  Administration  |      Version:  2.5      
 Severity:  normal          |   Resolution:           
 Keywords:                  |  
----------------------------+-----------------------------------------------
Comment (by jhodgdon):

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

-- 
Ticket URL: <http://trac.wordpress.org/ticket/5970#comment:1>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list