sunrise

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 2 Imported by: 8

README

go-sunrise

Build Status Coverage Status Go Report Card GoDoc MIT License

Go package for calculating the sunrise and sunset times for a given location based on this method.

Usage

To calculate sunrise and sunset times, you will need the following information:

  • the date for which you wish to calculate the times
  • the latitude and longitudinal coordinates of the location

Begin by importing the package:

import "github.com/nathan-osman/go-sunrise"

Next, feed the information into the SunriseSunset() method:

rise, set := sunrise.SunriseSunset(
    43.65, -79.38,          // Toronto, CA
    2000, time.January, 1,  // 2000-01-01
)

The two return values will be the sunrise and sunset times for the location on the given day as time.Time values. If sun does not rise or set, both return values will be time.Time{}.

Documentation

Index

Constants

View Source
const (
	// Degree provides a precise fraction for converting between degrees and
	// radians.
	Degree = math.Pi / 180

	// J2000 is the Julian date for January 1, 2000, 12:00:00 TT.
	J2000 = 2451545
)
View Source
const DefaultPlaces = 5

DefaultPlaces specifies the default precision for rounding.

Variables

This section is empty.

Functions

func ArgumentOfPerihelion

func ArgumentOfPerihelion(d float64) float64

ArgumentOfPerihelion calculates the argument of periapsis for the earth on the given Julian day.

func Declination

func Declination(eclipticLongitude float64) float64

Declination calculates one of the two angles required to locate a point on the celestial sphere in the equatorial coordinate system. The ecliptic longitude parameter must be in degrees.

func EclipticLongitude

func EclipticLongitude(solarAnomaly, equationOfCenter, d float64) float64

EclipticLongitude calculates the angular distance of the earth along the ecliptic.

func EquationOfCenter

func EquationOfCenter(solarAnomaly float64) float64

EquationOfCenter calculates the angular difference between the position of the earth in its elliptical orbit and the position it would occupy in a circular orbit for the given mean anomaly.

func HourAngle

func HourAngle(latitude, declination float64) float64

HourAngle calculates the second of the two angles required to locate a point on the celestial sphere in the equatorial coordinate system.

func JulianDayToTime

func JulianDayToTime(d float64) time.Time

JulianDayToTime converts a Julian day into a time.Time.

func MeanSolarNoon

func MeanSolarNoon(longitude float64, year int, month time.Month, day int) float64

MeanSolarNoon calculates the time at which the sun is at its highest altitude. The returned time is in Julian days.

func Round

func Round(f float64, places int) float64

Round takes the provided float and rounds it to the specified number of decimal places. This function is adapted from user korya on GitHub (https://gist.github.com/DavidVaini/10308388#gistcomment-1391788).

func SolarMeanAnomaly

func SolarMeanAnomaly(d float64) float64

SolarMeanAnomaly calculates the angle of the sun relative to the earth for the specified Julian day.

func SolarTransit

func SolarTransit(d, solarAnomaly, eclipticLongitude float64) float64

SolarTransit calculates the Julian data for the local true solar transit.

func SunriseSunset

func SunriseSunset(latitude, longitude float64, year int, month time.Month, day int) (time.Time, time.Time)

SunriseSunset calculates when the sun will rise and when it will set on the given day at the specified location. Returns time.Time{} if there sun does not rise or set

func TimeToJulianDay

func TimeToJulianDay(t time.Time) float64

TimeToJulianDay converts a time.Time into a Julian day.

Types

This section is empty.

Jump to

Keyboard shortcuts

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