fix: reminder_time format for habits and tasks (HH:MM instead of timestamp)

This commit is contained in:
Cosmo
2026-02-06 14:25:52 +00:00
parent afeb3adddf
commit 9e90aa6d95
2 changed files with 41 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package model
import (
"database/sql"
"strings"
"time"
)
@@ -14,7 +15,7 @@ type Task struct {
Color string `db:"color" json:"color"`
DueDate sql.NullTime `db:"due_date" json:"-"`
DueDateStr *string `db:"-" json:"due_date"`
Priority int `db:"priority" json:"priority"` // 0=none, 1=low, 2=medium, 3=high
Priority int `db:"priority" json:"priority"`
ReminderTime sql.NullString `db:"reminder_time" json:"-"`
ReminderTimeStr *string `db:"-" json:"reminder_time"`
CompletedAt sql.NullTime `db:"completed_at" json:"-"`
@@ -28,8 +29,22 @@ func (t *Task) ProcessForJSON() {
s := t.DueDate.Time.Format("2006-01-02")
t.DueDateStr = &s
}
if t.ReminderTime.Valid {
t.ReminderTimeStr = &t.ReminderTime.String
if t.ReminderTime.Valid && t.ReminderTime.String != "" {
timeStr := t.ReminderTime.String
// Handle formats like "0000-01-01T19:00:00Z" or "19:00:00"
if strings.Contains(timeStr, "T") {
parsed, err := time.Parse(time.RFC3339, timeStr)
if err == nil {
formatted := parsed.Format("15:04")
t.ReminderTimeStr = &formatted
return
}
}
// Handle "19:00:00" format
if len(timeStr) >= 5 {
formatted := timeStr[:5]
t.ReminderTimeStr = &formatted
}
}
t.Completed = t.CompletedAt.Valid
}
@@ -39,9 +54,9 @@ type CreateTaskRequest struct {
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"`
Color string `json:"color,omitempty"`
DueDate *string `json:"due_date,omitempty"` // YYYY-MM-DD
DueDate *string `json:"due_date,omitempty"`
Priority int `json:"priority,omitempty"`
ReminderTime *string `json:"reminder_time,omitempty"` // HH:MM
ReminderTime *string `json:"reminder_time,omitempty"`
}
type UpdateTaskRequest struct {