Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Tweak the ISOTime marshaller
Browse files Browse the repository at this point in the history
@timofurrer does this fix #1384
  • Loading branch information
svanharmelen committed Mar 7, 2022
1 parent 4c8a95d commit 8daa0de
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"net/url"
"reflect"
"strconv"
"time"
)
Expand Down Expand Up @@ -119,7 +120,7 @@ func (a *ApproverIDsValue) EncodeValues(key string, v *url.Values) error {
}

// MarshalJSON implements the json.Marshaler interface
func (a *ApproverIDsValue) MarshalJSON() ([]byte, error) {
func (a ApproverIDsValue) MarshalJSON() ([]byte, error) {
return json.Marshal(a.value)
}

Expand Down Expand Up @@ -155,7 +156,7 @@ func (a *AssigneeIDValue) EncodeValues(key string, v *url.Values) error {
}

// MarshalJSON implements the json.Marshaler interface
func (a *AssigneeIDValue) MarshalJSON() ([]byte, error) {
func (a AssigneeIDValue) MarshalJSON() ([]byte, error) {
return json.Marshal(a.value)
}

Expand Down Expand Up @@ -191,7 +192,7 @@ func (a *ReviewerIDValue) EncodeValues(key string, v *url.Values) error {
}

// MarshalJSON implements the json.Marshaler interface
func (a *ReviewerIDValue) MarshalJSON() ([]byte, error) {
func (a ReviewerIDValue) MarshalJSON() ([]byte, error) {
return json.Marshal(a.value)
}

Expand Down Expand Up @@ -362,6 +363,10 @@ const iso8601 = "2006-01-02"

// MarshalJSON implements the json.Marshaler interface
func (t ISOTime) MarshalJSON() ([]byte, error) {
if reflect.ValueOf(t).IsZero() {
return []byte(`null`), nil
}

if y := time.Time(t).Year(); y < 0 || y >= 10000 {
// ISO 8901 uses 4 digits for the years
return nil, errors.New("json: ISOTime year outside of range [0,9999]")
Expand Down

0 comments on commit 8daa0de

Please sign in to comment.