From: ara.t.howard@... Date: 2006-08-10T06:09:18+09:00 Subject: Re: solar local time On Wed, 9 Aug 2006, Ara.T.Howard wrote: > too funny. this is a sketch of my code so far: for anyone following the thread or searching archvies here's the answer i ended up with, it's correct afaik: harp:~ > cat a.rb require 'date' require 'time' # # returns a datetime object defined at a certain location on earth. in # otherwords a certian time 'there' not 'here' or 'utc' - a time in an # arbitrary other timezone. # def solar_localtime time, longitude deg_per_hr = 15 secs_per_hr = 60 * 60 longitude = Float longitude t = case time when Time time.utc when DateTime Time.parse time.to_s else Time.parse time.to_s end if longitude > 180.0 off_sec = - ((360.0 - longitude) / deg_per_hr) * secs_per_hr tz = - ((360.0 - longitude) ) / 360.0 else off_sec = (longitude / deg_per_hr) * secs_per_hr tz = (longitude ) / 360.0 end t += off_sec y, d, h, m, s = %w( year yday hour min sec ).map{|m| t.send m} DateTime.ordinal y, d, h, m, s, tz end # # demo # now = Time.now.utc # you could also do: now = DateTime.now puts(now.iso8601) require 'yaml' [15, 30, 45].each do |longitude| y longitude => solar_localtime(now, longitude).to_s y -longitude => solar_localtime(now, -longitude).to_s end harp:~ > ruby a.rb 2006-08-09T21:06:33Z 15: 2006-08-09T22:06:32+0100 -15: 2006-08-09T20:06:33-0100 30: 2006-08-09T23:06:33+0200 -30: 2006-08-09T19:06:32-0200 45: 2006-08-10T00:06:33+0300 -45: 2006-08-09T18:06:33-0300 the trick is use DateTime - you can't do it with Time. regards. -a -- to foster inner awareness, introspection, and reasoning is more efficient than meditation and prayer. - h.h. the 14th dali lama