Documentation ¶
Overview ¶
Package sun provides solar time calculations.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Times ¶
Times returns the times for sun rise, solar noon and sun set for the given time and location based on the formulae provided by the NOAA.
See https://gml.noaa.gov/grad/solcalc/solareqns.PDF
Example ¶
package main import ( "fmt" "log" "time" "github.com/kortschak/sun" ) func main() { // Calculate solar times for Paris on 2021-07-30. loc, err := time.LoadLocation("CET") if err != nil { log.Fatal(err) } date := time.Date(2021, 7, 30, 12, 0, 0, 0, loc) rise, noon, set := sun.Times(date, 48.856614, 2.3522219) fmt.Printf("Sunrise: %v\nNoon: %v\nSunset: %v\n", rise, noon, set) }
Output: Sunrise: 2021-07-30 06:20:05 +0200 CEST Noon: 2021-07-30 13:57:09 +0200 CEST Sunset: 2021-07-30 21:34:13 +0200 CEST
Types ¶
type Parser ¶
type Parser struct { // CronParser is the parser used to handle // any non-solar cron specs. If it is nil // the standard github.com/robfig/cron/v3 // parser is used. CronParser cron.ScheduleParser }
Parser is a cron spec parser that handles solar event descriptors. These are
- @sunrise
- @noon
- @sunset
Each solar cron spec in in the form
@(sunrise|noon|sunset)([+-]duration)? lat lon
Example ¶
c := cron.New(cron.WithParser(sun.Parser{})) // Set a reminder to go for a walk each evening. _, err := c.AddFunc("@sunset-30m 48.856614 2.3522219", func() { fmt.Println("Take a walk along the Seine before sunset.") }) if err != nil { log.Fatal(err) } c.Start() select {}
Output:
type Schedule ¶
type Schedule struct { // Event is the event type being scheduled. Event Event // Offset is the relative time offset relative // to the solar-time event. Offset time.Duration // Lat and Lon are the latitude and longitude // for the scheduled event. Lat, Lon float64 // Location overrides the schedule location. Location *time.Location }
Schedule is a cron.Schedule that schedules solar-time events.
Click to show internal directories.
Click to hide internal directories.