mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-09 18:07:03 +02:00
scrobblerlog: fixed timezone offset calculation
The timezone offset must be substracted to get the actual time in UTC.
This commit is contained in:
parent
0a411fe2fa
commit
e973e72bbe
2 changed files with 4 additions and 3 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue