Comments (1)
I hit the same or a similar issue. My UTC offset is +2 and the sunrise/set times calculated by the library are one day behind what other sources say for my location (Hamburg, Germany). This is my test program:
package main
import (
"fmt"
"log"
"time"
"github.com/kelvins/sunrisesunset"
)
const (
Location = "Europe/Berlin"
Latitude = 53.536268
Longitude = 9.992086
// StartDate = "2018-01-01"
StartDate = "2021-09-18"
// EndDate = "2099-12-31"
EndDate = "2021-09-30"
)
func main() {
loc, err := time.LoadLocation(Location)
if err != nil {
log.Fatalf("Failed to load location %q: %v", Location, err)
}
start, err := time.ParseInLocation("2006-01-02", StartDate, loc)
if err != nil {
log.Fatalf("Failed to parse start date %q: %v", StartDate, err)
}
end, err := time.ParseInLocation("2006-01-02", EndDate, loc)
if err != nil {
log.Fatalf("Failed to parse end date %q: %v", EndDate, err)
}
for t := start; !t.After(end); t = t.AddDate(0, 0, 1) {
_, offset := t.Zone()
sunrise, sunset, err := sunrisesunset.GetSunriseSunset(Latitude, Longitude, float64(offset)/3600.0, t)
// If no error has occurred, print the results
if err == nil {
fmt.Printf("Sunrise @ %s: %s\n", t.Format("2006-01-02"), sunrise.Format("15:04:05")) // Sunrise: 06:11:44
fmt.Printf("Sunset @ %s : %s\n", t.Format("2006-01-02"), sunset.Format("15:04:05")) // Sunset: 18:14:27
} else {
fmt.Println(err)
}
}
}
which outputs
Sunrise @ 2021-09-18: 06:57:11
Sunset @ 2021-09-18 : 19:30:39
Sunrise @ 2021-09-19: 06:58:56
Sunset @ 2021-09-19 : 19:28:12
Sunrise @ 2021-09-20: 07:00:40 <-- example this should be the sunrise time of 2019-09-19 (Sunday)
Sunset @ 2021-09-20 : 19:25:45
Sunrise @ 2021-09-21: 07:02:26
Sunset @ 2021-09-21 : 19:23:17
Sunrise @ 2021-09-22: 07:04:11
Sunset @ 2021-09-22 : 19:20:50
Sunrise @ 2021-09-23: 07:05:56
Sunset @ 2021-09-23 : 19:18:23
Sunrise @ 2021-09-24: 07:07:41
Sunset @ 2021-09-24 : 19:15:56
Sunrise @ 2021-09-25: 07:09:27
Sunset @ 2021-09-25 : 19:13:28
Sunrise @ 2021-09-26: 07:11:13
Sunset @ 2021-09-26 : 19:11:01
Sunrise @ 2021-09-27: 07:12:59
Sunset @ 2021-09-27 : 19:08:35
Sunrise @ 2021-09-28: 07:14:45
Sunset @ 2021-09-28 : 19:06:08
Sunrise @ 2021-09-29: 07:16:32
Sunset @ 2021-09-29 : 19:03:41
Sunrise @ 2021-09-30: 07:18:18
Sunset @ 2021-09-30 : 19:01:15
I will simply add a day in my calculations to "fix" this, as in my case I don't need to worry about the location or UTC offset changing too much.
from sunrisesunset.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sunrisesunset.