diff --git a/internal/db/period.go b/internal/db/period.go index f13d321..00c4886 100644 --- a/internal/db/period.go +++ b/internal/db/period.go @@ -57,11 +57,11 @@ const ( // and end will be 23:59:59 on Saturday at the end of the current week. // If opts.Year (or opts.Year + opts.Month) is provided, start and end will simply by the start and end times of that year/month. func ListenActivityOptsToTimes(opts ListenActivityOpts) (start, end time.Time) { - now := time.Now() loc := opts.Timezone if loc == nil { loc, _ = time.LoadLocation("UTC") } + now := time.Now().In(loc) // If Year (and optionally Month) are specified, use calendar boundaries if opts.Year != 0 { diff --git a/internal/db/psql/listen_activity.go b/internal/db/psql/listen_activity.go index 7a3a776..b2c7990 100644 --- a/internal/db/psql/listen_activity.go +++ b/internal/db/psql/listen_activity.go @@ -23,7 +23,7 @@ func (d *Psql) GetListenActivity(ctx context.Context, opts db.ListenActivityOpts var listenActivity []db.ListenActivityItem if opts.AlbumID > 0 { l.Debug().Msgf("Fetching listen activity for %d %s(s) from %v to %v for release group %d", - opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05"), t2.Format("Jan 02, 2006 15:04:05"), opts.AlbumID) + opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05 MST"), t2.Format("Jan 02, 2006 15:04:05 MST"), opts.AlbumID) rows, err := d.q.ListenActivityForRelease(ctx, repository.ListenActivityForReleaseParams{ Column1: opts.Timezone.String(), ListenedAt: t1, @@ -44,7 +44,7 @@ func (d *Psql) GetListenActivity(ctx context.Context, opts db.ListenActivityOpts l.Debug().Msgf("Database responded with %d steps", len(rows)) } else if opts.ArtistID > 0 { l.Debug().Msgf("Fetching listen activity for %d %s(s) from %v to %v for artist %d", - opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05"), t2.Format("Jan 02, 2006 15:04:05"), opts.ArtistID) + opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05 MST"), t2.Format("Jan 02, 2006 15:04:05 MST"), opts.ArtistID) rows, err := d.q.ListenActivityForArtist(ctx, repository.ListenActivityForArtistParams{ Column1: opts.Timezone.String(), ListenedAt: t1, @@ -65,7 +65,7 @@ func (d *Psql) GetListenActivity(ctx context.Context, opts db.ListenActivityOpts l.Debug().Msgf("Database responded with %d steps", len(rows)) } else if opts.TrackID > 0 { l.Debug().Msgf("Fetching listen activity for %d %s(s) from %v to %v for track %d", - opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05"), t2.Format("Jan 02, 2006 15:04:05"), opts.TrackID) + opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05 MST"), t2.Format("Jan 02, 2006 15:04:05 MST"), opts.TrackID) rows, err := d.q.ListenActivityForTrack(ctx, repository.ListenActivityForTrackParams{ Column1: opts.Timezone.String(), ListenedAt: t1, @@ -86,7 +86,7 @@ func (d *Psql) GetListenActivity(ctx context.Context, opts db.ListenActivityOpts l.Debug().Msgf("Database responded with %d steps", len(rows)) } else { l.Debug().Msgf("Fetching listen activity for %d %s(s) from %v to %v", - opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05"), t2.Format("Jan 02, 2006 15:04:05")) + opts.Range, opts.Step, t1.Format("Jan 02, 2006 15:04:05 MST"), t2.Format("Jan 02, 2006 15:04:05 MST")) rows, err := d.q.ListenActivity(ctx, repository.ListenActivityParams{ Column1: opts.Timezone.String(), ListenedAt: t1, diff --git a/internal/db/psql/listen_activity_test.go b/internal/db/psql/listen_activity_test.go index b2da07f..affc202 100644 --- a/internal/db/psql/listen_activity_test.go +++ b/internal/db/psql/listen_activity_test.go @@ -101,8 +101,8 @@ func TestListenActivity(t *testing.T) { (1, 1, NOW() - INTERVAL '2 months 1 day'), (1, 1, NOW() - INTERVAL '3 months 1 day'), (1, 2, NOW() - INTERVAL '1 month 1 day'), - (1, 2, NOW() - INTERVAL '1 hour'), - (1, 2, NOW() - INTERVAL '1 minute'), + (1, 2, NOW() - INTERVAL '1 second'), + (1, 2, NOW() - INTERVAL '2 seconds'), (1, 2, NOW() - INTERVAL '2 months 1 day')`) require.NoError(t, err)