Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/utils/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (ct *Time) UnmarshalJSON(b []byte) (err error) {

// MarshalJSON writes a quoted string in the custom format
func (ct Time) MarshalJSON() ([]byte, error) {
if ct.IsZero() {
return []byte("\"\""), nil
}

return []byte(ct.String()), nil
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/utils/time_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.

package utils

import (
"bytes"
"testing"
)

func TestMarshalJSONIsZeroDate(t *testing.T) {
ct := new(Time) // create zero time
str, _ := ct.MarshalJSON()
if !bytes.Equal(str, []byte("\"\"")) {
t.Error("Expected empty string but received: \"" + string(str) + "\"\n")
}
}