pttodo/pttodo/todo.go

40 lines
823 B
Go

package pttodo
import (
"fmt"
"time"
)
type Todo struct {
Todo string
Detail string `yaml:",omitempty"`
TS TS `yaml:",omitempty"`
Schedule Schedule `yaml:",omitempty"`
Tags string `yaml:",omitempty"`
Subtasks []Todo `yaml:",omitempty"`
}
func (todo Todo) Triggered() bool {
last := todo.TS
next, err := todo.Schedule.Next(last.time())
return err == nil && time.Now().After(next)
}
func (todo Todo) MarshalYAML() (interface{}, error) {
if fmt.Sprint(todo) == fmt.Sprint(Todo{Todo: todo.Todo}) {
return todo.Todo, nil
}
type Alt Todo
return (Alt)(todo), nil
}
func (todo *Todo) UnmarshalYAML(unmarshal func(interface{}) error) error {
*todo = Todo{}
if err := unmarshal(&todo.Todo); err == nil {
return nil
}
type Alt Todo
alt := (*Alt)(todo)
return unmarshal(alt)
}