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

Sunset time for a day changes as the time during that same day changes #2

Open
keep94 opened this issue Sep 7, 2013 · 1 comment
Open

Comments

@keep94
Copy link

keep94 commented Sep 7, 2013

Bear with me on this one. I am a perfectionist. I tested your library for Nov 2, 2013 as that is the last day of DST here in California. For my latitude and longitude, your library reports the next sunset after 0:00 Nov 2 as 18:09:04. I tried 18:00 Nov 2 and got a sunset of 18:08:20. I tried 18:08 Nov 2 and got a sunset of 18:08:17. So I increase the time during Nov 2, 2013 the sunset time changes by getting earlier!

Expected behavior:

For a particular latitude and longitude, the next sunset time should remain constant for all times between the previous sunset and that one.

@umpc
Copy link

umpc commented May 16, 2016

Workaround/Solution:

Instead of making the package do more than the basic calculations, if you need consistent output for each day, you can use the time at the beginning of the day, instead of the result of time.Now(), as the time argument:

package main

import (
        "fmt"
        "github.com/cpucycle/astrotime"
        "time"
)

const (
        Event = "sunrise"
        X, Y = float64(12.345), float64(-12.345)
)

func Bod(t time.Time) time.Time {
        yr, mth, day := t.Date()
        return time.Date(yr, mth, day, 0, 0, 0, 0, t.Location())
}

func main() {
        t := Bod(time.Now())

        switch Event {
        case "sunrise":
                fmt.Println(astrotime.CalcSunrise(t, Y, -X))
        case "sunset":
                fmt.Println(astrotime.CalcSunset(t, Y, -X))
        }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants