add todo.ID()

This commit is contained in:
Bel LaPointe
2022-03-23 09:42:21 -06:00
parent 939793bd3f
commit 814ae3ab23
2 changed files with 44 additions and 0 deletions

View File

@@ -1,7 +1,9 @@
package pttodo
import (
"encoding/base64"
"fmt"
"hash/crc32"
"time"
)
@@ -15,6 +17,18 @@ type Todo struct {
writeTS bool
}
func (todo Todo) ID() string {
hash := crc32.NewIEEE()
fmt.Fprintf(hash, "%d:%s", 0, todo.Todo)
fmt.Fprintf(hash, "%d:%s", 1, todo.Details)
fmt.Fprintf(hash, "%d:%s", 2, todo.Schedule)
fmt.Fprintf(hash, "%d:%s", 3, todo.Tags)
for i := range todo.Subtasks {
fmt.Fprintf(hash, "%d:%s", 4, todo.Subtasks[i].ID())
}
return base64.StdEncoding.EncodeToString(hash.Sum(nil))
}
func (todo Todo) Triggered() bool {
last := todo.TS
next, err := todo.Schedule.Next(last.time())