[WIP] Task editing

This commit is contained in:
Martin
2024-05-29 19:47:57 +02:00
parent 5d930685a3
commit 5d70a248dc
11 changed files with 1077 additions and 355 deletions

View File

@ -197,6 +197,30 @@ func (t *Task) GetDate(dateString string) time.Time {
return dt
}
func (t *Task) HasTag(tag string) bool {
for _, t := range t.Tags {
if t == tag {
return true
}
}
return false
}
func (t *Task) AddTag(tag string) {
if !t.HasTag(tag) {
t.Tags = append(t.Tags, tag)
}
}
func (t *Task) RemoveTag(tag string) {
for i, ttag := range t.Tags {
if ttag == tag {
t.Tags = append(t.Tags[:i], t.Tags[i+1:]...)
return
}
}
}
type Tasks []*Task
type Context struct {
@ -291,3 +315,97 @@ func parseCountdown(d time.Duration) string {
return fmt.Sprintf("%d:%02d:%02d", hours, minutes, seconds)
}
var (
dateFormats = []string{
"2006-01-02",
"2006-01-02T15:04",
"20060102T150405Z",
}
specialDateFormats = []string{
"",
"now",
"today",
"sod",
"eod",
"yesterday",
"tomorrow",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
"mon",
"tue",
"wed",
"thu",
"fri",
"sat",
"sun",
"soy",
"eoy",
"soq",
"eoq",
"som",
"eom",
"socm",
"eocm",
"sow",
"eow",
"socw",
"eocw",
"soww",
"eoww",
"1st",
"2nd",
"3rd",
"4th",
"5th",
"6th",
"7th",
"8th",
"9th",
"10th",
"11th",
"12th",
"13th",
"14th",
"15th",
"16th",
"17th",
"18th",
"19th",
"20th",
"21st",
"22nd",
"23rd",
"24th",
"25th",
"26th",
"27th",
"28th",
"29th",
"30th",
"31st",
}
)
func ValidateDate(s string) error {
for _, f := range dateFormats {
if _, err := time.Parse(f, s); err == nil {
return nil
}
}
for _, f := range specialDateFormats {
if s == f {
return nil
}
}
return fmt.Errorf("invalid date")
}