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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user