Skip to content

buildscientist/prayertime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrayerTime Go Report Card Coverage Status

PrayerTime is a Go based library that calculates Muslim prayer times occurring 5 times a day. The library was ported from Hamid Zarrabi-Zadeh and Hussain Ali Khan's Java implementation.

Full details as to the overall prayer calculation algorithm are available on the Praytimes.org site.

Credit

Special thanks to Sal Zia of Maverick & BlueBerry for the gopher artwork. Original design credit goes to Renee French.

Prerequisites

  1. Go (v1.7 of above) installed on target workstation.
  2. GOPATH environment variable set correctly.

Installation

go get github.com/buildscientist/prayertime 

API

The PrayerTime Go API is fairly simple to use - the user does not need to understand the underlying calculations to use the library.

The PrayerLocale struct is defined as follows:

type PrayerLocale struct {
	latitude, longitude, timezone float64
	PrayerCalcMethod,AsrJuristic,AdjustHighLats,TimeFormat int
}

It requires 3 parameters:

  • Latitude - integer value from 90 to -90
  • Longitude - integer value from -180 to 180
  • Timezone - integer value denoting offset from UTC

The other parameters are not required and are preset at instantiation including:

  • PrayerCalcMethod - set to prayertime.ISNA
  • AsrJuristic - set to prayertime.SHAFII by default
  • AdjustHighLats - set to prayertime.NONE by default.
  • TimeFormat - set to prayertime.TIME_12 by default. Displays prayer times in the format of hh:mm suffix

Example

package main

import (
	"fmt"
	"github.com/buildscientist/prayertime"
	"time"
)

func main() {
	location, _ := time.LoadLocation("America/Chicago")
	_, offset := time.Now().In(location).Zone()
	timezone := float64(offset / 3600)

	chicago := prayertime.New(41.879626, -87.648217, timezone)
	chicagoPrayerTime := prayertime.CalculatePrayerTimes(&chicago, time.Now())
	printPrayerTimes("Chicago", chicagoPrayerTime)
}

func printPrayerTimes(city string, prayertimes []string) {
	today := time.Now()
	fmt.Println()
	fmt.Println("=======" + city + "=======")
	fmt.Println(today.Month(), today.Day(), today.Year())

	for x := 0; x < len(prayertimes); x++ {
		fmt.Println(prayertime.PrayerTimeNames[x] + " - " + prayertimes[x])
	}

}

This should output something similar to the following:

=======Chicago=======
September 20 2017
fajr - 05:18 AM
sunrise - 06:35 AM
dhuhr - 12:44 PM
asr - 04:14 PM
sunset - 06:55 PM
maghrib - 06:55 PM
isha - 08:12 PM