solar

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package solar provides a thin wrapper around github.com/mstephenholl/go-solar for computing sunrise/sunset and determining whether a given UTC instant is during daytime or nighttime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNight

func IsNight(t time.Time, latitude, longitude float64) bool

IsNight returns true if the given instant falls in the aeronautical definition of night at the supplied latitude and longitude: outside every civil-twilight day interval of the local solar days around t's UTC date.

Types

type Daylight added in v1.4.0

type Daylight []Interval

Daylight is a set of civil-twilight day intervals at one location.

func DaylightBetween added in v1.4.0

func DaylightBetween(from, to time.Time, latitude, longitude float64) Daylight

DaylightBetween returns the civil-twilight day intervals at the location for every UTC date from the day before from's date to the day after to's date. Every instant in [from, to] is day iff the result contains it.

func (Daylight) IsNight added in v1.4.0

func (d Daylight) IsNight(t time.Time) bool

IsNight reports whether t lies outside every interval in d.

type Interval added in v1.4.0

type Interval struct {
	Start time.Time
	End   time.Time
}

Interval is a closed UTC time range [Start, End].

func (Interval) Contains added in v1.4.0

func (iv Interval) Contains(t time.Time) bool

Contains reports whether t lies in [Start, End].

type SunTimes

type SunTimes struct {
	Sunrise time.Time
	Sunset  time.Time
}

SunTimes holds sunrise and sunset times for a given date and location.

func Calculate

func Calculate(date time.Time, latitude, longitude float64) SunTimes

Calculate computes sunrise and sunset UTC times for a given date, latitude, and longitude. Computation is delegated to github.com/mstephenholl/go-solar.

Edge cases:

  • Polar night (sun never rises): both Sunrise and Sunset are set to the start of the UTC day; the whole day counts as night.
  • Midnight sun (sun never sets): Sunrise is set to the start of the UTC day and Sunset to 23:59:59 UTC; the whole day counts as day.

type TwilightTimes added in v1.2.2

type TwilightTimes struct {
	Dawn time.Time // beginning of morning civil twilight (sun at -6° rising)
	Dusk time.Time // end of evening civil twilight (sun at -6° setting)
}

TwilightTimes holds the morning (Dawn) and evening (Dusk) civil twilight boundaries for a given UTC date and location.

func CivilTwilight added in v1.2.2

func CivilTwilight(date time.Time, latitude, longitude float64) TwilightTimes

CivilTwilight computes the morning-civil-twilight start (Dawn) and evening-civil-twilight end (Dusk) in UTC of the local solar day go-solar associates with the given UTC date; either may fall on an adjacent UTC date. Classify instants with IsNight or DaylightBetween, not with one pair.

Edge cases: polar night collapses the window to zero width at the start of the UTC day; midnight sun spans the whole UTC day.

Jump to

Keyboard shortcuts

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