about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--defaults.toml2
-rw-r--r--internal/config/config.go27
-rw-r--r--searchix.go2
3 files changed, 27 insertions, 4 deletions
diff --git a/defaults.toml b/defaults.toml
index da3eb4f..9b5760d 100644
--- a/defaults.toml
+++ b/defaults.toml
@@ -47,7 +47,7 @@ x-content-type-options = 'nosniff'
 
 [Importer]
 Timeout = '30m0s'
-UpdateAt = 04:00:00
+UpdateAt = '04:00:00'
 
 [Importer.Sources]
 [Importer.Sources.darwin]
diff --git a/internal/config/config.go b/internal/config/config.go
index 3947d18..9ab7ab5 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -62,7 +62,30 @@ func mustURL(in string) (u URL) {
 	return u
 }
 
-func mustLocalTime(in string) (time toml.LocalTime) {
+// this type is necessary as nix's `fromTOML` doesn't support TOML date/time formats
+type LocalTime struct {
+	toml.LocalTime
+}
+
+func (t *LocalTime) MarshalText() ([]byte, error) {
+	b, err := t.LocalTime.MarshalText()
+	if err != nil {
+		return nil, errors.WithMessage(err, "could not marshal time value")
+	}
+
+	return b, nil
+}
+
+func (t *LocalTime) UnmarshalText(in []byte) (err error) {
+	err = t.LocalTime.UnmarshalText(in)
+	if err != nil {
+		return errors.WithMessage(err, "could not parse time value")
+	}
+
+	return nil
+}
+
+func mustLocalTime(in string) (time LocalTime) {
 	err := time.UnmarshalText([]byte(in))
 	if err != nil {
 		panic(errors.Errorf("Could not parse time: %s", in))
@@ -85,7 +108,7 @@ type Web struct {
 type Importer struct {
 	Sources  map[string]*Source
 	Timeout  Duration
-	UpdateAt toml.LocalTime
+	UpdateAt LocalTime
 }
 
 type Config struct {
diff --git a/searchix.go b/searchix.go
index 605db55..26c8148 100644
--- a/searchix.go
+++ b/searchix.go
@@ -184,7 +184,7 @@ func main() {
 				Timezone:      time.Local.String(),
 			}
 
-			nextRun := nextOccurrenceOfLocalTime(cfg.Importer.UpdateAt)
+			nextRun := nextOccurrenceOfLocalTime(cfg.Importer.UpdateAt.LocalTime)
 			for {
 				slog.Debug("scheduling next run", "next-run", nextRun)
 				<-time.After(time.Until(nextRun))