From a5250592cc8ae2654b60e404445207705d63cdf1 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Thu, 15 Aug 2024 10:31:14 -0700 Subject: [PATCH] Use cmp.Or to select appropriate time.Format format The cmp.Or helper was added in Go 1.22. --- arshal_time.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arshal_time.go b/arshal_time.go index f1ef5ee..f0acf8e 100644 --- a/arshal_time.go +++ b/arshal_time.go @@ -6,6 +6,7 @@ package json import ( "bytes" + "cmp" "errors" "fmt" "math" @@ -317,11 +318,7 @@ func (a *timeArshaler) hasCustomFormat() bool { func (a *timeArshaler) appendMarshal(b []byte) ([]byte, error) { switch a.base { case 0: - // TODO(https://go.dev/issue/60204): Use cmp.Or(a.format, time.RFC3339Nano). - format := a.format - if format == "" { - format = time.RFC3339Nano - } + format := cmp.Or(a.format, time.RFC3339Nano) n0 := len(b) b = a.tt.AppendFormat(b, format) // Not all Go timestamps can be represented as valid RFC 3339.