From b63b85bd307795f8b730a5e24dbe779d31a2d47f Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 5 Oct 2023 10:57:28 -0500 Subject: [PATCH] Add 'LooksLike' function --- timer.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/timer.go b/timer.go index f6dfeb2..03b03bc 100644 --- a/timer.go +++ b/timer.go @@ -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 +}