Clocks with Google Chart API
January 7th, 2008 by Ryan GovostesHave you seen Google’s Chart API? Send it a formatted GET request and it will spit out a pretty graph. The API is fairly powerful, supporting dozens of options and five different chart types, including Venn diagrams and pie charts.
What you may not know is that there is an undocumented “clock” chart type. It’s used by Google when you do time zone queries, such as time in ithaca, ny. The little icon that appears next to the result actually displays the correct local time; what’s more, the clock border is silver for night and gold for day. Here’s the URL of the image:
http://www.google.com/chart?chs=40×30&chc=localtime&cht=cf&chd=s:Wp&sig=-r0X-_m3bpzbNNulLXfJyr7SDTI
(Pay no attention to the fact that the URL is expired and go grab yourself a fresh one with a query like the one above.)
The cht (chart type) parameter is cf, likely short for “clock face.” The data, above Wp, is the encoded time; according to the encoding spec, W is 22 and p is 41, so the time is 10:41 PM. chc is not a documented parameter, and only seems to apply to the clock chart type.
But wait, something’s amiss — if you try to fiddle with the URL above, you’ll notice you can’t change any of the parameters or you get back a 400 Bad Request error. What’s the deal? It looks like Google has added a cryptographic signature in the sig parameter; if you change the URL string, you invalidate the signature and Google refuses to generate the clock.
Fear not, you can still generate your own clocks — just drop the sig and chc parameters and everything will work just fine. Note that the clock image is just a 40×30 bitmap; you can’t scale it or change the background.
January 16th, 2008 at 4:14 pm
Tony Ruscoe of the excellent Google Blogoscoped points out that they discussed this on their forum. He writes,
June 5th, 2008 at 12:57 pm
[…] Clocks with Google Chart API: Google Charts will return a nifty little clock face displaying the time in any given location, even changing the border to silver at night and gold during the day. […]