fix: Return date as a string instead of local time

This commit is contained in:
2023-04-05 07:48:19 +02:00
parent 64a4814eef
commit ccc04dd9ee
6 changed files with 87 additions and 28 deletions
+8 -4
View File
@@ -73,17 +73,21 @@ func (d Provider) parseResponse(res *req.Response) ([]prayer.Times, error) {
return nil, fmt.Errorf("received error: %s", res.String())
}
if len(response.ResultObject.PrayerTimes) == 0 {
return nil, nil
}
var times []prayer.Times
const format = "15:04"
now := time.Now()
today := time.Now().UTC().Truncate(time.Hour * 24)
for _, pt := range response.ResultObject.PrayerTimes {
then := pt.Date.UTC().Truncate(time.Hour * 24)
if then.Before(now) {
then := prayer.Date(pt.Date).Time()
if then.Before(today) {
continue
}
times = append(times, prayer.Times{
Date: then,
Date: pt.Date.Format(time.DateOnly),
Fajr: pt.Fajr.Format(format),
Sunrise: pt.Sunrise.Format(format),
Dhuhr: pt.Dhuhr.Format(format),
+3 -1
View File
@@ -30,6 +30,8 @@ func TestDiyanetAPI_GetByCoords(t *testing.T) {
times, err := p.Get(context.Background(), "11104")
assert.NoError(t, err)
assert.NotEmpty(t, times)
t.Logf("%#+v", times[0])
for _, time := range times {
t.Log(time)
}
})
}