diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-01 10:05:11 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-01 10:05:11 +0300 |
| commit | 74bcb110cba9cd22b88c561115e332d500de7716 (patch) | |
| tree | 080287b50ff69e2e601e5ab781da500a93c4b43c /internal/schedule/stats.go | |
| parent | cbdce79d25206573d1f79c9c647dcaa251b69463 (diff) | |
use of entry.Entry around the code base
Diffstat (limited to 'internal/schedule/stats.go')
| -rw-r--r-- | internal/schedule/stats.go | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go index b36fd54..e6b2b29 100644 --- a/internal/schedule/stats.go +++ b/internal/schedule/stats.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "codeberg.org/snonux/gos/internal/entry" "codeberg.org/snonux/gos/internal/format" "codeberg.org/snonux/gos/internal/oi" ) @@ -58,16 +59,16 @@ func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error { var errs []error for filePath := range ch { - entryTime, err := parseEntryPath(filePath) + ent, err := entry.New(filePath) if err != nil { errs = append(errs, err) continue } - if entryTime.Before(lookbackTime) { + if ent.Time.Before(lookbackTime) { continue } - if entryTime.Before(oldest) { - oldest = entryTime + if ent.Time.Before(oldest) { + oldest = ent.Time } s.posted++ } @@ -91,7 +92,8 @@ func (s *stats) gatherQueuedStats(dir string) error { errs []error ) for filePath := range ch { - if _, err := parseEntryPath(filePath); err != nil { + // Here, we only test whether we can parse the entry. + if _, err := entry.New(filePath); err != nil { errs = append(errs, err) continue } @@ -116,14 +118,3 @@ func nowTime() time.Time { func pastTime(duration time.Duration) time.Time { return nowTime().Add(-duration) } - -// TODO: Maybe introduce types.Entry struct, which encapsulates all the parsing -func parseEntryPath(filePath string) (time.Time, error) { - // Format: foobarbaz.something.here.txt.STAMP.{posted,queued} - // We want to get the STAMP! - parts := strings.Split(filePath, ".") - if len(parts) < 4 { - return time.Time{}, fmt.Errorf("not a valid entry path: %s", filePath) - } - return time.Parse(format.Time, parts[len(parts)-2]) -} |
