Skip to content

Commit

Permalink
Fix Y2K25 bug in magnetic declination function
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmab committed Dec 31, 2024
1 parent 97bfe80 commit 2600331
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/bearings/declination.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

var igrfData = igrf.New()
var stubDate = time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
var stubDate = time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)

// Declination returns the magnetic declination at the given point and time.
func Declination(p orb.Point, t time.Time) (unit.Angle, error) {
if 1900 > t.Year() || t.Year() > 2025 {
log.Warn().Time("date", t).Msg("year is outside IGRF model range, replacing with 2024")
if 1900 > t.Year() || t.Year() > stubDate.Year() {
log.Warn().Time("date", t).Msgf("year is outside IGRF model range, replacing with %d", stubDate.Year())
t = stubDate
}
field, err := igrfData.IGRF(p.Lat(), p.Lon(), 0, float64(t.Year())+float64(t.YearDay())/366)
Expand Down

0 comments on commit 2600331

Please sign in to comment.