2019-03-14 15:29:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2021-04-29 15:11:51 +00:00
|
|
|
"time"
|
2019-03-14 15:29:33 +00:00
|
|
|
"unicode"
|
2021-04-29 15:11:51 +00:00
|
|
|
|
|
|
|
todotxt "git.bullercodeworks.com/brian/go-todotxt"
|
2019-03-14 15:29:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func itoa(val int) string {
|
|
|
|
return strconv.Itoa(val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func atoi(val string) int {
|
|
|
|
return oatoi(val, -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func oatoi(val string, def int) int {
|
|
|
|
v, err := strconv.Atoi(val)
|
|
|
|
if err != nil {
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func isCombination(s1, s2 []string) bool {
|
|
|
|
if len(s1) != len(s2) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, v := range s1 {
|
|
|
|
var found bool
|
|
|
|
for _, vv := range s2 {
|
|
|
|
if v == vv {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// We split projects/contexts on spaces or commas
|
|
|
|
func splitFields(v string) []string {
|
|
|
|
f := func(c rune) bool {
|
|
|
|
return unicode.IsSpace(c) || c == ','
|
|
|
|
}
|
|
|
|
return strings.FieldsFunc(v, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tagsToSlice(v map[string]string) []string {
|
|
|
|
var ret []string
|
|
|
|
for k, v := range v {
|
|
|
|
ret = append(ret, k+":"+v)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func sliceToTags(v []string) map[string]string {
|
|
|
|
ret := make(map[string]string)
|
|
|
|
for _, vv := range v {
|
|
|
|
tags := strings.Split(vv, ":")
|
|
|
|
if len(tags) == 2 {
|
|
|
|
ret[tags[0]] = tags[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func sliceIsValidTags(v []string) bool {
|
|
|
|
for _, vv := range v {
|
|
|
|
if len(strings.Split(vv, ":")) != 2 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2021-04-29 15:11:51 +00:00
|
|
|
|
|
|
|
func copyTaskList(t todotxt.TaskList) todotxt.TaskList {
|
|
|
|
re := todotxt.NewTaskList()
|
|
|
|
for _, v := range t {
|
|
|
|
re.AddTask(&v)
|
|
|
|
}
|
|
|
|
return *re
|
|
|
|
}
|
|
|
|
|
|
|
|
func dateWithinNextDay(d time.Time) bool {
|
|
|
|
return !d.IsZero() && d.Before(time.Now().Add(time.Hour*24))
|
|
|
|
}
|