refactor: deduplicate engine internals, replace bubble sorts, remove dead code
Extract shared code that was duplicated across functions: - taskJSON struct (MarshalJSON/UnmarshalJSON) to package-level type - scanTask(scanner) helper for GetTask/GetTasks (~70 identical lines) - monthNames map for parseMonthName/parseDayAndMonth - applyNonDateAttribute helper for Apply/ApplyToNew - resolveDisplayID calls replace inline loops in FormatTaskListWithFormat Replace O(n²) bubble sorts with sort.Slice in all four report sort functions (sortByUrgency, NewestReport, NextReport, OldestReport). Remove dead code: formatTimeWithColor (unused, also used time.Now() instead of timeNow()), getCurrentTimestamp (unnecessary wrapper). Remove ~20 comments that restated the next line of code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,21 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var monthNames = map[string]time.Month{
|
||||
"jan": time.January, "january": time.January,
|
||||
"feb": time.February, "february": time.February,
|
||||
"mar": time.March, "march": time.March,
|
||||
"apr": time.April, "april": time.April,
|
||||
"may": time.May,
|
||||
"jun": time.June, "june": time.June,
|
||||
"jul": time.July, "july": time.July,
|
||||
"aug": time.August, "august": time.August,
|
||||
"sep": time.September, "september": time.September,
|
||||
"oct": time.October, "october": time.October,
|
||||
"nov": time.November, "november": time.November,
|
||||
"dec": time.December, "december": time.December,
|
||||
}
|
||||
|
||||
// DateParser handles all date/time/duration parsing with configurable options
|
||||
type DateParser struct {
|
||||
base time.Time
|
||||
@@ -238,22 +253,7 @@ func (p *DateParser) parseWeekday(s string) (time.Time, bool) {
|
||||
|
||||
// parseMonthName handles month names (jan, january, feb, february, etc.)
|
||||
func (p *DateParser) parseMonthName(s string) (time.Time, bool) {
|
||||
months := map[string]time.Month{
|
||||
"jan": time.January, "january": time.January,
|
||||
"feb": time.February, "february": time.February,
|
||||
"mar": time.March, "march": time.March,
|
||||
"apr": time.April, "april": time.April,
|
||||
"may": time.May,
|
||||
"jun": time.June, "june": time.June,
|
||||
"jul": time.July, "july": time.July,
|
||||
"aug": time.August, "august": time.August,
|
||||
"sep": time.September, "september": time.September,
|
||||
"oct": time.October, "october": time.October,
|
||||
"nov": time.November, "november": time.November,
|
||||
"dec": time.December, "december": time.December,
|
||||
}
|
||||
|
||||
month, ok := months[s]
|
||||
month, ok := monthNames[s]
|
||||
if !ok {
|
||||
return time.Time{}, false
|
||||
}
|
||||
@@ -316,22 +316,7 @@ func (p *DateParser) parseDayAndMonth(dayStr, monthStr string) (int, time.Month,
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
months := map[string]time.Month{
|
||||
"jan": time.January, "january": time.January,
|
||||
"feb": time.February, "february": time.February,
|
||||
"mar": time.March, "march": time.March,
|
||||
"apr": time.April, "april": time.April,
|
||||
"may": time.May,
|
||||
"jun": time.June, "june": time.June,
|
||||
"jul": time.July, "july": time.July,
|
||||
"aug": time.August, "august": time.August,
|
||||
"sep": time.September, "september": time.September,
|
||||
"oct": time.October, "october": time.October,
|
||||
"nov": time.November, "november": time.November,
|
||||
"dec": time.December, "december": time.December,
|
||||
}
|
||||
|
||||
month, ok := months[monthStr]
|
||||
month, ok := monthNames[monthStr]
|
||||
if !ok {
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user