Skip to content

Commit

Permalink
fixup! fix and log a bunch of issues; get to rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Jul 27, 2024
1 parent a7ba168 commit e442686
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions internal/model/suntimes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// TODO: find a home for this
package model

import (
"time"

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

type SuntimesProvider struct {
Latitude float64
Longitude float64
}

// SunTimes represents the sunrise and sunset times of a date.
type SunTimes struct {
Rise, Set Timestamp
}

// GetSunTimes returns the sunrise and sunset times for the receiver-date at
// the given location.
// Warning: slow (TODO)
func (p *SuntimesProvider) Get(d Date) SunTimes {

// calculate sunrise sunset (UTC)
sunriseTime, sunsetTime := sunrise.SunriseSunset(p.Latitude, p.Longitude, d.Year, time.Month(d.Month), d.Day)

// convert time to current location
sunriseTime = sunriseTime.In(time.Now().Location())
sunsetTime = sunsetTime.In(time.Now().Location())

// convert to suntimes
suntimes := SunTimes{
*NewTimestampFromGotime(sunriseTime),
*NewTimestampFromGotime(sunsetTime),
}

return suntimes
}

0 comments on commit e442686

Please sign in to comment.