initial commit
This commit is contained in:
44
cmd/tpstate/sunCalculations.go
Normal file
44
cmd/tpstate/sunCalculations.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func nextSunriseSunsetTime(t time.Time) (time.Time, time.Time, error) {
|
||||
s := config.SunRiseSet
|
||||
|
||||
s.Date = t
|
||||
currentSR, currentSS, err := s.GetSunriseSunset()
|
||||
if err != nil {
|
||||
return time.Time{}, time.Time{}, err
|
||||
}
|
||||
|
||||
s.Date = t.Add(24 * time.Hour)
|
||||
nextSR, nextSS, err := s.GetSunriseSunset()
|
||||
if err != nil {
|
||||
return time.Time{}, time.Time{}, err
|
||||
}
|
||||
|
||||
var (
|
||||
nSR time.Time
|
||||
nSS time.Time
|
||||
)
|
||||
|
||||
if currentSR.After(t) {
|
||||
nSR = currentSR
|
||||
} else {
|
||||
nSR = nextSR
|
||||
}
|
||||
|
||||
if currentSS.After(t) {
|
||||
nSS = currentSS
|
||||
} else {
|
||||
nSS = nextSS
|
||||
}
|
||||
|
||||
log.Printf("[TRACE] Next calculated sunrise: %s\n", nSR.Format("2006-01-02 15:04:05"))
|
||||
log.Printf("[TRACE] Next calculated sunset : %s\n", nSS.Format("2006-01-02 15:04:05"))
|
||||
|
||||
return nSR, nSS, nil
|
||||
}
|
Reference in New Issue
Block a user