Add 'LooksLike' function

This commit is contained in:
Brian Buller 2023-10-05 10:57:28 -05:00
parent 6ea3390313
commit b63b85bd30

View File

@ -224,3 +224,32 @@ func (timer *Timer) HasTag(name string) bool {
func (timer *Timer) GetTag(name string) string {
return timer.AdditionalTags[name]
}
// LooksLike returns true if the passed in timer looks like this
func (timer *Timer) LooksLike(tmr *Timer) bool {
if tmr.StartDate != timer.StartDate ||
tmr.FinishDate != timer.FinishDate ||
tmr.Finished != timer.Finished ||
tmr.Notes != timer.Notes ||
len(tmr.Projects) != len(timer.Projects) ||
len(tmr.Contexts) != len(timer.Contexts) ||
len(tmr.AdditionalTags) != len(timer.AdditionalTags) {
return false
}
for _, prj := range tmr.Projects {
if !timer.HasProject(prj) {
return false
}
}
for _, ctx := range tmr.Contexts {
if !timer.HasContext(ctx) {
return false
}
}
for key, val := range tmr.AdditionalTags {
if !timer.HasTag(key) || timer.GetTag(key) != val {
return false
}
}
return true
}