Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
/ go-nighttime Public archive

Go package for flight night time calculation

License

Notifications You must be signed in to change notification settings

vsimakhin/go-nighttime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arhived

The repository is archived. For the flight night-time calculation check https://github.com/vsimakhin/web-logbook/blob/main/internal/nighttime/nighttime.go

General

It's a simplified way to calculate where/what time an airplane and the sun can meet. It doesn't compensate for sunset/sunrise times for airplane altitude.

The logic is simple. It finds a midpoint on the route, checks the time when the airplane will be there and compares it with sunset/sunrise at this point. If the difference is too big it takes the front/rear part of the route and checks the midpoint again and again...

Known issues

It will not properly calculate a night time if the departure is before sunset and the arrival is after sunrise

Usage

package main

import (
	nighttime "github.com/vsimakhin/go-nighttime"
	"time"
	"fmt"
)

func main() {

	// flight from EBBR to LKPR
	route := nighttime.Route{
		Departure: nighttime.Place{
			Lat:  50.9014015198,
			Lon:  4.4844398499,
			Time: time.Date(2022, 6, 3, 18, 53, 0, 0, time.UTC),
		},
		Arrival: nighttime.Place{
			Lat:  50.1007995605,
			Lon:  14.2600002289,
			Time: time.Date(2022, 6, 3, 20, 16, 0, 0, time.UTC),
		},
	}

	fmt.Println("Flight time:", route.FlightTime())
	fmt.Println("Distance (nm):", route.Distance())
	fmt.Println("Night time:", route.NightTime())
}
$ go run main.go
Flight time: 1h23m0s
Distance (nm): 376.5411972344908
Night time: 27m0s

Used modules