-
Notifications
You must be signed in to change notification settings - Fork 7
/
5-high-lat-seventh-night.go
35 lines (30 loc) · 1.13 KB
/
5-high-lat-seventh-night.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package prayer
import (
"time"
)
// OneSeventhNight is adapter where the night period is divided into seven parts.
// Isha starts when the first seventh part ends, and Fajr starts when the last seventh
// part starts.
//
// This adapter depends on sunrise and sunset time, so it might not be suitable for
// area in extreme latitudes (>=65 degrees).
//
// Reference: http://praytimes.org/calculation
func OneSeventhNight() HighLatitudeAdapter {
return highLatOneSeventhNight
}
func highLatOneSeventhNight(_ Config, _ int, schedules []Schedule) []Schedule {
for i, s := range schedules {
// Seventh night require Sunrise and Maghrib, and only done if Fajr or Isha missing
if !s.Sunrise.IsZero() && !s.Maghrib.IsZero() && (s.Fajr.IsZero() || s.Isha.IsZero()) {
// Calculate night duration
dayDuration := s.Maghrib.Sub(s.Sunrise).Seconds()
nightDuration := float64(24*60*60) - dayDuration
// Calculate Fajr and Isha time
seventhDuration := time.Duration(nightDuration / 7 * float64(time.Second))
schedules[i].Fajr = s.Sunrise.Add(-seventhDuration)
schedules[i].Isha = s.Maghrib.Add(seventhDuration)
}
}
return schedules
}