type in your query to search makeyougohmm
Things that ... make you go hmmtechnology music video art news reviews and muse on the web

January 25, 2007

Being off by hours, Wordpress timezone change impact on archived posts and comments

developers, blogs and podcasting — by TDavid @ 4:28 pm PST

Wordpress timezone change doesn't impact the archived post/date times

Learned something new about Wordpress.

For quite some time I’ve wanted to use Pacific Standard Time on this blog instead of Eastern Standard Time. Nothing against you east coasters, but I don’t live on the east coast and I’ve been making manual timezone changes in my head instead of doing the simpler thing: just change the timezone. Admittedly, this is a selfish change, but there is probably nobody else in the world that spends as much time at this site as me, so I might as well have the clock set to my home zone, right?

A more logical change would allow every reader and author to set their preferred timezone and perhaps a WP plugin or core operation adjusts the timestamp displayed to match the clock. Maybe a Wordpress plugin exists out there to handle that already (or maybe it’s already a part of being a registered/logged in user)? A long time ago I created some Javascript code that worked in tandem with PHP to figure out the time set on the computer and display that. Suppose I could conjure that code and bring it into a plugin or something. Only problem there is that if the person’s computer clock is wrong or they aren’t running javascript (or blocking javascript) then the times have to revert to a default setting. For my uses elsewhere years ago, this was a fine solution. That would probably work here too.

How to change the timezone
If you go into the Wordpress Admin->Options and change the timezone, it doesn’t actually alter the timestamps of the posts and comments, which means that by switching from right coast (EST) to left coast (PST) all existing posts and comments would now display off by three hours when PST is added to the end of the timestamp.

Every archived post before this one as of this writing, in fact, are now indeed off by three hours. The times displayed are actually EST and yet the PST I added to the templates is wrong. Aren’t timezones fun?

A few solutions came to mind
Being a programmer, this got me thinking about the best way to deal with the situation.

1) adjust the timestamp on the fly. Pros: no need to change the database, a one or two liner piece of code. Cons: forces dynamic script to run when the time isn’t going to change. Not the most efficient solution.
2) find or create myself a script to cycle through the WP database and change all the timestamps for every archived post and comment. Pros: permanent change in the database, no additional run time scripting needed. Cons: unless there is a plugin or mod script already written, I’ll need to create the code myself

A core Wordpress change would be to use GMT for everything and then offset the displayed time based on user settings dynamically. This way nobody would ever have to go into the database and make manual time data changes when a timezone has been changed. That is how I’ve dealt with timezone concerns in programs like these. In fact, last month I shared how to write a program using PHP that showed how to calculate days in the future and incorporates timezones changes.

This seems like buggy architecture that you can easily change the time in the WP admin area but if you do this to an already established blog it doesn’t fix the past, it only changes the future, and it doesn’t tell the user this is happening. The only way I noticed this was happening was by making a comment and seeing the comments out of order. On further investigation I saw every post was out of order too. I was able to fix them easily by manually editing the timestamps, but no way would anybody do this with thousands of posts and comments manually. That’s what scripting is for.

Sure, I realize it’s only three hours, big deal, right? Maybe option #3 is not to bother with this at all but this is the kind of nitpicky thing that us programmer types get wrapped up in sometimes. Ok, won’t speak for others, just myself, it’s the kind of detail I get wrapped up in sometimes.

v2.1.0 has same issue
Hoping maybe with the new Wordpress 2.1.0 maybe this was one of the 500+ bugs that was fixed, I decided to investigate that option on another blog.

I checked out the situation on our group blog VTOR and switched from EST to PST and the same problem there. PST makes good sense there because Second Life time or SL time as it’s sometimes called is PST. New posts and comments have the correct timestamp but the archived ones are still off by three hours just like here. So upgrading to the newest version and changing the time doesn’t fix this issue.

BTW, some might not consider this a bug at all. To me it’s a bug because the user behavior assumes that by changing the timezone all their posts, not just new posts, will be displayed correctly. Giving the user no message or warning that old posts won’t be changed is problematic.

Answers at Wordpress support?
I did a little poking around in the Wordpress support area to see if anybody had whipped up some code that would cycle through all the old posts and comments and fix the timestamp and didn’t see any fixes. A few people suggested appending “T” to the date code, but that shows the server timezone and isn’t altered by the routine that kicks out the time in Wordpress. Also the newer ‘e’ date code is only available in PHP 5.1.5+. I also did a few Google queries. Didn’t find anything promising right away. Maybe I’m just using the wrong queries to find what I’m looking for.

Before I sit down and write what is probably less than 10-15 lines of code, and if I do that I’ll gladly share the code with others, I thought I’d make a post here first and see if any other Wordpress users have run into this situation and already created this code or used a plugin to fix this quickly and easily.

I’m not the first person using Wordpress who wanted to change the timezone midstream that had this happen, at least Sterling is in the club too. Did everybody else not care if the times on their posts and comments were off by hours? Maybe I shouldn’t care either. The future posts and comments will show correctly now so it’s only the past that’s off — by three hours. But according to current stats that is nearly 9,000 comments and over 4,000 posts that are off.

I could just blame it on the Twilight Zone.

What do you think?

Did this post make you go hmm?

F = please no more posts like thisD = not among your best stuffC = average postB = good post, I liked itA = great post, please create more like this (Hmm, no ratings yet)

Loading ... Loading ...

Maybe Related Posts (plugin generated)

RSS Feed comments for this post 7 Comments »

  1. It is a pain, but I am glad that Wordpress is free. It is worth it’s weight in gold.

    Just my opinion. Then again, I used to work support for a free audio player and had my head ripped off frequently.

    Comment by pkelley — January 25, 2007 @ 5:40 pm PST

  2. One thing to be careful of is that the permalink URL uses the date. Change the “day” the post happened on and you run the risk of breaking all of your URLs.

    I had a friend do that when he tried to bump old posts to the front page.

    Comment by engtech — January 25, 2007 @ 11:14 pm PST

  3. That is a good point, engtech. Just ran a query to see how many posts fall between midnight and 3am that would be impacted by an actual date change: 204 of 4,140 (4.9%)

    QUERY:
    mysql> select ID, post_title, post_date from POSTS where HOUR(post_date) < 3;

    Could change the time on these to midnight so the day does not roll back and the permalink therefore is not impacted. I notice the date_gmt is also saved. That would not break any permalink URLs that use date. This seems redundant to me. Why need both timestamps? If you already have GMT you can do a timezone offset for posts and comments (like I am talking about in the post in option #1).

    Even though what you mention, engtech, would impact less than 5% of the posts, would probably be less of an issue just going with option #1 on all posts and comments made before a certain time and just rolling back the time programatically, this way not touching the data at all. I know where the timezone was changed, which is the key piece of information.

    I will let this one stew for awhile and give others a chance to chime in before making a decision.

    Edited 6:36am PST and 6:39am PST: Fixed the unclosed italicized text and removed a redundant sentence. Removed the post list, not really needed.

    Comment by TDavid — January 26, 2007 @ 6:33 am PST

  4. pkelley - being on the other side of offering freeware for years, I hear what you’re saying. I wouldn’t dial up one of the Wordpress volunteer developers and bitch anybody out.

    With this post I’m simply trying to explore the best way to deal with what I believe is a not completely rare situation. I do have one solution in mind, but will continue to wait and see if anybody else comes along and offers a better solution.

    Comment by TDavid — January 26, 2007 @ 6:50 am PST

  5. […] I love WordPress. It’s free, and it rocks. But I do wonder why they didn’t store timestamps in universal time to avoid problems like these. […]

    Pingback by Chipping the web - rock lobster -- Chip’s Quips — January 31, 2007 @ 5:50 pm PST

  6. […] Behind the Hmmcast I realize the post time has been messed up on this blog again. Daylight savings has bitten the version of WordPress I’m using (haven’t verified if it’s fixed in the most recent version WP version yet). While the time shows as 4:20pm, it’s actually being published at 5:20pm because of the -8 offset in the settings. Instead of using the server time and adjusting it’s using a gmtdate offset without daylight savings calculated. If I change it to the correct time, then comments made between the last time I changed and now will be off by one hour. […]

    Pingback by Cheap prices, best value and everybody votes on Wii » Make You Go Hmm — March 14, 2007 @ 4:22 pm PST

  7. Yes please i would like to see this fixed too. I’m currently blogging from Thailand which is gmt+7 and most comments are from relatives in Sweden which is gmt+1. My server is also gmt +1. I set the timezone to utc+7 and I also use the T parameter to show timezone. So now all posts and comments come up with Thai/GMT+7 time but still show the timezone as GMT+1, a bit confusing.

    Comment by Max — December 12, 2008 @ 4:48 pm PST


TrackBack URI: http://www.makeyougohmm.com/20070125/4178/trackback/

Leave a comment


By leaving a comment you consent to the Official Hmm Comment Policy

Return Home

Copyright 2003-2008 KMR Enterprises All Rights Reserved. Privacy Policy