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.
[...] First, let’s link to the plugin itself. The plugin is called Automatic Timezone. [...]
[...] more about the plugin, called Automatic Timezone, on OttoDestruct, also known as Nothing To See Here. « MiniPosts2 test: with more tag [...]
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 ?
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.
[...] Automatic Timezone Plugin - automatisch die Sommerzeit -Normalzeit haben — super! [...]
[...] 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. [...]
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.
Good point. I’ve added that information to the configuration screen for version 1.5.
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!
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/
Good-ho.
Cheers.
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”).
[...] zum Plugin auf der Website von Samuel Wood Filed under: dieser Blog [...]
[...] 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. [...]
[...] 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 [...]
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.
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.
Thanks for the reply, Otto.
hi. Thanks for plugin
perfect.
Regards
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/
Sure, if you send me translation files, then I’ll include them in the plugin. I think I only need the MO file, actually.
[...] di fornire un supporto di base ai blogger che affidano a WordPress le loro pubblicazioni online: Automatic Timezone Plugin by [...]
[...] Automatic Timezone voor automatische overgang zomer/wintertijd [...]
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!
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.
[...] from 2008-11-10] You can also use Otto’s WordPress plugin Automatic Timezone - but note that you should have PHP5 installed for that [...]