From e9ce2517377e9921aa8354499a07535c00e9d96d Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Wed, 25 Dec 2024 10:20:33 +0100 Subject: [PATCH] date and time zero value --- item/date.go | 2 +- item/date_test.go | 2 +- item/task_test.go | 2 +- item/time.go | 4 ++++ item/time_test.go | 7 ++++++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/item/date.go b/item/date.go index 5e48174..7771dae 100644 --- a/item/date.go +++ b/item/date.go @@ -167,7 +167,7 @@ func (d Date) DaysBetween(d2 Date) int { func (d Date) String() string { if d.t.IsZero() { - return "no date" + return "" } return strings.ToLower(d.t.Format(DateFormat)) diff --git a/item/date_test.go b/item/date_test.go index b48f82d..3d9f6e0 100644 --- a/item/date_test.go +++ b/item/date_test.go @@ -230,7 +230,7 @@ func TestDateString(t *testing.T) { { name: "zero", date: item.NewDate(0, 0, 0), - exp: "no date", + exp: "", }, { name: "normal", diff --git a/item/task_test.go b/item/task_test.go index d4e342e..c1ca7b2 100644 --- a/item/task_test.go +++ b/item/task_test.go @@ -102,7 +102,7 @@ func TestTaskItem(t *testing.T) { expItem: item.Item{ Kind: item.KindTask, Updated: time.Time{}, - Body: `{"duration":"0s","title":"","time":"00:00"}`, + Body: `{"duration":"0s","title":"","time":""}`, }, }, { diff --git a/item/time.go b/item/time.go index af7ae0c..3b7185c 100644 --- a/item/time.go +++ b/item/time.go @@ -44,6 +44,10 @@ func NewTimeFromString(timeStr string) Time { } func (t *Time) String() string { + if t.t.IsZero() { + return "" + } + return t.t.Format(TimeFormat) } diff --git a/item/time_test.go b/item/time_test.go index 3811cca..9fc41af 100644 --- a/item/time_test.go +++ b/item/time_test.go @@ -44,11 +44,16 @@ func TestTimeFromString(t *testing.T) { }{ { name: "empty", - exp: "00:00", + exp: "", }, { name: "invalid", str: "invalid", + exp: "", + }, + { + name: "00:00", + str: "00:00", exp: "00:00", }, {