diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-28 09:59:06 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-28 12:50:12 +0200 |
| commit | dbf8980f1bc5428d1eb463505968469617dbf3fc (patch) | |
| tree | c94c057bfe6d2d8ff3763a64a30cefd59d76cd87 /internal/task/task.go | |
| parent | d2cc2def17b58da762d88090c0c298dc2e87dd1d (diff) | |
refactor(task): centralize Taskwarrior date format as task.DateFormat
DRY/MEDIUM task (UUID 2c74960f): the format string "20060102T150405Z" was
hardcoded in 5+ places across the task and ui packages.
- Export task.DateFormat constant from internal/task/task.go
- Replace hardcoded string in task.go and stats.go with DateFormat
- Update internal/ui/helpers.go to alias the constant (taskDateFormat =
task.DateFormat) rather than repeating the string literal
- Replace all 6 raw string literals in table.go with task.DateFormat
- Remove duplicate dueText() from table.go; its only call site now uses
formatDueText() from helpers.go, which also normalises to midnight UTC
for more accurate day-difference calculations
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/task/task.go')
| -rw-r--r-- | internal/task/task.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/internal/task/task.go b/internal/task/task.go index 2c7f8e8..8eadd18 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -16,6 +16,11 @@ import ( "github.com/google/shlex" ) +// DateFormat is the date format used by Taskwarrior in all date fields +// (e.g. Entry, Due, Start). All date parsing and formatting in this +// package uses this constant. +const DateFormat = "20060102T150405Z" + // Task represents a taskwarrior task as returned by `task export`. type Annotation struct { Entry string `json:"entry"` @@ -421,7 +426,7 @@ func SortTasks(tasks []Task) { if s == "" { return time.Time{}, false } - t, err := time.Parse("20060102T150405Z", s) + t, err := time.Parse(DateFormat, s) if err != nil { return time.Time{}, false } |
