feat: Rewrite to use the Diyanet API

This commit is contained in:
2026-02-21 01:50:59 +03:00
parent 43d4560fbb
commit 73316d4e62
17 changed files with 637 additions and 9198 deletions
+15 -68
View File
@@ -1,85 +1,32 @@
package prayer
import (
"context"
"database/sql/driver"
"encoding/json"
"errors"
"time"
)
var ErrInvalidLocation = errors.New("invalid location")
type TimesProvider interface {
Get(ctx context.Context, location string) ([]Times, error)
Name() string
}
type Coordinates struct {
Latitude float64
Longitude float64
}
type LocationTimesProvider interface {
GetByCoords(ctx context.Context, coords Coordinates) ([]Times, error)
Name() string
}
type Date time.Time
func (d Date) String() string {
return time.Time(d).Format(time.DateOnly)
}
func (d *Date) Scan(src any) error {
switch v := src.(type) {
case []byte:
return json.Unmarshal(v, d)
case string:
return json.Unmarshal([]byte(v), d)
case time.Time:
*d = Date(v)
return nil
}
return nil
}
func (d *Date) Value() (driver.Value, error) {
return json.Marshal(d)
}
func (d *Date) UnmarshalJSON(bytes []byte) error {
var t time.Time
if err := json.Unmarshal(bytes, &t); err != nil {
return err
}
_, offset := t.Zone()
t = t.Add(time.Duration(offset * int(time.Second)))
t = t.UTC()
*d = Date(t)
return nil
}
func (d Date) MarshalJSON() ([]byte, error) {
t := time.Time(d)
return json.Marshal(t.Format(time.DateOnly))
}
func (d Date) Time() time.Time {
t := time.Time(d)
_, offset := t.Zone()
t = t.Add(time.Duration(offset * int(time.Second)))
t = t.UTC()
return t
type Location struct {
ID int `json:"id"`
NameTR string `json:"name_tr"`
NameEN string `json:"name_en"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
type Times struct {
Date string `json:"date"`
Fajr string `json:"fajr"`
Sunrise string `json:"sunrise"`
Dhuhr string `json:"dhuhr"`
Asr string `json:"asr"`
Maghrib string `json:"maghrib"`
Isha string `json:"isha"`
Date string `json:"date"`
DateIslamic string `json:"date_islamic,omitempty"`
Fajr string `json:"fajr"`
Sunrise string `json:"sunrise"`
Dhuhr string `json:"dhuhr"`
Asr string `json:"asr"`
Sunset string `json:"sunset,omitempty"`
Maghrib string `json:"maghrib"`
Isha string `json:"isha"`
}