Sunday, July 10, 2011

Adding GMT/UTC to World Clock widget

The World Clock widget does not come with the option of displaying Universal Coordinated Time (UTC), what's sometimes referred to as Greenwich Mean Time. Nevertheless, it's easy enough to add the option yourself. The various time zones in the widget are set up in a JavaScript file buried in the widget's resources. Use Terminal.app to edit it. (You'll probably need to use sudo.)

Open the following file in vi:

sudo vi "/Library/Widgets/World Clock.wdgt/WorldClock.js"

The file contains a bunch of lists denoting parts of the world: South America, Pacific, Atlantic, Europe, et al. Each of those lists contain dictionary (or hash) entries for the various time zones in the list. For example, Europe's list begins: Amsterdam, Athens, Belgrade, Berlin, and so forth.

Purely out of Eurocentric chauvinism, I've put the entry for UTC in Europe's list, between Stockholm and Vienna:

{city:'UTC', offset:0, timezone:'UTC', id:""}

Each entry is separated by a comma, so be sure to add a comma after the entry. (Pay attention to what the code looks like to begin with.)

There is probably some fancy way of restarting the widget server, or whatever, but I just rebooted the machine after making the edit. The next time you bring up the World Clock widget, UTC will be available.

No comments: