fix: reminder_time format for habits and tasks (HH:MM instead of timestamp)
This commit is contained in:
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -12,8 +13,8 @@ type Habit struct {
|
||||
Description string `db:"description" json:"description"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Frequency string `db:"frequency" json:"frequency"` // daily, weekly, custom
|
||||
TargetDays []int `db:"-" json:"target_days"` // 0=Sun, 1=Mon, etc.
|
||||
Frequency string `db:"frequency" json:"frequency"`
|
||||
TargetDays []int `db:"-" json:"target_days"`
|
||||
TargetCount int `db:"target_count" json:"target_count"`
|
||||
ReminderTime sql.NullString `db:"reminder_time" json:"-"`
|
||||
ReminderTimeStr *string `db:"-" json:"reminder_time"`
|
||||
@@ -23,8 +24,23 @@ type Habit struct {
|
||||
}
|
||||
|
||||
func (h *Habit) ProcessForJSON() {
|
||||
if h.ReminderTime.Valid {
|
||||
h.ReminderTimeStr = &h.ReminderTime.String
|
||||
if h.ReminderTime.Valid && h.ReminderTime.String != "" {
|
||||
timeStr := h.ReminderTime.String
|
||||
// Handle formats like "0000-01-01T19:00:00Z" or "19:00:00"
|
||||
if strings.Contains(timeStr, "T") {
|
||||
// Parse as timestamp and extract time
|
||||
t, err := time.Parse(time.RFC3339, timeStr)
|
||||
if err == nil {
|
||||
formatted := t.Format("15:04")
|
||||
h.ReminderTimeStr = &formatted
|
||||
return
|
||||
}
|
||||
}
|
||||
// Handle "19:00:00" format
|
||||
if len(timeStr) >= 5 {
|
||||
formatted := timeStr[:5]
|
||||
h.ReminderTimeStr = &formatted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +78,7 @@ type UpdateHabitRequest struct {
|
||||
}
|
||||
|
||||
type LogHabitRequest struct {
|
||||
Date string `json:"date,omitempty"` // YYYY-MM-DD, defaults to today
|
||||
Date string `json:"date,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Note string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user