diff --git a/docs/source-2.0/spec/protocol-traits.rst b/docs/source-2.0/spec/protocol-traits.rst index 19a62a4cb91..0b86c3500d5 100644 --- a/docs/source-2.0/spec/protocol-traits.rst +++ b/docs/source-2.0/spec/protocol-traits.rst @@ -221,6 +221,8 @@ Smithy defines the following built-in timestamp formats: :rfc:`3339#section-5.6` with no UTC offset and optional fractional precision (for example, ``1985-04-12T23:20:50.52Z``). + *However*, offsets will still be parsed gracefully, but the datetime + will be normalized to an offset of zero (i.e. converted to UTC) * - http-date - An HTTP date as defined by the ``IMF-fixdate`` production in :rfc:`7231#section-7.1.1.1` (for example, diff --git a/smithy-aws-protocol-tests/model/awsJson1_1/datetime-offsets.smithy b/smithy-aws-protocol-tests/model/awsJson1_1/datetime-offsets.smithy new file mode 100644 index 00000000000..ec9485138b1 --- /dev/null +++ b/smithy-aws-protocol-tests/model/awsJson1_1/datetime-offsets.smithy @@ -0,0 +1,61 @@ +$version: "2.0" + +namespace aws.protocoltests.json + +use aws.protocols#awsJson1_1 +use aws.protocoltests.shared#DateTime +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +// These tests are for verifying the client can correctly parse +// the `DateTime` timestamp with an offset +@tags(["client-only"]) +@http(uri: "/DatetimeOffsets", method: "POST") +operation DatetimeOffsets { + output: DatetimeOffsetsOutput +} + +apply DatetimeOffsets @httpResponseTests([ + { + id: "AwsJson11DateTimeWithNegativeOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: awsJson1_1, + code: 200, + body: + """ + { + "datetime": "2019-12-16T22:48:18-01:00" + } + """, + params: { datetime: 1576540098 } + bodyMediaType: "application/json", + headers: { + "Content-Type": "application/x-amz-json-1.1" + }, + appliesTo: "client" + }, + { + id: "AwsJson11DateTimeWithPositiveOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: awsJson1_1, + code: 200, + body: + """ + { + "datetime": "2019-12-17T00:48:18+01:00" + } + """, + params: { datetime: 1576540098 } + bodyMediaType: "application/json", + headers: { + "Content-Type": "application/x-amz-json-1.1" + }, + appliesTo: "client" + }, +]) + +structure DatetimeOffsetsOutput { + datetime: DateTime +} diff --git a/smithy-aws-protocol-tests/model/awsJson1_1/main.smithy b/smithy-aws-protocol-tests/model/awsJson1_1/main.smithy index 4f1a467d56a..e5604e85cad 100644 --- a/smithy-aws-protocol-tests/model/awsJson1_1/main.smithy +++ b/smithy-aws-protocol-tests/model/awsJson1_1/main.smithy @@ -36,6 +36,8 @@ service JsonProtocol { // custom endpoints with paths HostWithPathOperation, + + DatetimeOffsets, ], } diff --git a/smithy-aws-protocol-tests/model/awsQuery/datetime-offsets.smithy b/smithy-aws-protocol-tests/model/awsQuery/datetime-offsets.smithy new file mode 100644 index 00000000000..07daa318fa8 --- /dev/null +++ b/smithy-aws-protocol-tests/model/awsQuery/datetime-offsets.smithy @@ -0,0 +1,62 @@ +$version: "2.0" + +namespace aws.protocoltests.query + +use aws.protocols#awsQuery +use aws.protocoltests.shared#DateTime +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +// These tests are for verifying the client can correctly parse +// the `DateTime` timestamp with an offset +@tags(["client-only"]) +operation DatetimeOffsets { + output: DatetimeOffsetsOutput +} + +apply DatetimeOffsets @httpResponseTests([ + { + id: "AwsQueryDateTimeWithNegativeOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: awsQuery, + code: 200, + body: """ + + + 2019-12-16T22:48:18-01:00 + + + """, + params: { datetime: 1576540098 } + bodyMediaType: "application/xml", + headers: { + "Content-Type": "text/xml" + }, + appliesTo: "client" + }, + { + id: "AwsQueryDateTimeWithPositiveOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: awsQuery, + code: 200, + body: """ + + + 2019-12-17T00:48:18+01:00 + + + """, + params: { datetime: 1576540098 } + bodyMediaType: "application/xml", + headers: { + "Content-Type": "text/xml" + }, + appliesTo: "client" + }, +]) + +structure DatetimeOffsetsOutput { + datetime: DateTime +} diff --git a/smithy-aws-protocol-tests/model/awsQuery/main.smithy b/smithy-aws-protocol-tests/model/awsQuery/main.smithy index 3db3663ab6b..8ee0c6f5abd 100644 --- a/smithy-aws-protocol-tests/model/awsQuery/main.smithy +++ b/smithy-aws-protocol-tests/model/awsQuery/main.smithy @@ -62,5 +62,7 @@ service AwsQuery { // custom endpoints with paths HostWithPathOperation, + + DatetimeOffsets, ] } diff --git a/smithy-aws-protocol-tests/model/ec2Query/datetime-offsets.smithy b/smithy-aws-protocol-tests/model/ec2Query/datetime-offsets.smithy new file mode 100644 index 00000000000..f698b7bb1b9 --- /dev/null +++ b/smithy-aws-protocol-tests/model/ec2Query/datetime-offsets.smithy @@ -0,0 +1,58 @@ +$version: "2.0" + +namespace aws.protocoltests.ec2 + +use aws.protocols#ec2Query +use aws.protocoltests.shared#DateTime +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +// These tests are for verifying the client can correctly parse +// the `DateTime` timestamp with an offset +@tags(["client-only"]) +operation DatetimeOffsets { + output: DatetimeOffsetsOutput +} + +apply DatetimeOffsets @httpResponseTests([ + { + id: "Ec2QueryDateTimeWithNegativeOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: ec2Query, + code: 200, + body: """ + + 2019-12-16T22:48:18-01:00 + requestid + + """, + bodyMediaType: "application/xml", + headers: { + "Content-Type": "text/xml;charset=UTF-8" + }, + params: { datetime: 1576540098 } + }, + { + id: "Ec2QueryDateTimeWithPositiveOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: ec2Query, + code: 200, + body: """ + + 2019-12-17T00:48:18+01:00 + requestid + + """, + bodyMediaType: "application/xml", + headers: { + "Content-Type": "text/xml;charset=UTF-8" + }, + params: { datetime: 1576540098 } + } +]) + +structure DatetimeOffsetsOutput { + datetime: DateTime +} diff --git a/smithy-aws-protocol-tests/model/ec2Query/main.smithy b/smithy-aws-protocol-tests/model/ec2Query/main.smithy index e9884a1c875..d10fc421c91 100644 --- a/smithy-aws-protocol-tests/model/ec2Query/main.smithy +++ b/smithy-aws-protocol-tests/model/ec2Query/main.smithy @@ -78,5 +78,7 @@ service AwsEc2 { // custom endpoints with paths HostWithPathOperation, + + DatetimeOffsets, ] } diff --git a/smithy-aws-protocol-tests/model/restJson1/datetime-offsets.smithy b/smithy-aws-protocol-tests/model/restJson1/datetime-offsets.smithy new file mode 100644 index 00000000000..0738daa043d --- /dev/null +++ b/smithy-aws-protocol-tests/model/restJson1/datetime-offsets.smithy @@ -0,0 +1,55 @@ +$version: "2.0" + +namespace aws.protocoltests.restjson + +use aws.protocols#restJson1 +use aws.protocoltests.shared#DateTime +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +// These tests are for verifying the client can correctly parse +// the `DateTime` timestamp with an offset +@tags(["client-only"]) +@http(uri: "/DatetimeOffsets", method: "POST") +operation DatetimeOffsets { + output: DatetimeOffsetsOutput +} + +apply DatetimeOffsets @httpResponseTests([ + { + id: "RestJsonDateTimeWithNegativeOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: restJson1, + code: 200, + body: + """ + { + "datetime": "2019-12-16T22:48:18-01:00" + } + """, + params: { datetime: 1576540098 } + bodyMediaType: "application/json", + appliesTo: "client" + }, + { + id: "RestJsonDateTimeWithPositiveOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: restJson1, + code: 200, + body: + """ + { + "datetime": "2019-12-17T00:48:18+01:00" + } + """, + params: { datetime: 1576540098 } + bodyMediaType: "application/json", + appliesTo: "client" + }, +]) + +structure DatetimeOffsetsOutput { + datetime: DateTime +} diff --git a/smithy-aws-protocol-tests/model/restJson1/main.smithy b/smithy-aws-protocol-tests/model/restJson1/main.smithy index 810c292af52..8d2647ecf8b 100644 --- a/smithy-aws-protocol-tests/model/restJson1/main.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/main.smithy @@ -137,5 +137,7 @@ service RestJson { TestPayloadStructure, TestPayloadBlob, TestNoPayload, + + DatetimeOffsets, ] } diff --git a/smithy-aws-protocol-tests/model/restXml/datetime-offsets.smithy b/smithy-aws-protocol-tests/model/restXml/datetime-offsets.smithy new file mode 100644 index 00000000000..5a005d564d0 --- /dev/null +++ b/smithy-aws-protocol-tests/model/restXml/datetime-offsets.smithy @@ -0,0 +1,57 @@ +$version: "2.0" + +namespace aws.protocoltests.restxml + +use aws.protocols#restXml +use aws.protocoltests.shared#DateTime +use smithy.test#httpRequestTests +use smithy.test#httpResponseTests + +// These tests are for verifying the client can correctly parse +// the `DateTime` timestamp with an offset +@tags(["client-only"]) +@http(uri: "/DatetimeOffsets", method: "POST") +operation DatetimeOffsets { + output: DatetimeOffsetsOutput +} + +apply DatetimeOffsets @httpResponseTests([ + { + id: "RestXmlDateTimeWithNegativeOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: restXml, + code: 200, + body: """ + + 2019-12-16T22:48:18-01:00 + + """, + bodyMediaType: "application/xml", + headers: { + "Content-Type": "application/xml" + }, + params: { datetime: 1576540098 } + }, + { + id: "RestXmlDateTimeWithPositiveOffset", + documentation: """ + Ensures that clients can correctly parse datetime (timestamps) with offsets""", + protocol: restXml, + code: 200, + body: """ + + 2019-12-17T00:48:18+01:00 + + """, + bodyMediaType: "application/xml", + headers: { + "Content-Type": "application/xml" + }, + params: { datetime: 1576540098 } + }, +]) + +structure DatetimeOffsetsOutput { + datetime: DateTime +} diff --git a/smithy-aws-protocol-tests/model/restXml/main.smithy b/smithy-aws-protocol-tests/model/restXml/main.smithy index f18a26efe02..2c24158d610 100644 --- a/smithy-aws-protocol-tests/model/restXml/main.smithy +++ b/smithy-aws-protocol-tests/model/restXml/main.smithy @@ -92,5 +92,7 @@ service RestXml { EndpointOperation, EndpointWithHostLabelOperation, EndpointWithHostLabelHeaderOperation, + + DatetimeOffsets, ] }