first functional version

This commit is contained in:
2021-12-10 15:15:21 -06:00
parent 4278e622ce
commit c9ad2a10f5
5 changed files with 56 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"log"
"math"
"time"
)
@@ -25,25 +26,20 @@ func nextSunriseSunsetTime(t time.Time) (sunrise, sunset time.Time, err error) {
return time.Time{}, time.Time{}, err
}
var (
nSR time.Time
nSS time.Time
)
nSR := currentSR
nSS := currentSS
if currentSR.After(t) {
nSR = currentSR
} else {
if t.After(currentSR) {
nSR = nextSR
}
if currentSS.After(t) {
nSS = currentSS
} else {
if t.After(currentSS) {
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"))
log.Printf("[TRACE] Calculated Time: %s\n", t.Format(config.TimeFormat))
log.Printf("[TRACE] Next calculated sunrise: %s (%v)\n", nSR.Format(config.TimeFormat), math.Round(nSR.Sub(time.Now()).Seconds()))
log.Printf("[TRACE] Next calculated sunset : %s (%v)\n", nSS.Format(config.TimeFormat), math.Round(nSS.Sub(time.Now()).Seconds()))
return nSR, nSS, nil
}