Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Latest commit

 

History

History
83 lines (59 loc) · 3.9 KB

README.md

File metadata and controls

83 lines (59 loc) · 3.9 KB

⚠️ 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