scrobblerlog: fixed timezone offset calculation

The timezone offset must be substracted to get the actual time in UTC.
This commit is contained in:
Philipp Wolfer 2025-05-01 11:51:02 +02:00
parent 0a411fe2fa
commit e973e72bbe
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
2 changed files with 4 additions and 3 deletions

View file

@ -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)
}
}

View file

@ -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,
)
}