sunrisesunset

package module
v0.0.0-...-4d545fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 3 Imported by: 31

README

⚠ This project is no longer being maintained ⚠

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

Sunrise Sunset Package

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

Documentation

Overview

Package sunrisesunset should be used to calculate the apparent sunrise and sunset based on the latitude, longitude, UTC offset and date. All calculations (formulas) were extracted from the Solar Calculation Details of the Earth System Research Laboratory: https://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSunriseSunset

func GetSunriseSunset(latitude float64, longitude float64, utcOffset float64, date time.Time) (sunrise time.Time, sunset time.Time, err error)

GetSunriseSunset function is responsible for calculate the apparent Sunrise and Sunset times. If some parameter is wrong it will return an error.

Types

type Parameters

type Parameters struct {
	Latitude  float64
	Longitude float64
	UtcOffset float64
	Date      time.Time
}

The Parameters struct can also be used to manipulate the data and get the sunrise and sunset

func (*Parameters) GetSunriseSunset

func (p *Parameters) GetSunriseSunset() (time.Time, time.Time, error)

Just call the 'general' GetSunriseSunset function and return the results

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL