Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix longitude sign bug #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions astrotime.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// NAA - NOAA's Astronomical Algorithms
package astrotime

// (JavaScript web page
// (JavaScript web page
// http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html by
// Chris Cornwall, Aaron Horiuchi and Chris Lehman)
// Ported to C++ by Pete Gray ([email protected]), July 2006
// Released as Open Source and can be used in any way, as long as the
// Released as Open Source and can be used in any way, as long as the
// above description remains in place.

import (
Expand Down Expand Up @@ -306,10 +306,12 @@ func calcSunriseUTC(jd float64, latitude float64, longitude float64) float64 {
return timeUTC
}

// CalcSunrise calculates the sunrise, in local time, on the day t at the
// CalcSunrise calculates the sunrise, in local time, on the day t at the
// location specified in longitude and latitude.
// For why we flip the sign on longitude, see: http://www.esrl.noaa.gov/gmd/grad/solcalc/sunrise.html
func CalcSunrise(t time.Time, latitude float64, longitude float64) time.Time {
jd := CalcJD(t)
longitude = -longitude
sunriseUTC := time.Duration(math.Floor(calcSunriseUTC(jd, latitude, longitude)*60) * 1e9)
loc, _ := time.LoadLocation("UTC")
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc).Add(sunriseUTC).In(t.Location())
Expand Down Expand Up @@ -377,10 +379,12 @@ func calcSunsetUTC(jd float64, latitude float64, longitude float64) float64 {
return 720 + timeDiff - eqTime
}

// CalcSunset calculates the sunset, in local time, on the day t at the
// CalcSunset calculates the sunset, in local time, on the day t at the
// location specified in longitude and latitude.
// For why we flip the sign on longitude, see: http://www.esrl.noaa.gov/gmd/grad/solcalc/sunrise.html
func CalcSunset(t time.Time, latitude float64, longitude float64) time.Time {
jd := CalcJD(t)
longitude = -longitude
sunsetUTC := time.Duration(math.Floor(calcSunsetUTC(jd, latitude, longitude)*60) * 1e9)
loc, _ := time.LoadLocation("UTC")
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc).Add(sunsetUTC).In(t.Location())
Expand Down