MCPcopy Create free account
hub / github.com/diillson/chatcli / parseFlexibleDate

Function parseFlexibleDate

cli/memory_command.go:873–897  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

871}
872
873func parseFlexibleDate(s string) (time.Time, error) {
874 s = strings.TrimSpace(s)
875
876 if s == "yesterday" {
877 return time.Now().AddDate(0, 0, -1), nil
878 }
879 if s == "today" {
880 return time.Now(), nil
881 }
882
883 // Try YYYY-MM-DD
884 if t, err := time.Parse("2006-01-02", s); err == nil {
885 return t, nil
886 }
887 // Try YYYYMMDD
888 if t, err := time.Parse("20060102", s); err == nil {
889 return t, nil
890 }
891 // Try DD/MM/YYYY
892 if t, err := time.Parse("02/01/2006", s); err == nil {
893 return t, nil
894 }
895
896 return time.Time{}, fmt.Errorf("unrecognized date format: %s", s)
897}

Callers 3

TestParseFlexibleDateFunction · 0.85
handleMemoryCommandMethod · 0.85
loadMemoryIntoContextMethod · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by 1

TestParseFlexibleDateFunction · 0.68