Skip to content

Commit

Permalink
Use cmp.Or to select appropriate time.Format format
Browse files Browse the repository at this point in the history
The cmp.Or helper was added in Go 1.22.
  • Loading branch information
dsnet committed Aug 15, 2024
1 parent 2d9f40f commit a525059
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions arshal_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package json

import (
"bytes"
"cmp"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a525059

Please sign in to comment.