scrobblerlog: Allow configuring fallback time zone

Fixes #6
This commit is contained in:
Philipp Wolfer 2025-04-29 10:05:40 +02:00
parent 0f4b04c641
commit ed191d2f15
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
5 changed files with 68 additions and 22 deletions

View file

@ -18,6 +18,7 @@ package scrobblerlog
import (
"bufio"
"fmt"
"os"
"sort"
"strings"
@ -34,6 +35,7 @@ type ScrobblerLogBackend struct {
includeSkipped bool
append bool
file *os.File
timezone *time.Location
log scrobblerlog.ScrobblerLog
}
@ -53,6 +55,10 @@ func (b *ScrobblerLogBackend) Options() []models.BackendOption {
Label: i18n.Tr("Append to file"),
Type: models.Bool,
Default: "true",
}, {
Name: "time-zone",
Label: i18n.Tr("Specify a time zone for the listen timestamps"),
Type: models.String,
}}
}
@ -60,6 +66,14 @@ func (b *ScrobblerLogBackend) InitConfig(config *config.ServiceConfig) error {
b.filePath = config.GetString("file-path")
b.includeSkipped = config.GetBool("include-skipped", false)
b.append = config.GetBool("append", true)
timezone := config.GetString("time-zone")
if timezone != "" {
location, err := time.LoadLocation(timezone)
if err != nil {
return fmt.Errorf("Invalid time-zone %q: %w", timezone, err)
}
b.log.FallbackTimezone = location
}
b.log = scrobblerlog.ScrobblerLog{
TZ: scrobblerlog.TZ_UTC,
Client: "Rockbox unknown $Revision$",