Documentation ¶
Overview ¶
Package sunrise computes sunrises and sunsets using wikipedia article http://en.wikipedia.org/wiki/Sunrise_equation. Testing at my latitude and longitude in California shows that computed sunrises and sunsets can vary by as much as 2 minutes from those that NOAA reports at http://www.esrl.noaa.gov/gmd/grad/solcalc/sunrise.html.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Phase ¶
type Phase int
Phase indicates day or night.
func DayOrNight ¶
func DayOrNight(latitude, longitude float64, currentTime time.Time) ( dayOrNight Phase, start, end time.Time)
DayOrNight returns whether currentTime is day or night at the given location. start and end are the start and end of the current day or night. start and end are in the same timezone as currentTime. Latitude is postive for north and negative for south. Longitude is positive for east and negative for west.
type Sunrise ¶
type Sunrise struct {
// contains filtered or unexported fields
}
Sunrise gives sunrise and sunset times.
Example ¶
Show sunrise and sunset for first 5 days of June in LA
package main import ( "fmt" "github.com/keep94/sunrise" "time" ) func main() { var s sunrise.Sunrise // Start time is June 1, 2013 PST location, _ := time.LoadLocation("America/Los_Angeles") startTime := time.Date(2013, 6, 1, 0, 0, 0, 0, location) // Coordinates of LA are 34.05N 118.25W s.Around(34.05, -118.25, startTime) for s.Sunrise().Before(startTime) { s.AddDays(1) } formatStr := "Jan 2 15:04:05" for i := 0; i < 5; i++ { fmt.Printf("Sunrise: %s Sunset: %s\n", s.Sunrise().Format(formatStr), s.Sunset().Format(formatStr)) s.AddDays(1) } }
Output: Sunrise: Jun 1 05:44:01 Sunset: Jun 1 20:00:42 Sunrise: Jun 2 05:43:45 Sunset: Jun 2 20:01:17 Sunrise: Jun 3 05:43:30 Sunset: Jun 3 20:01:52 Sunrise: Jun 4 05:43:17 Sunset: Jun 4 20:02:25 Sunrise: Jun 5 05:43:05 Sunset: Jun 5 20:02:57
func (*Sunrise) AddDays ¶
AddDays computes the sunrise and sunset numDays after (or before if numDays is negative) the current sunrise and sunset at the same latitude and longitude.
func (*Sunrise) Around ¶
Around computes the sunrise and sunset times for latitude and longitude around currentTime. Generally, the computed sunrise will be no earlier than 24 hours before currentTime and the computed sunset will be no later than 24 hours after currentTime. However, these differences may exceed 24 hours on days with more than 23 hours of daylight. The latitude is positive for north and negative for south. Longitude is positive for east and negative for west.