solar

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

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.

The wrapper preserves the historical API used throughout this repository (Calculate, SunTimes, IsNight) while delegating the underlying astronomical math to go-solar.

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 UTC time falls in the aeronautical definition of night: before the morning civil twilight begins, or after the evening civil twilight ends, at the supplied latitude and longitude.

Types

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, so any time on that day is considered "night".
  • Midnight sun (sun never sets): Sunrise is set to the start of the UTC day and Sunset to 23:59:59 UTC, so any time on that day is considered "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. Per ICAO Annex 2 / EU Regulation 2018/1976 the aeronautical definition of "night" is:

"the period between the end of evening civil twilight and the beginning
 of morning civil twilight or such other period between sunset and
 sunrise as may be prescribed by the appropriate authority."

Civil twilight is defined as the period during which the centre of the sun is between 0° and 6° below the horizon. Dawn marks the beginning of morning civil twilight; Dusk marks the end of evening civil twilight.

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 for the given date and location. These are the EASA "night" boundaries: any time between Dusk and the next day's Dawn is considered night.

Edge cases (polar night / midnight sun): when the sun is permanently below or above the civil-twilight threshold, go-solar returns the zero time for the affected boundary. We collapse those zero values to the start of the UTC day for Dawn and end of the UTC day for Dusk so that:

  • permanent polar night (no civil dawn or dusk): the entire UTC day is night;
  • midnight sun (sun stays above −6°): the entire UTC day is day.

Jump to

Keyboard shortcuts

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