fix: Return date as a string instead of local time
This commit is contained in:
@@ -42,18 +42,19 @@ func (p Provider) Name() string {
|
||||
|
||||
func (p Provider) Get(ctx context.Context, location string) ([]prayer.Times, error) {
|
||||
times, err := p.loadTimes(ctx, location)
|
||||
if err == nil && len(times) != 0 {
|
||||
return times, nil
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load prayer times from db: %w", err)
|
||||
}
|
||||
if len(times) > 0 {
|
||||
return times, nil
|
||||
}
|
||||
|
||||
times, err = p.provider.Get(ctx, location)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get prayer times: %w", err)
|
||||
}
|
||||
|
||||
if len(times) > 1 {
|
||||
if len(times) > 0 {
|
||||
if err := p.saveTimes(ctx, location, times); err != nil {
|
||||
return nil, fmt.Errorf("failed to save times to db: %w", err)
|
||||
}
|
||||
@@ -110,15 +111,15 @@ func Migrate(con *sql.DB) error {
|
||||
}
|
||||
|
||||
type prayerTimesRow struct {
|
||||
ProviderID int64 `db:"provider_id"`
|
||||
LocationID string `db:"location_id"`
|
||||
Date time.Time `db:"date"`
|
||||
Fajr string `db:"fajr"`
|
||||
Sunrise string `db:"sunrise"`
|
||||
Dhuhr string `db:"dhuhr"`
|
||||
Asr string `db:"asr"`
|
||||
Maghrib string `db:"maghrib"`
|
||||
Isha string `db:"isha"`
|
||||
ProviderID int64 `db:"provider_id"`
|
||||
LocationID string `db:"location_id"`
|
||||
Date string `db:"date"`
|
||||
Fajr string `db:"fajr"`
|
||||
Sunrise string `db:"sunrise"`
|
||||
Dhuhr string `db:"dhuhr"`
|
||||
Asr string `db:"asr"`
|
||||
Maghrib string `db:"maghrib"`
|
||||
Isha string `db:"isha"`
|
||||
}
|
||||
|
||||
func (r prayerTimesRow) toDomain() prayer.Times {
|
||||
@@ -166,7 +167,7 @@ func (p Provider) saveTimes(ctx context.Context, locationID string, times []pray
|
||||
|
||||
func (p Provider) loadTimes(ctx context.Context, locationID string) ([]prayer.Times, error) {
|
||||
now := p.clockFunc()
|
||||
today := now.Truncate(time.Hour * 24)
|
||||
today := now.UTC().Truncate(time.Hour * 24)
|
||||
|
||||
q := p.db.
|
||||
From(goqu.T("prayer_times").As("pt")).
|
||||
|
||||
Reference in New Issue
Block a user