From 6a3d20351b62a9fab7e15fcc8397c25f3461b749 Mon Sep 17 00:00:00 2001 From: rknizzle Date: Tue, 1 Jun 2021 17:11:26 -0400 Subject: [PATCH] Replace sorting in breakTime with loadAllRecordsSortedAscending - I realized that fs.RecordFilepaths already has a mechanism for sorting the record filenames by start time so I think its better to take advantage of that and use loadAllRecordsSortedAscending instead of sorting in breakTime() --- core/timetrace.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/timetrace.go b/core/timetrace.go index 2cdfa8f..784a578 100644 --- a/core/timetrace.go +++ b/core/timetrace.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "sort" "time" "github.com/dominikbraun/timetrace/config" @@ -138,16 +137,11 @@ func (t *Timetrace) Status() (*Report, error) { } func (t *Timetrace) breakTime(date time.Time) (time.Duration, error) { - records, err := t.loadAllRecords(date) + records, err := t.loadAllRecordsSortedAscending(date) if err != nil { return 0, err } - // sort the records by start time - sort.Slice(records, func(i, j int) bool { - return records[i].Start.Before(records[j].Start) - }) - // add up the time between records var breakTime time.Duration for i := 0; i < len(records)-1; i++ {