-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexamples_test.go
140 lines (117 loc) · 4.53 KB
/
examples_test.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// get today's sunlight times for London
package suncalc_test
import (
"fmt"
"math"
"time"
"github.com/sixdouglas/suncalc"
)
func ExampleGetTimes() {
var now = time.Date(2005, 6, 1, 12, 0, 0, 0, time.UTC)
// Location to query for
lat, long := 51.5, -0.1
// get the times for today, latitude, longitude, height below or above the
// horizon, and in timezone
var times = suncalc.GetTimes(now, lat, long)
for _, timeOfDay := range suncalc.DayTimeNames {
oneTime := times[timeOfDay]
if !oneTime.Value.IsZero() {
fmt.Printf("%-13s %s\n", string(oneTime.Name),
oneTime.Value.Format("2006-01-02 15:04:05"))
}
}
// format sunrise time from the Date object
fmt.Printf("Sunrise / Sunset time: %s / %s\n",
times[suncalc.Sunrise].Value.Format("15:04:05"),
times[suncalc.Sunset].Value.Format("15:04:05"),
)
// get position of the sun (azimuth and altitude) at today's sunrise
var sunrisePos = suncalc.GetPosition(times[suncalc.Sunrise].Value, lat, long)
// get sunrise azimuth in degrees
var sunriseAzimuth = sunrisePos.Azimuth * 180 / math.Pi
fmt.Printf("Sunrise Azimuth: %f deg\n", sunriseAzimuth)
// get position of the sun (azimuth and altitude) at today's sunset
var sunsetPos = suncalc.GetPosition(times[suncalc.Sunset].Value, lat, long)
// get the sunset azimuth in degrees
var sunsetAzimuth = sunsetPos.Azimuth * 180 / math.Pi
fmt.Printf("Sunset Azimuth: %f deg\n", sunsetAzimuth)
// get current position of the sun (azimuth and altitude) at today's sunrise
var sunPos = suncalc.GetPosition(now, lat, long)
fmt.Printf("Sun Azimuth: %f deg\n", sunPos.Azimuth*180/math.Pi)
fmt.Printf("Sun Altitude: %f deg\n", sunPos.Altitude*180/math.Pi)
// Output:
// nauticalDawn 2005-06-01 01:57:31
// dawn 2005-06-01 03:04:43
// sunrise 2005-06-01 03:50:12
// sunriseEnd 2005-06-01 03:54:33
// goldenHourEnd 2005-06-01 04:42:52
// goldenHour 2005-06-01 19:16:35
// sunsetStart 2005-06-01 20:04:54
// sunset 2005-06-01 20:09:15
// dusk 2005-06-01 20:54:44
// nauticalDusk 2005-06-01 22:01:56
// Sunrise / Sunset time: 03:50:12 / 20:09:15
// Sunrise Azimuth: -128.374196 deg
// Sunset Azimuth: 128.610491 deg
// Sun Azimuth: 0.351955 deg
// Sun Altitude: 60.593709 deg
}
func ExampleGetTimesWithObserver() {
var now = time.Date(2012, 12, 12, 12, 0, 0, 0, time.UTC)
// Use time.Now() for today
// Location to query for
lat, long := 51.5, -0.1
// get the times for today, latitude, longitude, height below or above the
// horizon, and in timezone
var observer = suncalc.Observer{
Latitude: lat,
Longitude: long,
Height: 0,
Location: time.UTC,
}
var times = suncalc.GetTimesWithObserver(now, observer)
for _, timeOfDay := range suncalc.DayTimeNames {
oneTime := times[timeOfDay]
if !oneTime.Value.IsZero() {
fmt.Printf("%-13s %s\n", string(oneTime.Name),
oneTime.Value.Format("2006-01-02 15:04:05"))
}
}
// format sunrise time from the Date object
fmt.Printf("Sunrise / Sunset time: %s / %s\n",
times[suncalc.Sunrise].Value.Format("15:04:05"),
times[suncalc.Sunset].Value.Format("15:04:05"),
)
// get position of the sun (azimuth and altitude) at today's sunrise
var sunrisePos = suncalc.GetPosition(times[suncalc.Sunrise].Value, lat, long)
// get sunrise azimuth in degrees
var sunriseAzimuth = sunrisePos.Azimuth * 180 / math.Pi
fmt.Printf("Sunrise Azimuth: %f deg\n", sunriseAzimuth)
// get position of the sun (azimuth and altitude) at today's sunset
var sunsetPos = suncalc.GetPosition(times[suncalc.Sunset].Value, lat, long)
// get the sunset azimuth in degrees
var sunsetAzimuth = sunsetPos.Azimuth * 180 / math.Pi
fmt.Printf("Sunset Azimuth: %f deg\n", sunsetAzimuth)
// get current position of the sun (azimuth and altitude) at today's sunrise
var sunPos = suncalc.GetPosition(now, lat, long)
fmt.Printf("Sun Azimuth: %f deg\n", sunPos.Azimuth*180/math.Pi)
fmt.Printf("Sun Altitude: %f deg\n", sunPos.Altitude*180/math.Pi)
// Output:
// nightEnd 2012-12-12 05:54:58
// nauticalDawn 2012-12-12 06:35:38
// dawn 2012-12-12 07:18:37
// sunrise 2012-12-12 07:58:39
// sunriseEnd 2012-12-12 08:03:00
// goldenHourEnd 2012-12-12 08:59:36
// goldenHour 2012-12-12 14:51:47
// sunsetStart 2012-12-12 15:48:23
// sunset 2012-12-12 15:52:45
// dusk 2012-12-12 16:32:47
// nauticalDusk 2012-12-12 17:15:46
// night 2012-12-12 17:56:26
// Sunrise / Sunset time: 07:58:39 / 15:52:45
// Sunrise Azimuth: -52.101764 deg
// Sunset Azimuth: 52.356679 deg
// Sun Azimuth: 1.187845 deg
// Sun Altitude: 15.381733 deg
}