119 lines
2.4 KiB
Go
119 lines
2.4 KiB
Go
package taskwarrior
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Task struct {
|
|
Id int64 `json:"id"`
|
|
Uuid string `json:"uuid"`
|
|
Description string `json:"description"`
|
|
Project string `json:"project"`
|
|
Priority string `json:"priority"`
|
|
Status string `json:"status"`
|
|
Tags []string `json:"tags"`
|
|
Depends []string `json:"depends"`
|
|
Urgency float32 `json:"urgency"`
|
|
Due string `json:"due"`
|
|
Wait string `json:"wait"`
|
|
Scheduled string `json:"scheduled"`
|
|
Until string `json:"until"`
|
|
Recur string `json:"recur"`
|
|
Start string `json:"start"`
|
|
End string `json:"end"`
|
|
Entry string `json:"entry"`
|
|
Modified string `json:"modified"`
|
|
Parent string `json:"parent"`
|
|
}
|
|
|
|
func (t *Task) Get(field string) string {
|
|
switch field {
|
|
case "id":
|
|
return strconv.FormatInt(t.Id, 10)
|
|
case "uuid":
|
|
return t.Uuid
|
|
case "description":
|
|
return t.Description
|
|
case "project":
|
|
return t.Project
|
|
case "priority":
|
|
return t.Priority
|
|
case "status":
|
|
return t.Status
|
|
case "tags":
|
|
return strings.Join(t.Tags, ", ")
|
|
case "urgency":
|
|
return fmt.Sprintf("%.2f", t.Urgency)
|
|
case "due":
|
|
return t.Due
|
|
case "wait":
|
|
return t.Wait
|
|
case "scheduled":
|
|
return t.Scheduled
|
|
case "end":
|
|
return t.End
|
|
case "entry":
|
|
return t.Entry
|
|
case "modified":
|
|
return t.Modified
|
|
// TODO: implement these fields
|
|
case "start.age":
|
|
return formatTime(t.Start)
|
|
case "depends":
|
|
return strings.Join(t.Depends, ", ")
|
|
case "entry.age":
|
|
return formatTime(t.Entry)
|
|
case "scheduled.countdown":
|
|
return formatTime(t.Scheduled)
|
|
case "until.remaining":
|
|
return formatTime(t.Until)
|
|
case "due.relative":
|
|
return formatTime(t.Due)
|
|
case "recur":
|
|
return t.Recur
|
|
default:
|
|
slog.Error(fmt.Sprintf("Field not implemented: %s", field))
|
|
return ""
|
|
}
|
|
}
|
|
|
|
type Tasks []*Task
|
|
|
|
type Context struct {
|
|
Name string
|
|
Active bool
|
|
ReadFilter string
|
|
WriteFilter string
|
|
}
|
|
|
|
type Contexts map[string]*Context
|
|
|
|
type Report struct {
|
|
Name string
|
|
Description string
|
|
Labels []string
|
|
Filter string
|
|
Sort string
|
|
Columns []string
|
|
Context bool
|
|
}
|
|
|
|
type Reports map[string]*Report
|
|
|
|
func formatTime(timeStr string) string {
|
|
if timeStr == "" {
|
|
return ""
|
|
}
|
|
format := "20060102T150405Z"
|
|
t, err := time.Parse(format, timeStr)
|
|
if err != nil {
|
|
slog.Error("Failed to parse time:", err)
|
|
return timeStr
|
|
}
|
|
return t.Format("2006-01-02 15:04")
|
|
}
|