Skip to content

Commit

Permalink
Replace sorting in breakTime with loadAllRecordsSortedAscending
Browse files Browse the repository at this point in the history
	- 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()
  • Loading branch information
rknizzle committed Jun 3, 2021
1 parent 9b537a4 commit 6a3d203
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions core/timetrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"os"
"sort"
"time"

"github.com/dominikbraun/timetrace/config"
Expand Down Expand Up @@ -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++ {
Expand Down

0 comments on commit 6a3d203

Please sign in to comment.