[wp-hackers] Possible bug in the function human_time_diff()

Otto otto at ottodestruct.com
Thu Mar 26 18:11:46 GMT 2009


No, that doesn't make any sense unless you set your time zone wrong to
start with.

Look at your code:
<?php echo human_time_diff(get_the_time('U'),
current_time('timestamp')) . ' ago'; ?>

get_the_time('U') gets the timestamp of the post, as WordPress thinks
it is. So it's accounting for the time zone setting there, or, at
least, the time zone that the blog was set to when the post was made.

current_time('timestamp') gets the time with time zone setting accounted for.

human_time_diff doesn't care about time zones. It's taking two
absolute times and getting their difference.

On the settings page, your time zone should be YOUR time. The "server
time" should always be the absolute UTC/GMT time, regardless of what
time zone it's in. The important point here is that after you've set a
time zone on the settings screen, then it will show you your local
time, where you happen to be sitting at. Where the server is located
is irrelevant.

-Otto
Sent from: Memphis Tennessee United States.


On Thu, Mar 26, 2009 at 6:41 AM, Chetan Kunte <ckunte at gmail.com> wrote:
> To add to my previous observation, and going by the logic, I need to
> set my location time to match my server time, or else
> human_time_diff() shows time erroneously for the day it is published.
>
> Currently I've set my time as GMT +1 under settings. But if I set it
> as GMT-6 (same as my server time instead of my actual location time),
> then there would be no more time zone crossing point, and so the time
> would continuously increase (not descend until it reaches your actual
> time zone before ascending like I mentioned earlier). But then it
> defeats the purpose of having a time zone setting in WordPress---at
> least in this case.
> --
> Chetan
>
>
>
> On Thu, Mar 26, 2009 at 12:26 PM, Chetan Kunte <ckunte at gmail.com> wrote:
>>> The function "get_the_time" will get the time for the current post.
>>> Are you putting this code in the correct place in the Loop?
>>
>> Yes, I am. It is a simple loop. It displays post date followed by post
>> title. I have replaced the the_time() or the_date() call with echo
>> human_time_diff() . With the exception of the day it is published on,
>> it works fine for other days. On the day it is published, due to
>> perhaps time zones, it gets 'mungled', I think.
>>
>> Here's what's happening:
>>
>> Host server is in GMT -6.
>> I am publishing from GMT+1.
>>
>> 1 minute after publishing, it shows 5 hours ago, so appararently it is
>> doing this: abs(-6+1)= 5hrs ago.
>> 1 hour later, it becomes, I think abs(-6+1+1)= 4hrs ago.
>> 5 hours, 1min later, abs(-6+1+5)= 1min ago.
>> 6 hours later, abs(-6+1+6)= 1 hour ago.
>> 12 hours later abs(-6+1+12) = 7hours ago.
>>
>> Does anyone else has seen this happening?
>> --
>> Chetan
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list