What I'm Doing...

Subscribe

Search

Email

  • Memphis, TN 38103 U.S.A. Otto 240cf86e-5cad-11dc-8314-0800200c9a66

Buy Otto a Beer

Currency:

Amount:

Website(Optional):

Get Otto a Gift

My Amazon.com Wish List
Text

Automatic Timezone – A WordPress Plugin

Note: This plugin is no longer necessary in WordPress 2.8, because the functionality of it has been integrated into WordPress itself. If you’ve upgraded, you can remove this plugin.

Overview

One of the things that has always annoyed me about WordPress is the need to adjust the settings every so often, for one reason or another. Major things like how things look are fine, but minor things like having to set it for daylight savings time, or figure out what timezone I’m in… the computer should figure that stuff out. So I wrote the Automatic Timezone plugin. It’s simple, it’s easy.

WordPress normally requires you to set a date offset for the blog in terms of a numeric difference from GMT/UTC. Instead of that, this plugin uses the zoneinfo database, built into PHP 5 and most Linux systems. You just select a timezone instead.

The advantage of this is that the database contains all that is needed for daylight savings time adjustments, and you don’t have to manually change the clock twice a year anymore.

Download Now

Requirements

Only one: PHP 5 and up or PHP 4 running on a Linux-based hosting service (sorry Windows PHP4 users… all 3 of you).

I highly recommend that you use PHP versions 5.2 and up with WordPress. PHP 4 is dead. Ask your web host to upgrade now, or ask them how you can use PHP 5 on your website. Most hosts offer a way to do it.

Features

  • Choose your timezone based on the standard zoneinfo method (by nearest city).
  • Automatically adjusts to daylight saving time.
  • Uses the built-in database of your server to determine DST rules. If the rules change in the future, your server will get updated and those rules will get updated automatically as well.

Installation Instructions

Unzip. Put automatic-timezone plugin directory into wp-content/plugins on your server. Activate the plugin. The plugin will check if it will work on your machine and it will refuse to activate if it won’t work.

Licensing

This plugin is licensed under the GPL Version 2 only.

Method to get support

You are free to email me, however I am also a moderator at the WordPress.org support forums, so you’ll find me there as well.

FAQ:

What is this list of cities? Where do I pick my Timezone?

The zoneinfo database uses a method of timezone choices that most people may not be familiar with. Instead of picking a named timezone, you pick a major city close to you that shares your timezone. The reason for this is although there’s 24 hours in the day, there’s hundreds of different ways of dealing with daylight savings time around the world, and laws and such change these all the time. The zoneinfo database tracks these and stores each different set of settings in a different “named” timezone, named after an area, such as a city, that uses that set of rules. So instead of picking something like “Central Time” or “Greenwich Mean Time”, you will choose a city. That determines what set of daylight savings rules you will use. For your convienence, the cities are grouped by continent.

The plugin won’t activate, it says it can’t find a list of timezones.

The plugin won’t work on some systems. Notably, Windows servers running PHP 4. Upgrade to PHP 5.

It’s not working, and I’m using PHP 4 on a non-Windows system.

This plugin works best with PHP 5.1 and up, but it should also work okay on some PHP 4 systems with Linux/Unix hosting. If it doesn’t, email me and I’ll try to help. It does try a few different methods, but if it won’t activate, then it also won’t work, so don’t try to force it or anything.

Download Now

55 Comments »

55 Comments

  • [...] And this bug from WordPress 2.1.2 is fixed, eliminating the need for this plugin. [...]

  • [...] Der Blog läuft unter Wordpress, das Ausgans-Theme ist Grid Focus von Derek Punsalan, unter anderen laufen die Plugins Add Lightbox, Lightbox2 for Wordpress, Vipers Video Quicktags und das automatic Timezone Plugin. [...]

  • [...] Automatic Timezone is the plugin on which this enchancement was based. It adds the same functionality to WordPress 2.5, 2.6 and 2.7. [...]

  • [...] Automatic Timezone Plugin von Otto nutzt die zoneinfo Datenbank, die in PHP 5 und den meisten Linux Systemen eingebaut ist um [...]

  • [...] turns out that time zone support in WordPress is dismal. Even with the Automatic timezone plugin, which I tried briefly, I can’t figure out how to make WordPress store all post and [...]

  • Hausmeister says:

    plug-in is not workig correct… it doesn’t show my any “time-zones” in admin-panel :(

    i’m using wp (latest version, german) and everything else is working fine. php version is 5.1.2

    any ideas why the plugin doesn’t show my any time zone???

    greets

  • Squarecandy says:

    great job – awesome simple plugin. I can’t believe we need a plugin for this. Anyone using any sort of events calendar plugins or anything else like that can’t do without it. This should be part of wordpress core! Do you know we should most effectively suggest that to the wordpress development community?

    • Otto says:

      Already done. I wrote the patch to get the basic functionality of it into WordPress 2.8. :)

      • Kenji says:

        So this plugin can be deactivated and deleted when WP 2.8 comes out?

        • Otto says:

          Yep. The 2.8 functionality basically duplicates this. It also is compatible, meaning that if you used this, then 2.8 will know about your setting and continue to use it.

          I’ve been considering upgrading the plugin to make it self-deactivate when 2.8 is being used. It’s not necessary, exactly, but it does seem like it’d be cool. ;)

          • Kenji says:

            Excellent — thanks for the quick response. I’m writing up my ten favorite WordPress plugins and want the final article to reflect v2.8’s functionality. I was going to recommend Automatic Timezone… I still will, but with the caveat that it’s best with pre-2.8.

  • [...] for quite some time developed by Otto but it hasn’t been implemented due to its reliance on PHP5. http://ottodestruct.com/blog/w.....-timezone/ I remember reading somewhere that some changes were going to be made and it would be part of [...]

  • [...] davor zurückschrecken oder wie ich eher zu der fauleren Fraktion gehören, gibt es das Automatic Timezone-Plugin was das automatisch für mich regelt. Hierbei wird einfach nur die gewünschte [...]

  • [...] Aber damit ist nun schluss. Nun gibt es ein Plugin das diese Arbeit übernimmt. Einmal Automatic Timezone installiert, und die manuelle Umstellerei hat ein Ende. Bis die Funktion irgendwann mal in einer [...]

  • [...] kann von sich aus die Umstellung nicht. Entweder stellt man händisch um oder man nutzt das Automatic Timezone Plugin von [...]

  • [...] på Wordpress, och behöver därför manuellt ändras i tidsinställningarna. Som tur är har ottodestruct.com släppt ett insticksprogram som automatiserar [...]

  • Anna-marie says:

    Hi Otto,

    1) Thanks for your plugin – it is almost essential for my plugin to handle timezone differences correctly between calendars, servers and wordpress installations!

    2)HTML validation: Your “clock.png” in the admin menu:
    I was testing my plugin’s validation and the admin page was not validating -it was actually a missing “alt” on your little clock icon on the admin settings menu timezone item.

    Validator response:
    required attribute “alt” not specified.

    …lock.png” style=”margin-right:4px;” />Timezone<a href=’options-g

    Thought you might like to know for next time you update the plugin. – just add an alt to the image.
    Regards, anna-marie

  • Vince says:

    Very nice plugin, thanks !
    Actually I’ve made a similar one for my old phpbb/PHP4 board, but hadn’t enough motivation to develop a good one for WP/PHP5 :)

    NB : there is a typo in french translated labels : ‘Heuresement’ => ‘Heureusement’

  • [...] Se mere på Automatic Timezone – A WordPress Plugin. [...]

  • [...] Automatic Timezone – Update the timezone automatically; I need the right timezone for the Twitter Tools plugin with my patch, and any work savings is a good work savings when you run a blog [...]

  • Charles says:

    Hello, I have a question about your excellent plugin.

    I need to display dates/times to many users in different time zones, and I was wondering if I could use your plugin to allow users to select their time zone when they create an account and then adjust event times (e.g., meetings, event start times, etc.) for each user? Can your plugin be used in this manner, or is it mainly for a WP admin to manage his/her one time zone?

    Thanks,
    Charles

    • Otto says:

      Sorry, but no. The whole of WordPress is somewhat built upon the idea that the blog itself has but one time zone. This plugin makes it easier and more automatic to select that timezone, but it doesn’t add any per-user functionality. However, with some modification and adaptation, it could be used in that fashion. It’s not a minor task, however, and would take some doing.

  • Ajay says:

    This plugin does not work for India, right? I couldn’t find any city wich is in Indian timezone +5:30

    • Otto says:

      Actually, this plugin does not contain any timezone info by itself. It gets the timezones from your installation of PHP or the server, depending on what your server supports. This is because the server itself is likely to be more up-to-date than anything else.

      I believe the correct timezone for India is Asia/Calcutta or Asia/Kolkata if that is available.

  • [...] from 2008-11-10] You can also use Otto’s WordPress plugin Automatic Timezone – but note that you should have PHP5 installed for that [...]

  • SunBum says:

    Hello,

    This is something I really need for another PHP app.

    What is the best way to make this generic i.e; strip the WP things from it. Sorry if this sounds strange :)

    Would like to strip it to plain functions that could be called from any
    PHP app.

    Thanks for the great code!

    • Otto says:

      It’s pretty WordPress specific, due to the way WordPress works. However, you can roll your own fairly simply. After PHP 5.1, you can use timezone_identifiers_list() to get an array of all the available timezones. Then you can choose one and call date_default_timezone_set() with that string to set the default timezone. After that, all date functions and such will use that timezone, except for the gmdate and similar functions, which operate in UTC time. I use my own calculations because WordPress expects a timezone offset instead, but for a generic app I would not do it that way.

      There is one generic function in the code that I more or less stole from an example posted on php.net. It takes the array of timezones and produces the nice ordered HTML dropdown list. It’s generic enough to use anywhere.

      The PHP 4 method I use is kind of a hack, so I would not recommend supporting it much, if at all. PHP 5 is becoming fairly standard now.

  • [...] Automatic Timezone voor automatische overgang zomer/wintertijd [...]

  • [...] di fornire un supporto di base ai blogger che affidano a WordPress le loro pubblicazioni online: Automatic Timezone Plugin by [...]

  • Hello Otto,

    I’ve translated your awesome plugin in Italian! ;-)
    Could I send you the .po & .mo files?

    Thanks in advance

    Best regards

    Gianni Diurno
    gidibao.net

    PS
    My WP-Plugins translation works (sample) | http://gidibao.net/index.php/portfolio/

    • Otto says:

      Sure, if you send me translation files, then I’ll include them in the plugin. I think I only need the MO file, actually.

  • baron says:

    hi. Thanks for plugin

    perfect.

    Regards

  • Alex says:

    Thanks for the reply, Otto. :-)

  • Alex says:

    Otto,

    Thanke for this plugin – very useful!

    Being a novice plugin writer I was especially interested in reeading through your code, particularly the comments, learning more about best practices. I do have one question, however, which relates to you not closing the php tag at the end of the file. Would you be able to explain this further? Is it actually bad practice to close the php tag?

    Thanks in advance.

    Alex.

    • Otto says:

      It is a good idea to leave the end of your plugin open, without closing the php tag, because that ensures that any blank lines at the end of the file don’t cause output. If including your plugin produces any output, then it breaks WordPress’s ability to send headers, which can break the login process, feeds, and several other things.

      So yes, always leave off the ending ?> in your php files, especially for WordPress plugins.

  • [...] auch daran denken, sein Blogsystem umzustellen. WordPress-Usern empfehle ich ja immer das Plugin Automatic Timezone. Einmal aktiviert braucht man sich nämlich um gar nichts mehr kümmern. Das Plugin [...]

  • [...] Automatic Timezone von Otto plugin nutzt die Zoneinfo Datenbank von PHP 5 und den meisten Linux Distributionen. Auf diese Weise muss nur noch die Zeitzone eingestellt werden. Bookmarks setzen: Diese Icons verlinken auf Bookmark Dienste bei denen Nutzer neue Inhalte finden und mit anderen teilen können. [...]

  • [...] zum Plugin auf der Website von Samuel Wood Filed under: dieser Blog [...]

  • Wow–a new version based on my comments in less than a day. That’s what I call service!

    Since I recall reading that this plugin was also meant to be a “best of” practices (or maybe I confused it with another one), I would like to know about the possibility of having a link to the settings page from the plugins page (as was done for “Ozh’ Admin Drop Down Menu” and “One Click Plugin Updater”).

  • Murk says:

    Good-ho.

    Cheers.

  • Otto says:

    Murk: Yes, modern computers always have their internal clocks set to the UTC time. The way they usually operate is that they know the current time in UTC and then calculate the local time based on the timezone they’re also set to. This is how they switch automatically for DST and such.

    Linux based hosts tend to be set to sync their clocks with time servers automatically, so they take care of this sort of thing for you. Windows systems don’t sync automatically by default, however when you set the timezone and the local time, it works backwards and figures out the UTC time, then sets its internal clock to that correctly.

    So while it’s certainly possible that a server has it’s time set intentionally wrong, it would be not be something that happens by accident. An admin would have to do it very intentionally… Default settings will get this right if somebody just sets up a system and doesn’t do anything other than select your timezone, which is 99% of the cases.

    Regarding version number: I always update the readme with the new version information, which is also reflected here as well: http://wordpress.org/extend/pl.....her_notes/

  • Murk says:

    Should all servers be set to UTC?

    Will there be some webhosts who stubbornly set to local time? (stubborn is a word that looks ‘wrong’ to me at the moment!)

    If so, would there be virtue in making a 2 stage thing:

    ‘My server’s timezone is: (default UTC)’
    ‘My timezone is: (default UTC)’

    Personally, my webhost is set to UTC – so I’m making a purely academic point.

    Request: when you bump the version number, it’s not always obvious ‘what’s new’ – any chance of putting this front and centre somewhere?

    I echo the previous sentiment – this plugin fixes a persistent WP annoyance, it really should be core!

  • Otto says:

    Good point. I’ve added that information to the configuration screen for version 1.5.

  • When first using the plugin, I would get a much better case of the warm fuzzies if, when I changed the timezone, it told me what time it currently was. That way wouldn’t have any doubt that I actually picked a correct timezone and the software is working.

    Thanks for fixing one of the holes in WordPress.

  • [...] Automatic Timezone says it all, it automatically sets your timezone (which is one of the few lame tasks when setting up a new blog, the computer should do this for you) Otto is a far better WP coder than I am and is a fine code snippet provider in the wp-hackers mailing list. His plugin is cleanly written, heavily commented, ready for translation, and shows some smart behaviors such as the auto-deactivation if it cannot run on a system. What could I say? I hope this plugin will get integrated into WordPress’ core, with a failover to the actual manual setting for the poor chaps running PHP4 on Windows servers. [...]

  • [...] Automatic Timezone Plugin – automatisch die Sommerzeit -Normalzeit haben — super! [...]

  • Otto says:

    Rwo: Unfortunately, the date and time it gets is the one set by the server itself. If the server has the wrong date, then there’s no good way for the plugin to detect that fact. You need to talk to your host and get them to set the date on their webserver correctly.

  • Rwo says:

    I’m now living in Vietnam ( UTC +7 ).
    I used your plugin and set the city ( Saigon ) but the problem still remain.
    Here is in the General Setting :

    “UTC time is 2008-06-22 3:56:07
    UTC +7 is 2008-06-22 10:56:07
    Fortunately for you, you’re using the Automatic Timezone plugin, and it has automatically set this value for you.
    This setting will change automatically if Daylight Savings Time rolls around.”

    It’s totally wrong cause today is 06/29/2008 :| Anything can fix that problem ?

  • [...] more about the plugin, called Automatic Timezone, on OttoDestruct, also known as Nothing To See Here. « MiniPosts2 test: with more tag [...]

  • [...] First, let’s link to the plugin itself. The plugin is called Automatic Timezone. [...]