Merge pull request #125424 from benluddy/cbor-timetag-rfc3339
KEP-4222: Decode CBOR time tags to interface{} as RFC 3339 timestamps.
			
			
This commit is contained in:
		@@ -300,17 +300,15 @@ func TestAppendixA(t *testing.T) {
 | 
				
			|||||||
				reasonByteString,
 | 
									reasonByteString,
 | 
				
			||||||
				reasonTimeToInterface,
 | 
									reasonTimeToInterface,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			fixme: "decoding of tagged time into interface{} must produce RFC3339 timestamp compatible with JSON, not time.Time",
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			example: hex("c11a514b67b0"),
 | 
								example: hex("c11a514b67b0"),
 | 
				
			||||||
			decoded: "2013-03-21T16:04:00Z",
 | 
								decoded: "2013-03-21T20:04:00Z",
 | 
				
			||||||
			encoded: hex("54323031332d30332d32315431363a30343a30305a"),
 | 
								encoded: hex("54323031332d30332d32315432303a30343a30305a"),
 | 
				
			||||||
			reasons: []string{
 | 
								reasons: []string{
 | 
				
			||||||
				reasonByteString,
 | 
									reasonByteString,
 | 
				
			||||||
				reasonTimeToInterface,
 | 
									reasonTimeToInterface,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			fixme: "decoding of tagged time into interface{} must produce RFC3339 timestamp compatible with JSON, not time.Time",
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			example: hex("c1fb41d452d9ec200000"),
 | 
								example: hex("c1fb41d452d9ec200000"),
 | 
				
			||||||
@@ -320,7 +318,6 @@ func TestAppendixA(t *testing.T) {
 | 
				
			|||||||
				reasonByteString,
 | 
									reasonByteString,
 | 
				
			||||||
				reasonTimeToInterface,
 | 
									reasonTimeToInterface,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			fixme: "decoding of tagged time into interface{} must produce RFC3339 timestamp compatible with JSON, not time.Time",
 | 
					 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			example: hex("d74401020304"),
 | 
								example: hex("d74401020304"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -85,6 +85,9 @@ var Decode cbor.DecMode = func() cbor.DecMode {
 | 
				
			|||||||
		// instead of the default, a cbor.Tag representing a (number, content) pair.
 | 
							// instead of the default, a cbor.Tag representing a (number, content) pair.
 | 
				
			||||||
		UnrecognizedTagToAny: cbor.UnrecognizedTagContentToAny,
 | 
							UnrecognizedTagToAny: cbor.UnrecognizedTagContentToAny,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Decode time tags to interface{} as strings containing RFC 3339 timestamps.
 | 
				
			||||||
 | 
							TimeTagToAny: cbor.TimeTagToRFC3339Nano,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// For parity with JSON, strings can be decoded into time.Time if they are RFC 3339
 | 
							// For parity with JSON, strings can be decoded into time.Time if they are RFC 3339
 | 
				
			||||||
		// timestamps.
 | 
							// timestamps.
 | 
				
			||||||
		ByteStringToTime: cbor.ByteStringToTimeAllowed,
 | 
							ByteStringToTime: cbor.ByteStringToTimeAllowed,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -647,7 +647,6 @@ func TestDecode(t *testing.T) {
 | 
				
			|||||||
				name:          "tag 0 RFC3339 text string",
 | 
									name:          "tag 0 RFC3339 text string",
 | 
				
			||||||
				in:            hex("c074323030362d30312d30325431353a30343a30355a"), // 0("2006-01-02T15:04:05Z")
 | 
									in:            hex("c074323030362d30312d30325431353a30343a30355a"), // 0("2006-01-02T15:04:05Z")
 | 
				
			||||||
				want:          "2006-01-02T15:04:05Z",
 | 
									want:          "2006-01-02T15:04:05Z",
 | 
				
			||||||
				fixme:         "decoding RFC3339 text string tagged with 0 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
@@ -668,63 +667,54 @@ func TestDecode(t *testing.T) {
 | 
				
			|||||||
				name:          "tag 1 timestamp unsigned integer",
 | 
									name:          "tag 1 timestamp unsigned integer",
 | 
				
			||||||
				in:            hex("c11a43b940e5"), // 1(1136214245)
 | 
									in:            hex("c11a43b940e5"), // 1(1136214245)
 | 
				
			||||||
				want:          "2006-01-02T15:04:05Z",
 | 
									want:          "2006-01-02T15:04:05Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with float16 value",
 | 
									name:          "tag 1 with float16 value",
 | 
				
			||||||
				in:            hex("c1f93c00"), // 1(1.0_1)
 | 
									in:            hex("c1f93c00"), // 1(1.0_1)
 | 
				
			||||||
				want:          "1970-01-01T00:00:01Z",
 | 
									want:          "1970-01-01T00:00:01Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with float32 value",
 | 
									name:          "tag 1 with float32 value",
 | 
				
			||||||
				in:            hex("c1fa3f800000"), // 1(1.0_2)
 | 
									in:            hex("c1fa3f800000"), // 1(1.0_2)
 | 
				
			||||||
				want:          "1970-01-01T00:00:01Z",
 | 
									want:          "1970-01-01T00:00:01Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with float64 value",
 | 
									name:          "tag 1 with float64 value",
 | 
				
			||||||
				in:            hex("c1fb3ff0000000000000"), // 1(1.0_3)
 | 
									in:            hex("c1fb3ff0000000000000"), // 1(1.0_3)
 | 
				
			||||||
				want:          "1970-01-01T00:00:01Z",
 | 
									want:          "1970-01-01T00:00:01Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with a five digit year",
 | 
									name:          "tag 1 with a five digit year",
 | 
				
			||||||
				in:            hex("c11b0000003afff44181"), // 1(253402300801)
 | 
									in:            hex("c11b0000003afff44181"), // 1(253402300801)
 | 
				
			||||||
				want:          "10000-01-01T00:00:01Z",
 | 
									want:          "10000-01-01T00:00:01Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
									assertOnError: assertErrorMessage("cbor: decoded time cannot be represented in RFC3339 format with sub-second precision: Time.MarshalText: year outside of range [0,9999]"),
 | 
				
			||||||
				assertOnError: assertNilError,
 | 
					 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with a negative integer value",
 | 
									name:          "tag 1 with a negative integer value",
 | 
				
			||||||
				in:            hex("c120"), // 1(-1)
 | 
									in:            hex("c120"), // 1(-1)
 | 
				
			||||||
				want:          "1969-12-31T23:59:59Z",
 | 
									want:          "1969-12-31T23:59:59Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with a negative float16 value",
 | 
									name:          "tag 1 with a negative float16 value",
 | 
				
			||||||
				in:            hex("c1f9bc00"), // 1(-1.0_1)
 | 
									in:            hex("c1f9bc00"), // 1(-1.0_1)
 | 
				
			||||||
				want:          "1969-12-31T23:59:59Z",
 | 
									want:          "1969-12-31T23:59:59Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with a negative float32 value",
 | 
									name:          "tag 1 with a negative float32 value",
 | 
				
			||||||
				in:            hex("c1fabf800000"), // 1(-1.0_2)
 | 
									in:            hex("c1fabf800000"), // 1(-1.0_2)
 | 
				
			||||||
				want:          "1969-12-31T23:59:59Z",
 | 
									want:          "1969-12-31T23:59:59Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				name:          "tag 1 with a negative float64 value",
 | 
									name:          "tag 1 with a negative float64 value",
 | 
				
			||||||
				in:            hex("c1fbbff0000000000000"), // 1(-1.0_3)
 | 
									in:            hex("c1fbbff0000000000000"), // 1(-1.0_3)
 | 
				
			||||||
				want:          "1969-12-31T23:59:59Z",
 | 
									want:          "1969-12-31T23:59:59Z",
 | 
				
			||||||
				fixme:         "decoding cbor data tagged with 1 produces time.Time instead of RFC3339 timestamp string",
 | 
					 | 
				
			||||||
				assertOnError: assertNilError,
 | 
									assertOnError: assertNilError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user