# Any Muslims around?

**URL:** <https://www.ruby-forum.com/t/any-muslims-around/112029>\
**Category:** Ruby\
**Created:** [August 14, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029 "2007-08-14T13:50:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 14, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/1 "2007-08-14T13:50:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 14, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/2 "2007-08-14T14:16:54Z")

</div>

> 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.

I guess time for prayer is at certain times per day? You could  
get the current time with Time.now, then sleep the appropriate  
time to the next prayer, and then wake up and to whatever you  
would like to do.

Ronald

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 14, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/3 "2007-08-14T15:30:11Z")

</div>

On 8/14/07, Ronald F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
> 
> I guess time for prayer is at certain times per day? You could  
> get the current time with Time.now, then sleep the appropriate  
> time to the next prayer, and then wake up and to whatever you  
> would like to do.

Hi,

you could also have a look at :

[http://openwferu.rubyforge.org/scheduler.html](http://openwferu.rubyforge.org/scheduler.html)

to install it :

sudo gem install openwferu-scheduler

then write a program that looks like :

—8\<—

require ‘rubygems’  
require ‘openwfe/util/scheduler’

include OpenWFE

scheduler = Scheduler.new  
scheduler.start

scheduler.schedule(“0 6 \* \* \*”) do  
puts “time for the morning prayer”  
end  
scheduler.schedule(“0 12 \* \* \*”) do  
puts “time for the noon prayer”  
end

# or

scheduler.schedule(“0 6,8,12,16,18 \* \* \*”) do  
puts “bismillah…”  
end  
—\>8—

The scheduler follows the “cron” convention  
([man 5 crontab - Google Search](http://www.google.com/search?q=man%205%20crontab))

Maybe you’re better off with a ruby program triggered by the cron in  
your system (if it’s a Unix / MacOSX one).

Best regards,

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 14, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/4 "2007-08-14T16:43:24Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 15, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/5 "2007-08-15T23:31:56Z")

</div>

John M. wrote:

> > 
> 
> sudo gem install openwferu-scheduler
> 
> # or
> 
> your system (if it’s a Unix / MacOSX one).
> 
> Best regards,

Some awesome suggestions here, but I think it’s a bit more complex  
considering how times vary from location to location. I guess I’ll have  
to try to make sense out of  
[http://www.arabeyes.org/project.php?proj=ITL](http://www.arabeyes.org/project.php?proj=ITL). As I said though, I’ll  
report back to base once I got something.

Thanks again guys!

All the best,  
Kyrre

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 16, 2007, 10:09am UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/6 "2007-08-16T10:09:25Z")

</div>

> Some awesome suggestions here, but I think it’s a bit more complex  
> considering how times vary from location to location.

But you have the timezone for each location, right? If you use the  
DateTime  
class for calculating times, you can convert between time zones using  
the  
new\_offset method, if you know the offset of the respective time zone to  
UTC.

If you only know the _name_ of the time zone, there is a hack on how  
to do it using the Time class, described in the “Ruby Cookbook” (which I

would recommend buying anyway). This hack works if your operating system

honours the TZ environment variable. You switch temporarily to this zone

(by changing TZ), get the local time there, and switch back to your own  
zone. You then have the time diff to your zone, and you can always get  
the time UTC time by calling Time#gmtime.

Ronald

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 15, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/7 "2007-08-15T23:28:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [August 16, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/any-muslims-around/112029/8 "2007-08-16T16:41:19Z")

</div>

On Thu, 16 Aug 2007 17:07:43 +0900, Ronald F. wrote:

> would recommend buying anyway). This hack works if your operating system  
> honours the TZ environment variable. You switch temporarily to this zone  
> (by changing TZ), get the local time there, and switch back to your own  
> zone. You then have the time diff to your zone, and you can always get  
> the time UTC time by calling Time#gmtime.
> 
> Ronald

I prefer the tzfile gem for dealing with timezones.

–Ken
