package diyanetcalc import ( "context" "errors" "fmt" "math" "time" "prayertimes/pkg/prayer" ) var errNotSupported = errors.New("not supported in calculation provider") type Provider struct{} func New() Provider { return Provider{} } func (Provider) SearchLocations(_ context.Context, _ string) ([]prayer.Location, error) { return nil, fmt.Errorf("failed to search locations: %w", errNotSupported) } func (Provider) Get(_ context.Context, _ string) (prayer.TimesResult, error) { return prayer.TimesResult{}, fmt.Errorf("failed to get prayer times by location id: %w", errNotSupported) } func (Provider) GetByCoords(_ context.Context, coords prayer.Coordinates) (prayer.TimesResult, error) { seq := CalculatePrayerTimes(CalculateParams{ Latitude: coords.Latitude, Longitude: coords.Longitude, StartingDay: time.Now().UTC().Truncate(24 * time.Hour), }) times := make([]prayer.Times, 0, daysToGenerate) for item := range seq { times = append(times, prayer.Times{ Date: item.Date, DateHijri: item.DateHijri, Fajr: item.Fajr, Sunrise: item.Sunrise, Dhuhr: item.Dhuhr, Asr: item.Asr, Sunset: item.Sunset, Maghrib: item.Maghrib, Isha: item.Isha, }) if len(times) == daysToGenerate { break } } return prayer.TimesResult{ Location: prayer.Location{ Latitude: coords.Latitude, Longitude: coords.Longitude, Timezone: fmt.Sprintf("UTC%+d", int(math.Round(coords.Longitude/degPerHour))), }, Times: times, }, nil }