Kyrre Nygård
8/15/2007 9:27:00 PM
Thanks a lot Ken, and the same to you guys, Ronald and John.
I'll report back to base once I got something.
All the best,
Kyrre Nygård
Ken Bloom wrote:
> On Tue, 14 Aug 2007 20:50:02 +0900, Kyrre Nygård wrote:
>
>
>> Just wondering if any Muslims have gotten around to making a Ruby script
>> that like plays a sound or something when it's time for prayer.
>>
>> Thanks,
>> Kyrre Nygård
>>
>
> Would this help? I use it as part of a suite of scripts for computing
> times that Orthodox Jews use to compute times for prayer. The algorithm
> comes from the US Naval Observatory's Almanac for Computers.
>
> --Ken
>
>
>
> require 'date'
> require 'mathn'
>
> #methods stolen from ruby-doc.org
> class Date
> def to_datetime() DateTime.new0(self.class.jd_to_ajd(jd, 0, 0), @of,
> @sg) end
> def to_date() self end
> def to_time() Time.local(year, mon, mday) end
> end
> class DateTime
> def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
> def to_datetime() self end
> def to_time
> d = new_offset(0)
> d.instance_eval do
> Time.utc(year, mon, mday, hour, min, sec,
> (sec_fraction * 86400000000).to_i)
> end.
> getlocal
> end
> end
>
> #end stolen
>
> def dms(degrees,minutes,seconds)
> degrees+minutes/60+seconds/60/60
> end
>
> module Sunrise
> include Math
> class Location
> attr_accessor :latitude, :longitude, :offset
> def initialize(latitude,longitude)
> @latitude,@longitude=latitude,longitude
> end
> end
>
> def toRad(degrees)
> degrees*PI/180
> end
>
> def toDeg(radians)
> radians*180/PI
> end
>
> def sun_rise_set(which,date,location,zenith)
> #step 1: first calculate the day of the year
> n=date.yday
>
> #step 2: convert the longitude to hour value and calculate an
> approximate time
> lngHour=location.longitude/15
> t=n+ ((6-lngHour)/24) if which==:sunrise
> t=n+ ((18-lngHour)/24) if which==:sunset
>
> #step 3: calculate the sun's mean anomaly
> m=(0.9856 * t) - 3.289
>
> #step 4: calculate the sun's true longitude
> l= (m+(1.1916 * sin(toRad(m))) + (0.020 * sin(toRad(2*m))) +
> 282.634) % 360
>
> #step 5a: calculate the sun's right ascension
> ra = toDeg(atan(0.91764 * tan(toRad(l)))) % 360
> ###step 5b: right ascension value needs to be in the same quadrant
> as L
> lquadrant = (l/90).floor*90
> raquadrant = (ra/90).floor*90
> ra=ra+(lquadrant-raquadrant)
>
> #step 5c: right ascension value needs to be converted into hours
> ra/=15
>
> #step 6: calculate the sun's declination
> sinDec = 0.39782 * sin(toRad(l))
> cosDec = cos(asin(sinDec))
> #step 7a: calculate the sun's local hour angle
> cosH = (cos(toRad(zenith)) - (sinDec * sin(toRad
> (location.latitude)))) / (cosDec * cos(toRad(location.latitude)))
>
> return nil if (not (-1..1).include? cosH)
>
> #step 7b: finish calculating H and convert into hours
> h = (360 - toDeg(acos(cosH)))/15 if which==:sunrise
> h = (toDeg(acos(cosH)))/15 if which==:sunset
> #step 8: calculate local mean time
> t = h + ra - (0.06571 * t) - 6.622
> t %=24
> #step 9: convert to UTC
> return date.to_datetime+(t - lngHour)/24
> end
>
> private :sun_rise_set
>
> def sunrise(date,location,zenith=90.8333)
> sun_rise_set :sunrise,date,location,zenith
> end
> def sunset(date,location,zenith=90.8333)
> sun_rise_set :sunset,date,location,zenith
> end
> end
>
>
>