Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print more info when created record collides with others #174

Merged
merged 11 commits into from
Sep 12, 2021
2 changes: 1 addition & 1 deletion cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func createRecordCommand(t *core.Timetrace) *cobra.Command {
return
}
if collides {
out.Err("Record collides with other record!")
out.Warn(" start and end of the record should not overlap with others")
return
}

Expand Down
22 changes: 19 additions & 3 deletions core/timetrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/dominikbraun/timetrace/config"
"github.com/dominikbraun/timetrace/out"
)

const (
Expand Down Expand Up @@ -295,17 +296,32 @@ func (t *Timetrace) RecordCollides(toCheck Record) (bool, error) {
}

func collides(toCheck Record, allRecords []*Record) bool {
collide := false
for _, rec := range allRecords {
var project, end string
if rec.Project != nil {
project = rec.Project.Key
}
if rec.End != nil {
end = rec.End.String()
}

if rec.End != nil && rec.Start.Before(*toCheck.End) && rec.End.After(toCheck.Start) {
return true
defer out.Info("%v %v-%v", project, rec.Start.String(), end)
collide = true
}

if rec.End == nil && toCheck.End.After(rec.Start) {
return true
defer out.Info("%v %v-%v", project, rec.Start.String(), end)
collide = true
}
}

return false
if collide {
out.Err("collides with these records :")
}

return collide
}

// isBackFile checks if a given filename is a backup-file
Expand Down