diff --git a/pkg/scrobblerlog/parser.go b/pkg/scrobblerlog/parser.go index 9c6471c..d355c62 100644 --- a/pkg/scrobblerlog/parser.go +++ b/pkg/scrobblerlog/parser.go @@ -247,7 +247,8 @@ func (l ScrobblerLog) rowToRecord(row []string) (Record, error) { // Convert a Unix timestamp to a [time.Time] object, but treat the timestamp // as being in the given location's timezone instead of UTC. -// If location is nil, the timestamp is returned as UTC. +// If location is nil, the timestamp is returned assumed to already be in UTC +// and returned unchanged. func timeFromLocalTimestamp(timestamp int64, location *time.Location) time.Time { t := time.Unix(timestamp, 0) @@ -256,7 +257,7 @@ func timeFromLocalTimestamp(timestamp int64, location *time.Location) time.Time if location != nil { _, offset := t.In(location).Zone() if offset != 0 { - t = t.Add(time.Duration(offset) * time.Second) + t = t.Add(-time.Duration(offset) * time.Second) } } diff --git a/pkg/scrobblerlog/parser_test.go b/pkg/scrobblerlog/parser_test.go index f4527cc..8dc30e5 100644 --- a/pkg/scrobblerlog/parser_test.go +++ b/pkg/scrobblerlog/parser_test.go @@ -91,7 +91,7 @@ func TestParserFallbackTimezone(t *testing.T) { require.NoError(t, err) record1 := result.Records[0] assert.Equal( - time.Unix(1260342084, 0).Add(2*time.Hour), + time.Unix(1260342084, 0).Add(-2*time.Hour), record1.Timestamp, ) }