Phase 2: Add config support for week_start_day and default_due_time
- Add WeekStartDay and DefaultDueTime fields to Config struct - Set defaults: week_start_day=monday, default_due_time=empty - Add GetWeekStart() and GetDefaultDueTime() helper methods - Update ParseDate() to use configured week start day - All tests passing
This commit is contained in:
@@ -4,14 +4,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DefaultFilter string `mapstructure:"default_filter"`
|
DefaultFilter string `mapstructure:"default_filter"`
|
||||||
DefaultSort string `mapstructure:"default_sort"`
|
DefaultSort string `mapstructure:"default_sort"`
|
||||||
ColorOutput bool `mapstructure:"color_output"`
|
ColorOutput bool `mapstructure:"color_output"`
|
||||||
|
WeekStartDay string `mapstructure:"week_start_day"`
|
||||||
|
DefaultDueTime string `mapstructure:"default_due_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalConfig *Config
|
var globalConfig *Config
|
||||||
@@ -72,6 +76,8 @@ func LoadConfig() (*Config, error) {
|
|||||||
v.SetDefault("default_filter", "status:pending")
|
v.SetDefault("default_filter", "status:pending")
|
||||||
v.SetDefault("default_sort", "due,priority")
|
v.SetDefault("default_sort", "due,priority")
|
||||||
v.SetDefault("color_output", true)
|
v.SetDefault("color_output", true)
|
||||||
|
v.SetDefault("week_start_day", "monday")
|
||||||
|
v.SetDefault("default_due_time", "")
|
||||||
|
|
||||||
// Try to read existing config
|
// Try to read existing config
|
||||||
err = v.ReadInConfig()
|
err = v.ReadInConfig()
|
||||||
@@ -110,6 +116,8 @@ func SaveConfig(cfg *Config) error {
|
|||||||
v.Set("default_filter", cfg.DefaultFilter)
|
v.Set("default_filter", cfg.DefaultFilter)
|
||||||
v.Set("default_sort", cfg.DefaultSort)
|
v.Set("default_sort", cfg.DefaultSort)
|
||||||
v.Set("color_output", cfg.ColorOutput)
|
v.Set("color_output", cfg.ColorOutput)
|
||||||
|
v.Set("week_start_day", cfg.WeekStartDay)
|
||||||
|
v.Set("default_due_time", cfg.DefaultDueTime)
|
||||||
|
|
||||||
return v.WriteConfig()
|
return v.WriteConfig()
|
||||||
}
|
}
|
||||||
@@ -121,3 +129,16 @@ func GetConfig() (*Config, error) {
|
|||||||
}
|
}
|
||||||
return LoadConfig()
|
return LoadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWeekStart returns the configured week start day
|
||||||
|
func (c *Config) GetWeekStart() time.Weekday {
|
||||||
|
if strings.ToLower(c.WeekStartDay) == "sunday" {
|
||||||
|
return time.Sunday
|
||||||
|
}
|
||||||
|
return time.Monday // default
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDefaultDueTime returns the configured default due time (HH:MM format or empty)
|
||||||
|
func (c *Config) GetDefaultDueTime() string {
|
||||||
|
return c.DefaultDueTime
|
||||||
|
}
|
||||||
|
|||||||
@@ -263,8 +263,14 @@ func (p *DateParser) nextWeekday(target time.Weekday) time.Time {
|
|||||||
return time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
|
return time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseDate is the public API that uses default settings
|
// ParseDate is the public API that uses config settings
|
||||||
func ParseDate(s string) (time.Time, error) {
|
func ParseDate(s string) (time.Time, error) {
|
||||||
parser := NewDefaultDateParser()
|
cfg, err := GetConfig()
|
||||||
|
weekStart := time.Monday // default
|
||||||
|
if err == nil {
|
||||||
|
weekStart = cfg.GetWeekStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
parser := NewDateParser(timeNow(), weekStart)
|
||||||
return parser.ParseDate(s)
|
return parser.ParseDate(s)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user