Add 'LooksLike' function
This commit is contained in:
parent
6ea3390313
commit
b63b85bd30
29
timer.go
29
timer.go
@ -224,3 +224,32 @@ func (timer *Timer) HasTag(name string) bool {
|
|||||||
func (timer *Timer) GetTag(name string) string {
|
func (timer *Timer) GetTag(name string) string {
|
||||||
return timer.AdditionalTags[name]
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user