Skip to content

Commit ac104c8

Browse files
aren55555omarismail
authored andcommitted
Revert "Add RFC3339 timestamp (google#201)" (google#203)
This reverts commit c0ee6d2.
1 parent 95d5725 commit ac104c8

File tree

4 files changed

+0
-106
lines changed

4 files changed

+0
-106
lines changed

Diff for: constants.go

-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ const (
1010
annotationLinks = "links"
1111
annotationOmitEmpty = "omitempty"
1212
annotationISO8601 = "iso8601"
13-
annotationRFC3339 = "rfc3339"
1413
annotationSeperator = ","
1514

16-
rfc3339TimeFormat = "2006-01-02T15:04:05Z07:00"
1715
iso8601TimeFormat = "2006-01-02T15:04:05Z"
1816

1917
// MediaType is the identifier for the JSON API media type

Diff for: models_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ type Timestamp struct {
3131
Next *time.Time `jsonapi:"attr,next,iso8601"`
3232
}
3333

34-
type TimestampRFC3339 struct {
35-
ID int `jsonapi:"primary,timestamps"`
36-
Time time.Time `jsonapi:"attr,timestamp,rfc3339"`
37-
Next *time.Time `jsonapi:"attr,next,rfc3339"`
38-
}
39-
4034
type Car struct {
4135
ID *string `jsonapi:"primary,cars"`
4236
Make *string `jsonapi:"attr,make,omitempty"`

Diff for: request.go

-26
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ var (
2323
// ErrInvalidISO8601 is returned when a struct has a time.Time type field and includes
2424
// "iso8601" in the tag spec, but the JSON value was not an ISO8601 timestamp string.
2525
ErrInvalidISO8601 = errors.New("Only strings can be parsed as dates, ISO8601 timestamps")
26-
// ErrInvalidRFC3339 is returned when a struct has a time.Time type field and includes
27-
// "rfc3339" in the tag spec, but the JSON value was not an RFC3339 timestamp string.
28-
ErrInvalidRFC3339 = errors.New("Only strings can be parsed as dates, RFC3339 timestamps")
2926
// ErrUnknownFieldNumberType is returned when the JSON value was a float
3027
// (numeric) but the Struct field was a non numeric type (i.e. not int, uint,
3128
// float, etc)
@@ -548,15 +545,12 @@ func handleLinks(attribute interface{}, args []string, fieldValue reflect.Value)
548545

549546
func handleTime(attribute interface{}, args []string, fieldValue reflect.Value) (reflect.Value, error) {
550547
var isIso8601 bool
551-
var isRFC3339 bool
552548
v := reflect.ValueOf(attribute)
553549

554550
if len(args) > 2 {
555551
for _, arg := range args[2:] {
556552
if arg == annotationISO8601 {
557553
isIso8601 = true
558-
} else if arg == annotationRFC3339 {
559-
isRFC3339 = true
560554
}
561555
}
562556
}
@@ -581,26 +575,6 @@ func handleTime(attribute interface{}, args []string, fieldValue reflect.Value)
581575
return reflect.ValueOf(t), nil
582576
}
583577

584-
if isRFC3339 {
585-
var tm string
586-
if v.Kind() == reflect.String {
587-
tm = v.Interface().(string)
588-
} else {
589-
return reflect.ValueOf(time.Now()), ErrInvalidRFC3339
590-
}
591-
592-
t, err := time.Parse(time.RFC3339, tm)
593-
if err != nil {
594-
return reflect.ValueOf(time.Now()), ErrInvalidRFC3339
595-
}
596-
597-
if fieldValue.Kind() == reflect.Ptr {
598-
return reflect.ValueOf(&t), nil
599-
}
600-
601-
return reflect.ValueOf(t), nil
602-
}
603-
604578
var at int64
605579

606580
if v.Kind() == reflect.Float64 {

Diff for: request_test.go

-72
Original file line numberDiff line numberDiff line change
@@ -413,78 +413,6 @@ func TestUnmarshalInvalidISO8601(t *testing.T) {
413413
}
414414
}
415415

416-
func TestUnmarshalParsesRFC3339(t *testing.T) {
417-
payload := &OnePayload{
418-
Data: &Node{
419-
Type: "timestamps",
420-
Attributes: map[string]interface{}{
421-
"timestamp": "2020-03-16T23:09:59+00:00",
422-
},
423-
},
424-
}
425-
426-
in := bytes.NewBuffer(nil)
427-
json.NewEncoder(in).Encode(payload)
428-
429-
out := new(TimestampRFC3339)
430-
431-
if err := UnmarshalPayload(in, out); err != nil {
432-
t.Fatal(err)
433-
}
434-
435-
expected := time.Date(2020, 3, 16, 23, 9, 59, 0, time.UTC)
436-
437-
if !out.Time.Equal(expected) {
438-
t.Fatal("Parsing the RFC3339 timestamp failed")
439-
}
440-
}
441-
442-
func TestUnmarshalParsesRFC3339TimePointer(t *testing.T) {
443-
payload := &OnePayload{
444-
Data: &Node{
445-
Type: "timestamps",
446-
Attributes: map[string]interface{}{
447-
"next": "2020-03-16T23:09:59+00:00",
448-
},
449-
},
450-
}
451-
452-
in := bytes.NewBuffer(nil)
453-
json.NewEncoder(in).Encode(payload)
454-
455-
out := new(TimestampRFC3339)
456-
457-
if err := UnmarshalPayload(in, out); err != nil {
458-
t.Fatal(err)
459-
}
460-
461-
expected := time.Date(2020, 3, 16, 23, 9, 59, 0, time.UTC)
462-
463-
if !out.Next.Equal(expected) {
464-
t.Fatal("Parsing the RFC3339 timestamp failed")
465-
}
466-
}
467-
468-
func TestUnmarshalInvalidRFC3339(t *testing.T) {
469-
payload := &OnePayload{
470-
Data: &Node{
471-
Type: "timestamps",
472-
Attributes: map[string]interface{}{
473-
"timestamp": "17 Aug 16 08:027 MST",
474-
},
475-
},
476-
}
477-
478-
in := bytes.NewBuffer(nil)
479-
json.NewEncoder(in).Encode(payload)
480-
481-
out := new(TimestampRFC3339)
482-
483-
if err := UnmarshalPayload(in, out); err != ErrInvalidRFC3339 {
484-
t.Fatalf("Expected ErrInvalidRFC3339, got %v", err)
485-
}
486-
}
487-
488416
func TestUnmarshalRelationshipsWithoutIncluded(t *testing.T) {
489417
data, err := json.Marshal(samplePayloadWithoutIncluded())
490418
if err != nil {

0 commit comments

Comments
 (0)