WIP: Intelligently parse dates when creating new task #10

Draft
breadone wants to merge 1 commits from #7 into main
2 changed files with 30 additions and 9 deletions

View File

@ -2,8 +2,11 @@ package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"regexp"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
func (m model) Init() tea.Cmd {
@ -95,11 +98,27 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
func AddNewTask(m *model) {
taskTitle := m.textinput.Value()
// parse date in title
var doDate int64 = -1
var deadline int64 = -1
reDate := regexp.MustCompile("\\d{1,2}/\\d{1,2}")
date := reDate.FindStringSubmatch(taskTitle)
if len(date) > 0 {
// what the fuck Go
date, _ := time.Parse("02/01/2006", "10/03/2025")
doDate = date.Unix()
}
t := todo{
name: m.textinput.Value(),
name: taskTitle,
done: false,
startdate: 0,
deadline: 0,
startdate: doDate,
deadline: deadline,
priority: 1,
isInbox: true,
}
@ -120,12 +139,12 @@ func (m model) View() string {
currentList = filter(m.todos, taskFilter)
case 1:
// s += "Today"
taskFilter := func(t todo) bool { return t.startdate == int(midnightToUnix()) || t.deadline == int(midnightToUnix()) }
taskFilter := func(t todo) bool { return t.startdate == midnightToUnix() || t.deadline == midnightToUnix() }
currentList = filter(m.todos, taskFilter)
case 2:
// s += "Tomorrow"
// 86400 seconds in 24h, add it on to today's midnight for tomorrow's midnight
taskFilter := func(t todo) bool { return t.startdate == int(midnightToUnix()) + 86400 || t.deadline == int(midnightToUnix()) + 86400}
taskFilter := func(t todo) bool { return t.startdate == midnightToUnix() + 86400 || t.deadline == midnightToUnix() + 86400}
currentList = filter(m.todos, taskFilter)
case 3:
// s += "Scheduled"
@ -156,8 +175,10 @@ func (m model) View() string {
checked = "x"
}
renderedTime := time.Unix(value.startdate, 0)
// Render the row
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, value.name)
s += fmt.Sprintf("%s [%s] %s %s\n", cursor, checked, value.name, renderedTime)
}
s += "\n\n"

View File

@ -7,8 +7,8 @@ import (
type todo struct {
name string
done bool
deadline int
startdate int
deadline int64
startdate int64
priority int // 1-4, 1 being highest priority, 4 being no priority
isInbox bool
}