-
Notifications
You must be signed in to change notification settings - Fork 4
/
tools_sun.go
78 lines (72 loc) · 1.72 KB
/
tools_sun.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
package novas
import "time"
// Computes the time of the start of spring in the given year.
func Spring(year int, precision time.Duration) Time {
t1 := Date(year, 3, 15, 0, 0, 0, 0, time.Local)
t2 := Time{Time: t1.AddDate(0, 0, 15)}
tt := Time{}
for t2.Sub(t1.Time) > precision {
tt.Time = t1.Add(t2.Sub(t1.Time) / 2)
if sun.App(tt).Dec > 0 {
t2.Time = tt.Time
} else {
t1.Time = tt.Time
}
}
return tt
}
// Computes the time of the start of summer in the given year.
func Summer(year int, precision time.Duration) Time {
t1 := Date(year, 6, 15, 0, 0, 0, 0, time.Local)
t2 := Time{Time: t1.AddDate(0, 0, 15)}
tt := Time{}
dec1 := sun.App(t1).Dec
dec2 := sun.App(t2).Dec
for t2.Sub(t1.Time) > precision {
tt.Time = t1.Add(t2.Sub(t1.Time) / 2)
dec := sun.App(tt).Dec
if dec1 < dec2 {
dec1 = dec
t1 = tt
} else {
dec2 = dec
t2 = tt
}
}
return tt
}
// Computes the time of the start of autumn in the given year.
func Autumn(year int, precision time.Duration) Time {
t1 := Date(year, 9, 15, 0, 0, 0, 0, time.Local)
t2 := Time{Time: t1.AddDate(0, 0, 15)}
tt := Time{}
for t2.Sub(t1.Time) > precision {
tt.Time = t1.Add(t2.Sub(t1.Time) / 2)
if sun.App(tt).Dec < 0 {
t2.Time = tt.Time
} else {
t1.Time = tt.Time
}
}
return tt
}
// Computes the time of the start of winter in the given year.
func Winter(year int, precision time.Duration) Time {
t1 := Date(year, 12, 15, 0, 0, 0, 0, time.Local)
t2 := Time{Time: t1.AddDate(0, 0, 15)}
tt := Time{}
dec1 := sun.App(t1).Dec
dec2 := sun.App(t2).Dec
for t2.Sub(t1.Time) > precision {
tt.Time = t1.Add(t2.Sub(t1.Time) / 2)
dec := sun.App(tt).Dec
if dec1 > dec2 {
dec1 = dec
t1 = tt
} else {
dec2 = dec
t2 = tt
}
}
return tt
}