date and time zero value

This commit is contained in:
Erik Winter 2024-12-25 10:20:33 +01:00
parent e4faf75aeb
commit e9ce251737
5 changed files with 13 additions and 4 deletions

View File

@ -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))

View File

@ -230,7 +230,7 @@ func TestDateString(t *testing.T) {
{
name: "zero",
date: item.NewDate(0, 0, 0),
exp: "no date",
exp: "",
},
{
name: "normal",

View File

@ -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":""}`,
},
},
{

View File

@ -44,6 +44,10 @@ func NewTimeFromString(timeStr string) Time {
}
func (t *Time) String() string {
if t.t.IsZero() {
return ""
}
return t.t.Format(TimeFormat)
}

View File

@ -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",
},
{