Giter VIP home page Giter VIP logo

sunrisesunset's Introduction

⚠️ This project is no longer being maintained ⚠️

Consider using a forked version of this repository or another project like go-sunrise.

Sunrise Sunset Package

License: MIT Build Status Coverage Status Go Report Card

Go package used to calculate the apparent sunrise and sunset times based on latitude, longitude, date and UTC offset.

You can use go get command:

go get github.com/kelvins/sunrisesunset

General

This package was created based on the Corrected Sunrise, Sunset, Noon Times in Seconds - and Solar Angles Matlab function developed by Richard Droste, that was created based on the spreadsheets available in the Earth System Research Laboratory website from the National Oceanic & Atmospheric Administration (NOAA).

Based on the Solar Calculation Details:

The calculations in the NOAA Sunrise/Sunset and Solar Position Calculators are based on equations from Astronomical Algorithms, by Jean Meeus. The sunrise and sunset results are theoretically accurate to within a minute for locations between +/- 72° latitude, and within 10 minutes outside of those latitudes. However, due to variations in atmospheric composition, temperature, pressure and conditions, observed values may vary from calculations.

Apparent Sunrise/Sunset:

Due to atmospheric refraction, sunrise occurs shortly before the sun crosses above the horizon. Light from the sun is bent, or refracted, as it enters earth's atmosphere. See Apparent Sunrise Figure. This effect causes the apparent sunrise to be earlier than the actual sunrise. Similarly, apparent sunset occurs slightly later than actual sunset. The sunrise and sunset times reported in our calculator have been corrected for the approximate effects of atmospheric refraction. However, it should be noted that due to changes in air pressure, relative humidity, and other quantities, we cannot predict the exact effects of atmospheric refraction on sunrise and sunset time. Also note that this possible error increases with higher (closer to the poles) latitudes.

Usage

package main

import (
    "fmt"
    "time"
    "github.com/kelvins/sunrisesunset"
)

func main() {
    // You can use the Parameters structure to set the parameters
    p := sunrisesunset.Parameters{
      Latitude:  -23.545570,
      Longitude: -46.704082,
      UtcOffset: -3.0,
      Date:      time.Date(2017, 3, 23, 0, 0, 0, 0, time.UTC),
    }

    // Calculate the sunrise and sunset times
    sunrise, sunset, err := p.GetSunriseSunset()

    // If no error has occurred, print the results
    if err == nil {
        fmt.Println("Sunrise:", sunrise.Format("15:04:05")) // Sunrise: 06:11:44
        fmt.Println("Sunset:", sunset.Format("15:04:05")) // Sunset: 18:14:27
    } else {
        fmt.Println(err)
    }
}

License

This project was created under the MIT license

sunrisesunset's People

Contributors

kelvins avatar lukasschwab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sunrisesunset's Issues

Consider adding execution time info to README.md

This library seems to be doing some quite a lot of calculations.
In a raspberrypi 4 it takes around 7 seconds to calculate the sunrise and sunset. My initial expectations was that it would only take a few ms and only noticed a few days later.

Maybe there should be a line in the readme like:
Calculating the sunrise and sunset can take a few seconds to calculate on most computers. You might want to plan your code accordingly.

sunrise for lat/lon in UTC+8 erroneosuly set to 00:00:00 UTC (should be on previous day)

Couldn't think of a title to accurately sum up the issue, but the problem here is that in UTC+8, when running the sample program with a UTC offset of 0, I get

Sunrise: 00:00:00
Sunset: 11:08:43

But this is wrong, the sunrise should be on the previous day actually in UTC, as when I set the timzeone offset to 8, I get

Sunrise: 07:00:40
Sunset: 19:08:43

and this is confirmed to be correct by other sources.

I'm using a program that uses your library, which does all its calculations in UTC, and therefore, my sunrise times are always wrong.

I took a quick look at the code but it's a bit much to process, and I decided to open an issue instead of just tackling it myself in case the solution was easy for you.

Sunrise and sunset generated times

The generated times by GetSunriseSunset are have the year, month, and day set to 1, which is faulty because when using it, generation of a custom date needs to occur, such as comparison between the three dates to be possible.

Failures for coordinates in Australia and Japan (at least)

It would appear that the library fails to calculate correct times for locations in Australia and Japan, though there may be others. I added the following to the tTests struct on line 59 of the sunrisesunset_test.go file:

{-37.849601165270194, 144.97009872662463, -5.0, date, time.Date(2017, 3, 23, 7, 26, 34, 0, time.UTC), time.Date(2017, 3, 23, 19, 41, 07, 0, time.UTC)}, // Melbourne - Australia

This results in the following failure:

--- FAIL: TestGetSunriseSunset (0.33s)
    /home/sknick/Source/github.com/kelvins/sunrisesunset/sunrisesunset_test.go:85: Expected:  2017-03-23 07:26:34 +0000 UTC Received:  2017-03-23 00:00:00 +0000 UTC
    /home/sknick/Source/github.com/kelvins/sunrisesunset/sunrisesunset_test.go:91: Expected:  2017-03-23 19:41:07 +0000 UTC Received:  2017-03-23 03:27:17 +0000 UTC
    /home/sknick/Source/github.com/kelvins/sunrisesunset/sunrisesunset_test.go:113: Expected:  2017-03-23 07:26:34 +0000 UTC Received:  2017-03-23 00:00:00 +0000 UTC
    /home/sknick/Source/github.com/kelvins/sunrisesunset/sunrisesunset_test.go:119: Expected:  2017-03-23 19:41:07 +0000 UTC Received:  2017-03-23 03:27:17 +0000 UTC
FAIL

I realize my expected values aren't accurate, but you can see that the library is just returning 00:00:00.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.