6100 comments
2357 subscribers
6264 on Twitter
Subscribe! Feed reader E-mail

Drupal: Timezones and places

The Drupal date_timezone module (part of Date) lets you use city names instead of timezone offsets in order to select a timezone, and that picks up Daylight Savings Time rules in a reasonably good manner, too.

A long list of cities can be hard to work with, though. This list is equally long, but it’s organized by GMT offset, which people are also likely to know.

Index: date_api.module
===================================================================
--- date_api.module	(revision 2404)
+++ date_api.module	(working copy)
@@ -490,6 +490,14 @@
           }
         }
       }
+
+      // Now reformat the zonenames so that they're of the form (GMT+0800) Asia/Manila
+      foreach ($zonenames as $name => $zone) {
+        $x = date_make_date('now', $name);
+        $list[$name] = '(GMT' . date_format($x, 'P') . ') ' . str_replace(' ', '_', $zone);
+      }
+      asort($list);
+      $zonenames = $list;
       if (!empty($zonenames)) {
         cache_set('date_timezone_identifiers_list', 'cache', serialize($zonenames));
       }

There’s probably a much more efficient way to do this, but hey, it works.

Short URL: http://sachachua.com/blog/p/6285

On This Day...

  • 2013: First impressions of Artrage 4 — I occasionally use Artrage Studio Pro for tracing images or animating sketchnotes. The interface doesn’t lend itself as well to [...]
  • 2012: Visual metaphors: Success — This is part of my Visual Metaphors series. I’m drawing these to help expand my visual vocabulary for drawing sketchnotes. [...]
  • 2011: Victoria Day weekend: back to the garden — Back home and back to the garden! The plants had been very busy growing while I was away. The oregano [...]
  • 2010: The garden in May —     I’ve written a little bit about our garden, but I haven’t reflected on how the garden helps [...]
  • 2009: Weekly review: Week ending May 22, 2009 — From last week: Revise our event calendar some more I think I’ve gotten a handle on those pesky timezone problems… Fix up [...]
  • 2009: Monthly review: April 2009 — Better late than never! =) Here’s what April 2009 was all about: HappinessI thought about my typical day’s happiness, what makes [...]
  • 2007: It’s good to be back — I still hate travelling by myself (especially when I can’t drown out distractions with music), but welcomes like this make it [...]
  • 2006: ARGH! — It’s a good thing that I’ve been cramming my paper all day, or I would’ve felt seriously upset about missing [...]
  • 2006: Stranger of the Day: Greg — On my way out of the common room to grab some lunch, I saw a very interesting collection of postcards on [...]
  • 2006: Up early — I’m up at 6 on the last day of a long weekend, _and_ I’m reading research papers. =) I hope Mark’s [...]
  • 2004: Graduation — 55er — The valedictorian choked back tears several times during her speech. The keynote speaker drawled on with great seriousness. My co-teachers grudgingly paid [...]
  • 2003: Dumb IT hiring practices — Andy Sy posted this to the compsci@lists.free.net.ph mailing list: ‘Dumb IT hiring practices’ http://www.angrycoder.com/article.aspx?cid=10&y=2002&m=5&d=24 I’ve seen the situation described in this article oh-so-often in [...]
  • 2003: Took some PersonalityQuizzes — Hmmm. Picked them up from cyberlizard.
  • 2003: Talked to a random stranger today — On the shuttle home from Libis, I chatted with Robert Rabago, an IBM communications intern who had recognized me from the [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!