-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
122 lines (105 loc) · 2.51 KB
/
utils.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"math"
"time"
"github.com/mshafiee/swephgo"
)
/* general helpers */
func jdToUTC(jd *float64) time.Time {
year := make([]int, 1)
month := make([]int, 1)
day := make([]int, 1)
hour := make([]float64, 1)
swephgo.Revjul(*jd, swephgo.SeGregCal, year, month, day, hour)
h := int(hour[0])
m := int(60 * (hour[0] - float64(h)))
utc := time.Date(year[0], time.Month(month[0]), day[0], h, m, 0, 0, time.UTC)
return utc
}
func jdToLocal(jd *float64) time.Time {
utc := jdToUTC(jd)
return utc.In(location)
}
func julian(d time.Time) *float64 {
h := float64(d.Hour()) + float64(d.Minute())/60 + float64(d.Second())/3600
jd := swephgo.Julday(d.Year(), int(d.Month()), d.Day(), h, swephgo.SeGregCal)
return &jd
}
/* Begining of the Day */
func bod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, time.Local)
}
/* Noon of the Day */
func nod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 12, 0, 0, 0, time.Local)
}
func smallestSignedAngleBetween(x float64, y float64) float64 {
return math.Min(2.0*math.Pi-math.Abs(x-y), math.Abs(x-y))
}
func fixangle(a float64) float64 {
return (a - 360*math.Floor(a/360))
}
func rad2deg(r float64) float64 {
return (r * 180) / math.Pi
}
func deg2rad(d float64) float64 {
return (d * math.Pi) / 180
}
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
func binarySearch(start Moon, end Moon, fullMoon bool) Moon {
half := end.date.Sub(start.date).Seconds() / 2
mDate := start.date.Add(time.Second * time.Duration(half))
phase, _ := Phase(mDate, swephgo.SeMoon)
newStart := start
newEnd := end
middle := Moon{
date: mDate,
phase: phase,
}
if fullMoon {
if start.phase < end.phase {
newStart = middle
} else {
newEnd = middle
}
} else {
if end.phase < start.phase {
newStart = middle
} else {
newEnd = middle
}
}
if newEnd.date.Sub(newStart.date).Minutes() < 1.0 {
return newEnd
}
return binarySearch(newStart, newEnd, fullMoon)
}
func moonEmoji(icon string) string {
switch icon {
case "New Moon":
return ":new_moon:"
case "Waxing Crescent":
return ":waxing_crescent_moon:"
case "First Quarter":
return ":first_quarter_moon:"
case "Waxing Gibbous":
return ":waxing_gibbous_moon:"
case "Full Moon":
return ":full_moon:"
case "Waning Gibbous":
return ":waning_gibbous_moon:"
case "Third Quarter":
return ":last_quarter_moon:"
case "Waning Crescent":
return ":waning_crescent_moon:"
default:
return ":star:"
}
}