feat: time-gated imports via cfg

This commit is contained in:
Gabe Farrell 2025-06-13 05:36:41 -04:00
parent 6d000d87e4
commit c14df8c2fb
6 changed files with 59 additions and 4 deletions

View file

@ -4,11 +4,13 @@ import (
"context"
"os"
"path"
"time"
"github.com/gabehf/koito/internal/cfg"
"github.com/gabehf/koito/internal/logger"
)
// runs after every importer
func finishImport(ctx context.Context, filename string, numImported int) error {
l := logger.FromContext(ctx)
_, err := os.Stat(path.Join(cfg.ConfigDir(), "import_complete"))
@ -27,3 +29,18 @@ func finishImport(ctx context.Context, filename string, numImported int) error {
}
return nil
}
// from https://stackoverflow.com/a/55093788 with modification to use cfg and check for zero values
func inImportTimeWindow(check time.Time) bool {
end, start := cfg.ImportWindow()
if start.IsZero() && end.IsZero() {
return true
}
if !start.IsZero() && end.IsZero() {
return !check.Before(start)
}
if start.IsZero() && !end.IsZero() {
return !check.After(end)
}
return !check.Before(start) && !check.After(end)
}