Time Zone plugin for WordPress

Written early in the evening in English • Tags: ,

WordPress implements a nice wide selection of hooks for plugins to modify the functionality of the software. I’ve used some of the most recent ones to override the time offset value with information derived from the operating system. The benefit is that WordPress can now automatically observe DST changes.

The result: timezone.php — download it now!

I’ve always disliked having to turn clocks everywhere twice a year. When a computer-based system makes me do it, I’m even more upset. Any relatively modern operating system knows about time zones and daylight saving time rules. Software running on those systems should exploit the information! That said, it is understandable that a multi-platform application such as WordPress will not choose to implement an approach that only works on some of the supported platforms.

There are some external restrictions on the implementation provided by this plugin:

  • using other timezones than that of the server only works on UNIX-like systems, as it is implemented by modifying the TZ variable in the environment
  • changing TZ is not available in PHP‘s safe mode
  • when TZ is changed, only a success message is displayed instead of the full form: this is due to PHP only implementing the old putenv interface for the environment (not the POSIX unsetenv(3) interface)

The Time Zone plugin homepage has quick instructions for installation, but all you really need to is download the plugin and activate it. Enjoy!

Update: You need WordPress 1.5 or later to have the necessary hooks available for this plugin.

20 comments

  • 1

    You are correct. This only works with WP 1.5, as earlier versions don’t have hooks for modifying options. The relevant code was added to CVS on January 27th (in revision 1.239 of wp-includes/functions.php).

    Kimmo Suominen — 13.2.05 @ 20:13

  • 2

    You don’t mention anywhere that this is for latest WP1.5 releases… It doesn’t work on WP 1.2…

    Brett Taylor — 13.2.05 @ 20:06

  • 3

    […] n Peruns Blog, wird ab sofort mein Blog seine Zeit laut Timezone automtisch setzen. Dieses Plugin ist eine php Datei und wird in den WordPressordner Plugins hochgeladen. Dort wird im Adminb […]

    Matthias Webblogg » Timezone wird ab jetzt automatisch eingestellt — 27.3.05 @ 12:51

  • 4

    […] rd. I assumed WordPress would do it automatically, but no. Luckily someone nice has made a Daylight Saving Time plugin, which automatically switches the time back and forth as and when it’s […]

    qwghlm.co.uk: blog : Daylight Saving Time with WordPress — 30.3.05 @ 5:23

  • 5

    […] clock forward. But that’s not good enough for a WordPresser — you need to have a plugin to do it for you of course! Thanks Qwghlm. Permalink: # | […]

    doctorvee » Dst — 30.3.05 @ 11:25

  • 6

    […] ay, either change your damned GMT offset, or (and this may be the better option), use this timezone plug-in. I did the latter and it took all of fifteen seconds and works peachy. In other […]

    omfghax.org » Blog Archive » Timezones… — 9.4.05 @ 1:25

  • 7

    The only place where “Cannot load” is output is in wp-admin/admin.php if the plugin file registered for a plugin page does not exist.

    The only reason I can think of for getting that error is that the plugin was erroneously installed in a subdirectory instead of the plugins directory.

    The plugin does not require modifying any files (neither WordPress core files nor the plugin itself).

    Kimmo Suominen — 22.4.05 @ 14:29

  • 8

    I have just upgraded from 1.2.2 to 1.5 and was very pleased to see that this plugin had been created. I have installed it in my plugin directory and activated it.

    But when I hit “options”, I’m getting the message “Cannot load timezone.php”. Do I have to alter options-general.php in some way?

    ejm — 22.4.05 @ 13:20

  • 9

    Thank you for your reply.

    Okay, I see! I appear to have TWO plugins folders. Some of the plugins go into wp-content/plugins/plugins/ and this timezone one goes into wp-content/plugins/

    So now it works but when I set the timezone to EST (EDT) the time shown is GMT. I also tried America/New_York and had the same results.

    What step have I missed now?

    ejm — 22.4.05 @ 16:22

  • 10

    To clarify, even though I see the following on the timezone options page:

    Time zone name: EDT Time zone offset: -0400 Date and time: Fri, 22 Apr 2005 16:24:55 -0400 (EDT) Automatic WordPress setting Times in the weblog should differ by: -4 hours

    The times shown on the blog are GMT 000

    ejm — 22.4.05 @ 16:27

  • 11

    Sorry to bother you YET again. The times on the blog are all correct now. I don’t know why they were not working immediately.

    Many thanks for making this plug-in. It’s great.

    ejm — 22.4.05 @ 17:25

  • 12

    Here is a list of timezones that may be useful to others who may want to install the plug-in: http://users.wpi.edu/~nv22/calendar/TIMEZONES

    ejm — 23.4.05 @ 9:48

  • 13

    I think wp-content/plugins/plugins is some sort of a mishap. You might want to see about moving everything from it up one level (to wp-content/plugins). Some plugins with multiple files have their own subdirectories, but most plugins install directly in wp-contents/plugins (and most are just 1 file).

    Regarding the times not showing up correctly immediately after activating the plugin: most likely your browser had cached an old copy of the page, and kept showing it to you instead of requesting a new one from the server. Activating and deactivating plugins does not change the Last-Modified date of the page, so this can easily happen. When trying out plugins it is best to use a forced reload (CTRL-F5 on most browsers) to make sure you are getting a fresh copy of the page from the server.

    Thanks for the list of time zones. It’ll be handy for more ideas to try for finding a working TZ value.

    Kimmo Suominen — 23.4.05 @ 16:52

  • 14

    Thanks. That was what i was looking for.

    Marchal — 26.5.05 @ 9:35

  • 15

    Hi there,

    If I have my server in the USA and I am in the UK. Will thisdetect that?

    Just wondered ;)

    Karl Bedingfield — 12.6.05 @ 10:54

  • 16

    Hi Karl,

    You can use the plugin to set the TZ value on UNIX-based hosts to select the time zone you want your blog to be in. In other words, you’d use something like Europe/London to select UK time, regardless where the server is located.

    Kimmo Suominen — 19.6.05 @ 16:57

  • 17

    […] One more upsetting thing about WordPress. It’s not daylight saving time aware. I noticed that the time was off by an hour. Before I sent a service request to my host, I checked the time on the server. It was correct. The time string was correct, but still an hour off. WordPress is not daylight saving time aware. Maybe I’ll hack out some code and add it to the process. Or maybe, I’ll find a plugin to make it aware. I’m sure I’ll have time to bust it out with all the free time I have each day. […]

    The Underwear of the Internet » WordPress Flaws — 5.10.05 @ 6:55

  • 18

    […] Google brought me to Kimmo Suominen’s solution: Time Zone plugin for WordPress. […]

    Le Blog d’Alex » Blog Archive » Time Zone plugin for WordPress — 31.10.05 @ 15:19

  • 19

    Thanks for the plugin… I think it’s what I need but can’t get it to work correctly. I am based in NZ, with a NZ server set to NZ time. I’m publishing using wbloggar from my desktop. Without your plugin, posts have the correct NZ time when published but move ahead by 13 hours when I retrieve the post, edit it via wbloggar, and republish.

    With your plugin, the same thing seems to be happening. I have set ‘Times in the weblog should differ by’ in WordPress admin to 0, but it seems to reset itself to 13 :(

    I’d really appreciate any help – thanks in advance! Joe

    Joe Foote — 2.11.05 @ 19:04

  • 20

    Joe — If you want to manually set the time you need to disable the plugin. While the plugin is enabled, you cannot set the time difference to zero manually. It will always come back as the difference based on the server time or TZ value you use.

    I think there is a bug with the RPC library where the time difference gets ignored. This causes the time to be wrong when using external editors such as wbloggar. I use wbloggar myself to write new posts, but rarely edit any old posts with it, so I haven’t paid much attention to the problem.

    Kimmo Suominen — 15.11.05 @ 11:59

Sorry, commenting is not available for this post.