Quick Timezone Calculation

| | TrackBacks (0)

I have been asked what time I get the forecasts for a location in my historical weather forecast system. The obvious problem being that if I read all the forecasts at nearly the same time, different cities could be in different days due to differing timezones.

The answer is, I read the forecasts at roughly midday in each of the locations. That is, every hour I read the forecasts for the locations where it is roughly midday. This is done by approximating the various timezones using the location's longitude. This isn't exact - it doesn't account for daylight savings or places like China, which is all one timezone despite being wide enough to be split into many. Generally it is accurate to within a couple of hours - fine for the purpose. The code is below.

time_band = -Time.now.gmtime.hour + 12
locs = Location.find_by_sql ["select * from locations where longitude >= ? and longitude < ?", (time_band-1)*15, time_band*15]

0 TrackBacks

Listed below are links to blogs that reference this entry: Quick Timezone Calculation.

TrackBack URL for this entry: http://www.cordinc.com/cgi-sys/cgiwrap/cordinc/managed-mt/mt-tb.cgi/38